Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,28 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
|
5 |
-
os.environ["http_proxy"] = "http://localhost:7890"
|
6 |
-
os.environ["https_proxy"] = "http://localhost:7890"
|
7 |
-
openai.api_key = '
|
8 |
|
9 |
-
|
10 |
-
{"role": "system", "content": "
|
11 |
]
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
messages.append({
|
16 |
-
|
17 |
-
|
18 |
)
|
19 |
-
|
20 |
-
messages.append({"role": "assistant", "content": reply})
|
21 |
-
|
22 |
|
23 |
-
inputs = Textbox(lines=7, label="请输入你的问题")
|
24 |
-
outputs = Textbox(lines=7, label="来自ChatGPT的回答")
|
25 |
|
26 |
-
gr.Interface(fn=ChatGPT_Bot, inputs=inputs, outputs=outputs, title="ChatGPT
|
27 |
-
description="我是您的AI
|
28 |
-
|
|
|
1 |
+
导入openai,os
|
2 |
+
将易变导入为gr
|
3 |
+
从gradio.components导入文档
|
4 |
|
5 |
+
os.environ[ "http_proxy" ] = "http://localhost:7890"
|
6 |
+
os.environ[ "https_proxy" ] = "http://localhost:7890"
|
7 |
+
openai.api_key = 'OPENAI_API_KEY
|
8 |
|
9 |
+
消息 = [
|
10 |
+
{ "role" : "system" , "content" : "你是一个乐于助人、善良的 AI 小助手。" },
|
11 |
]
|
12 |
|
13 |
+
定义ChatGPT_Bot(输入):
|
14 |
+
如果输入:
|
15 |
+
messages.append({ “角色”:“用户”,“内容”:输入})
|
16 |
+
聊天 = openai.ChatCompletion.create(
|
17 |
+
模型=“gpt- 3.5 -turbo”,消息=消息
|
18 |
)
|
19 |
+
回复 = chat.choices[ 0 ].message.content
|
20 |
+
messages.append({ "role" : "assistant" , "content" : reply})
|
21 |
+
返回回复
|
22 |
|
23 |
+
inputs = Textbox(lines= 7 , label= "请输入你的问题" )
|
24 |
+
outputs = Textbox(lines= 7 , label= "来自ChatGPT的回答" )
|
25 |
|
26 |
+
gr.Interface(fn=ChatGPT_Bot, inputs=inputs, outputs=outputs, title= "ChatGPT 人工智能助手" ,
|
27 |
+
description= "我是您的AI助理,您可以问任何您想知道的问题" ,
|
28 |
+
主题=gr.themes.Default()).launch(share= True )
|