Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,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 = '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'
|
8 |
+
|
9 |
+
消息 = [
|
10 |
+
{ "role" : "system" , "content" : "你是一个乐于助人、善良的 AI 小助手。" },
|
11 |
+
]
|
12 |
+
|
13 |
+
def 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 )
|