(user_message, history, jupyter_state, dialog_info, interpreter)
| 164 | demo.load(update_uuid, dialog_info, dialog_info) |
| 165 | |
| 166 | def bot(user_message, history, jupyter_state, dialog_info, interpreter): |
| 167 | logging.info(f"user message: {user_message}") |
| 168 | interpreter.dialog = convert_history(gradio_history=history, interpreter_history=interpreter.dialog) |
| 169 | history.append([user_message, None]) |
| 170 | |
| 171 | interpreter.dialog.append({"role": "user", "content": user_message}) |
| 172 | |
| 173 | # setup |
| 174 | HAS_CODE = False # For now |
| 175 | prompt = interpreter.dialog_to_prompt(dialog=interpreter.dialog) |
| 176 | |
| 177 | _ = interpreter.generate(prompt) |
| 178 | history[-1][1] = "" |
| 179 | generated_text = "" |
| 180 | for character in interpreter.streamer: |
| 181 | history[-1][1] += character |
| 182 | history[-1][1] = history[-1][1].replace("<|EOT|>","") |
| 183 | generated_text += character |
| 184 | yield history, history, jupyter_state, dialog_info |
| 185 | |
| 186 | if is_valid_python_code(history[-1][1].strip()): |
| 187 | history[-1][1] = f"```python\n{history[-1][1].strip()}\n```" |
| 188 | generated_text = history[-1][1] |
| 189 | |
| 190 | HAS_CODE, generated_code_block = interpreter.extract_code_blocks( |
| 191 | generated_text |
| 192 | ) |
| 193 | |
| 194 | interpreter.dialog.append( |
| 195 | { |
| 196 | "role": "assistant", |
| 197 | "content": generated_text.replace("<unk>_", "") |
| 198 | .replace("<unk>", "") |
| 199 | .replace("<|EOT|>", ""), |
| 200 | } |
| 201 | ) |
| 202 | |
| 203 | logging.info(f"saving current dialog to file {dialog_info[0]}.json...") |
| 204 | logging.info(f"current dialog: {interpreter.dialog}") |
| 205 | save_json(interpreter.dialog, mode="openci_only", json_file_path=JSON_DATASET_DIR/f"{dialog_info[0]}.json", dialog_id=dialog_info[0]) |
| 206 | |
| 207 | attempt = 1 |
| 208 | while HAS_CODE: |
| 209 | if attempt > MAX_TRY: |
| 210 | break |
| 211 | # if no code then doesn't have to execute it |
| 212 | generated_text = "" # clear generated text |
| 213 | |
| 214 | yield history, history, jupyter_state, dialog_info |
| 215 | |
| 216 | # replace unknown thing to none '' |
| 217 | generated_code_block = generated_code_block.replace( |
| 218 | "<unk>_", "" |
| 219 | ).replace("<unk>", "") |
| 220 | |
| 221 | if has_input_function_calls(generated_code_block): |
| 222 | code_block_output = "Please directly assign the value of inputs instead of using input() function in your code." |
| 223 | else: |
nothing calls this directly
no test coverage detected