From 4f55dfdc0e27d94060ac773001245baee66a43d5 Mon Sep 17 00:00:00 2001
From: qingxu fu <505030475@qq.com>
Date: Sat, 22 Jul 2023 02:25:30 +0800
Subject: [PATCH] easy
---
crazy_functions/虚空终端CodeInterpreter.py | 69 +++++++++++++---------
toolbox.py | 5 ++
2 files changed, 45 insertions(+), 29 deletions(-)
diff --git a/crazy_functions/虚空终端CodeInterpreter.py b/crazy_functions/虚空终端CodeInterpreter.py
index aefe430..e7e28eb 100644
--- a/crazy_functions/虚空终端CodeInterpreter.py
+++ b/crazy_functions/虚空终端CodeInterpreter.py
@@ -1,8 +1,21 @@
-from toolbox import CatchException, update_ui, gen_time_str, trimmed_format_exc, promote_file_to_downloadzone
+from toolbox import CatchException, update_ui, gen_time_str, trimmed_format_exc, promote_file_to_downloadzone, clear_file_downloadzone
from .crazy_utils import request_gpt_model_in_new_thread_with_ui_alive
from .crazy_utils import input_clipping, try_install_deps
import os
+templete = """
+```python
+import ... # Put dependencies here, e.g. import numpy as np
+
+class TerminalFunction(object): # Do not change the name of the class, The name of the class must be `TerminalFunction`
+
+ def run(self, path): # The name of the function must be `run`, it takes only a positional argument.
+ # rewrite the function you have just written here
+ ...
+ return generated_file_path
+```
+"""
+
def inspect_dependency(chatbot, history):
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
return True
@@ -40,19 +53,8 @@ def gpt_interact_multi_step(txt, file_type, llm_kwargs, chatbot, history):
# 第二步
prompt_compose = [
- "If previous stage is successful, rewrite the function you have just written to satisfy following templete: ",
-"""
-```python
-import ... # Put dependencies here, e.g. import numpy as np
-
-class TerminalFunction(object): # Do not change the name of the class, The name of the class must be `TerminalFunction`
-
- def run(self, path): # The name of the function must be `run`, it takes only a positional argument.
- # rewrite the function you have just written here
- ...
- return generated_string_or_path
-```
-"""
+ "If previous stage is successful, rewrite the function you have just written to satisfy following templete: \n",
+ templete
]
i_say = "".join(prompt_compose); inputs_show_user = "If previous stage is successful, rewrite the function you have just written to satisfy executable templete. "
gpt_say = yield from request_gpt_model_in_new_thread_with_ui_alive(
@@ -74,14 +76,15 @@ class TerminalFunction(object): # Do not change the name of the class, The name
# llm_kwargs=llm_kwargs, chatbot=chatbot, history=history,
# sys_prompt= r"You are a programmer."
# )
- # # 第三步
- i_say = "Show me how to use `pip` to install packages to run the code above. "
- i_say += 'For instance. `pip install -r opencv-python scipy numpy`'
- installation_advance = yield from request_gpt_model_in_new_thread_with_ui_alive(
- inputs=i_say, inputs_show_user=inputs_show_user,
- llm_kwargs=llm_kwargs, chatbot=chatbot, history=history,
- sys_prompt= r"You are a programmer."
- )
+ # # # 第三步
+ # i_say = "Show me how to use `pip` to install packages to run the code above. "
+ # i_say += 'For instance. `pip install -r opencv-python scipy numpy`'
+ # installation_advance = yield from request_gpt_model_in_new_thread_with_ui_alive(
+ # inputs=i_say, inputs_show_user=i_say,
+ # llm_kwargs=llm_kwargs, chatbot=chatbot, history=history,
+ # sys_prompt= r"You are a programmer."
+ # )
+ installation_advance = ""
return code_to_return, installation_advance, txt, file_type, llm_kwargs, chatbot, history
@@ -107,7 +110,14 @@ def init_module_instance(module):
init_f = getattr(importlib.import_module(module_), class_)
return init_f()
-
+def for_immediate_show_off_when_possible(file_type, fp, chatbot):
+ if file_type in ['png', 'jpg']:
+ image_path = os.path.abspath(fp)
+ chatbot.append(['这是一张图片, 展示如下:',
+ f'本地文件地址:
`{image_path}`
'+
+ f'本地文件预览: