LeeKinXUn commited on
Commit
513663e
1 Parent(s): 06950ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -1,28 +1,28 @@
1
- import openai,os
2
- import gradio as gr
3
- from gradio.components import Textbox
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
- messages = [
10
- {"role": "system", "content": "You are a helpful and kind AI Assistant."},
11
  ]
12
 
13
- def ChatGPT_Bot(input):
14
- if input:
15
- messages.append({"role": "user", "content": input})
16
- chat = openai.ChatCompletion.create(
17
- model="gpt-3.5-turbo", messages=messages
18
  )
19
- reply = chat.choices[0].message.content
20
- messages.append({"role": "assistant", "content": reply})
21
- return reply
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 AI助理",
27
- description="我是您的AI助理,您可以问任何你想知道的问题",
28
- theme=gr.themes.Default()).launch(share=True)
 
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 )