starsaround
commited on
Commit
•
7987763
1
Parent(s):
b7adec7
Update app.py
Browse files
app.py
CHANGED
@@ -20,28 +20,28 @@ from g4f.Provider import (
|
|
20 |
import os
|
21 |
|
22 |
provider_dict = {
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
'DeepAi': DeepAi,
|
37 |
'GetGpt': GetGpt
|
38 |
}
|
39 |
|
40 |
-
|
41 |
with gr.Blocks() as demo:
|
42 |
chatbot = gr.Chatbot([[None, None]], label='AI')
|
43 |
msg = gr.Textbox(value="", label='')
|
44 |
clear = gr.Button("Clear")
|
|
|
45 |
with gr.Row():
|
46 |
model_name = gr.Dropdown(['gpt-3.5-turbo', 'gpt-4'], value='gpt-3.5-turbo', label='模型')
|
47 |
provider_name = gr.Dropdown(provider_dict.keys(), value='GetGpt', label='提供者')
|
@@ -49,18 +49,34 @@ with gr.Blocks() as demo:
|
|
49 |
def user(user_message, history):
|
50 |
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
51 |
|
52 |
-
def bot(history, model_name, provider_name):
|
53 |
history[-1][1] = ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
bot_msg = g4f.ChatCompletion.create(model=model_name,
|
55 |
provider=provider_dict[provider_name],
|
56 |
-
messages=[{"role": "user",
|
|
|
|
|
57 |
stream=True)
|
58 |
for c in bot_msg:
|
59 |
history[-1][1] += c
|
60 |
yield history
|
61 |
-
|
62 |
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
63 |
-
bot, [chatbot, model_name, provider_name], chatbot
|
64 |
)
|
65 |
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
66 |
clear.click(lambda: None, None, chatbot, queue=False)
|
|
|
20 |
import os
|
21 |
|
22 |
provider_dict = {
|
23 |
+
'Ails': Ails,
|
24 |
+
'You': You,
|
25 |
+
'Bing': Bing,
|
26 |
+
'Yqcloud': Yqcloud,
|
27 |
+
'Theb': Theb,
|
28 |
+
'Aichat': Aichat,
|
29 |
+
'Bard': Bard,
|
30 |
+
'Vercel': Vercel,
|
31 |
+
'Forefront': Forefront,
|
32 |
+
'Lockchat': Lockchat,
|
33 |
+
'Liaobots': Liaobots,
|
34 |
+
'H2o': H2o,
|
35 |
+
'ChatgptLogin': ChatgptLogin,
|
36 |
'DeepAi': DeepAi,
|
37 |
'GetGpt': GetGpt
|
38 |
}
|
39 |
|
|
|
40 |
with gr.Blocks() as demo:
|
41 |
chatbot = gr.Chatbot([[None, None]], label='AI')
|
42 |
msg = gr.Textbox(value="", label='')
|
43 |
clear = gr.Button("Clear")
|
44 |
+
system_msg = gr.Textbox(value="你是一名助手,可以解答问题。", label='系统提示')
|
45 |
with gr.Row():
|
46 |
model_name = gr.Dropdown(['gpt-3.5-turbo', 'gpt-4'], value='gpt-3.5-turbo', label='模型')
|
47 |
provider_name = gr.Dropdown(provider_dict.keys(), value='GetGpt', label='提供者')
|
|
|
49 |
def user(user_message, history):
|
50 |
return gr.update(value="", interactive=False), history + [[user_message, None]]
|
51 |
|
52 |
+
def bot(history, model_name, provider_name, system_msg):
|
53 |
history[-1][1] = ''
|
54 |
+
if len(system_msg)>3000:
|
55 |
+
system_msg = system_msg[:1500] + system_msg[-1500:]
|
56 |
+
prompt = """
|
57 |
+
请你仔细阅读以下提示,然后针对用户的话进行回答。
|
58 |
+
提示:
|
59 |
+
```
|
60 |
+
{}
|
61 |
+
```
|
62 |
+
用户最新的话:
|
63 |
+
```
|
64 |
+
{}
|
65 |
+
```
|
66 |
+
请回答:
|
67 |
+
"""
|
68 |
bot_msg = g4f.ChatCompletion.create(model=model_name,
|
69 |
provider=provider_dict[provider_name],
|
70 |
+
messages=[{"role": "user",
|
71 |
+
"content": prompt.format(system_msg,
|
72 |
+
history[-1][0])}],
|
73 |
stream=True)
|
74 |
for c in bot_msg:
|
75 |
history[-1][1] += c
|
76 |
yield history
|
77 |
+
|
78 |
response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
79 |
+
bot, [chatbot, model_name, provider_name, system_msg], chatbot
|
80 |
)
|
81 |
response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
|
82 |
clear.click(lambda: None, None, chatbot, queue=False)
|