curry tang
commited on
Commit
·
b45abbf
1
Parent(s):
d1afe32
update
Browse files- app.py +18 -17
- prompts.py +25 -0
app.py
CHANGED
@@ -5,6 +5,7 @@ from config import settings
|
|
5 |
import base64
|
6 |
from PIL import Image
|
7 |
import io
|
|
|
8 |
|
9 |
|
10 |
deep_seek_llm = DeepSeekLLM(api_key=settings.deep_seek_api_key)
|
@@ -18,7 +19,7 @@ def init_chat():
|
|
18 |
|
19 |
def predict(message, history, chat):
|
20 |
print('!!!!!', message, history, chat)
|
21 |
-
|
22 |
if chat is None:
|
23 |
chat = init_chat()
|
24 |
history_messages = []
|
@@ -27,19 +28,20 @@ def predict(message, history, chat):
|
|
27 |
if assistant is not None:
|
28 |
history_messages.append(AIMessage(content=assistant))
|
29 |
|
30 |
-
if
|
31 |
-
history_messages.append(
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
response_message = ''
|
45 |
for chunk in chat.stream(history_messages):
|
@@ -60,7 +62,6 @@ def update_chat(_provider: str, _model: str, _temperature: float, _max_tokens: i
|
|
60 |
|
61 |
|
62 |
def explain_code(_code_type: str, _code: str, _chat):
|
63 |
-
print('>>>>>???', _code_type, _code, _chat)
|
64 |
if _chat is None:
|
65 |
_chat = init_chat()
|
66 |
chat_messages = [
|
@@ -157,6 +158,8 @@ def translate_doc(_language_input, _language_output, _doc, _chat):
|
|
157 |
|
158 |
with gr.Blocks() as app:
|
159 |
chat_engine = gr.State(value=None)
|
|
|
|
|
160 |
with gr.Accordion('模型参数设置', open=False):
|
161 |
with gr.Row():
|
162 |
provider = gr.Dropdown(
|
@@ -218,9 +221,7 @@ with gr.Blocks() as app:
|
|
218 |
with gr.Column(scale=2, min_width=600):
|
219 |
chatbot = gr.ChatInterface(
|
220 |
predict,
|
221 |
-
multimodal=True,
|
222 |
chatbot=gr.Chatbot(elem_id="chatbot", height=600, show_share_button=False),
|
223 |
-
textbox=gr.MultimodalTextbox(lines=1),
|
224 |
additional_inputs=[chat_engine]
|
225 |
)
|
226 |
with gr.Column(scale=1, min_width=300):
|
|
|
5 |
import base64
|
6 |
from PIL import Image
|
7 |
import io
|
8 |
+
from prompts import web_prompt
|
9 |
|
10 |
|
11 |
deep_seek_llm = DeepSeekLLM(api_key=settings.deep_seek_api_key)
|
|
|
19 |
|
20 |
def predict(message, history, chat):
|
21 |
print('!!!!!', message, history, chat)
|
22 |
+
history_len = len(history)
|
23 |
if chat is None:
|
24 |
chat = init_chat()
|
25 |
history_messages = []
|
|
|
28 |
if assistant is not None:
|
29 |
history_messages.append(AIMessage(content=assistant))
|
30 |
|
31 |
+
if history_len == 0:
|
32 |
+
history_messages.append(SystemMessage(content=web_prompt))
|
33 |
+
history_messages.append(HumanMessage(content=message))
|
34 |
+
# else:
|
35 |
+
# file = message.files[0]
|
36 |
+
# with Image.open(file.path) as img:
|
37 |
+
# buffer = io.BytesIO()
|
38 |
+
# img = img.convert('RGB')
|
39 |
+
# img.save(buffer, format="JPEG")
|
40 |
+
# image_data = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
41 |
+
# history_messages.append(HumanMessage(content=[
|
42 |
+
# {"type": "text", "text": message.text},
|
43 |
+
# {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_data}"}}
|
44 |
+
# ]))
|
45 |
|
46 |
response_message = ''
|
47 |
for chunk in chat.stream(history_messages):
|
|
|
62 |
|
63 |
|
64 |
def explain_code(_code_type: str, _code: str, _chat):
|
|
|
65 |
if _chat is None:
|
66 |
_chat = init_chat()
|
67 |
chat_messages = [
|
|
|
158 |
|
159 |
with gr.Blocks() as app:
|
160 |
chat_engine = gr.State(value=None)
|
161 |
+
with gr.Row(variant='panel'):
|
162 |
+
gr.Markdown("## 智能助手")
|
163 |
with gr.Accordion('模型参数设置', open=False):
|
164 |
with gr.Row():
|
165 |
provider = gr.Dropdown(
|
|
|
221 |
with gr.Column(scale=2, min_width=600):
|
222 |
chatbot = gr.ChatInterface(
|
223 |
predict,
|
|
|
224 |
chatbot=gr.Chatbot(elem_id="chatbot", height=600, show_share_button=False),
|
|
|
225 |
additional_inputs=[chat_engine]
|
226 |
)
|
227 |
with gr.Column(scale=1, min_width=300):
|
prompts.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
web_prompt = '''
|
2 |
+
You are an expert in Web development, including CSS, JavaScript, Typescript, React, Vue, Angular, Tailwind, Node.JS and Markdown.Don't apologise unnecessarily. Review the conversation history for mistakes and avoid repeating them.
|
3 |
+
|
4 |
+
During our conversation break things down in to discrete changes, and suggest a small test after each stage to make sure things are on the right track.
|
5 |
+
|
6 |
+
Only produce code to illustrate examples, or when directed to in the conversation. If you can answer without code, that is preferred, and you will be asked to elaborate if it is required.
|
7 |
+
|
8 |
+
Request clarification for anything unclear or ambiguous.
|
9 |
+
|
10 |
+
Before writing or suggesting code, perform a comprehensive code review of the existing code and describe how it works between <CODE_REVIEW> tags.
|
11 |
+
|
12 |
+
After completing the code review, construct a plan for the change between <PLANNING> tags. Ask for additional source files or documentation that may be relevant. The plan should avoid duplication (DRY principle), and balance maintenance and flexibility. Present trade-offs and implementation choices at this step. Consider available Frameworks and Libraries and suggest their use when relevant. STOP at this step if we have not agreed a plan.
|
13 |
+
|
14 |
+
Once agreed, produce code between <OUTPUT> tags. Pay attention to Variable Names, Identifiers and String Literals, and check that they are reproduced accurately from the original source files unless otherwise directed. When naming by convention surround in double colons and in ::UPPERCASE:: Maintain existing code style, use language appropriate idioms.
|
15 |
+
|
16 |
+
Always produce code starting with a new line, and in blocks (```) with the language specified:
|
17 |
+
|
18 |
+
```JavaScript
|
19 |
+
|
20 |
+
OUTPUT_CODE
|
21 |
+
|
22 |
+
```
|
23 |
+
|
24 |
+
Conduct Security and Operational reviews of PLANNING and OUTPUT, paying particular attention to things that may compromise data or introduce vulnerabilities. For sensitive changes (e.g. Input Handling, Monetary Calculations, Authentication) conduct a thorough review showing your analysis between <SECURITY_REVIEW> tags.
|
25 |
+
'''
|