Spaces:
Sleeping
Sleeping
liuzuoliang
commited on
Commit
•
dcbbdd5
1
Parent(s):
9287bd9
debug a error
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
|
2 |
import openai
|
3 |
import os
|
4 |
|
5 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
6 |
|
|
|
7 |
class Conversation:
|
8 |
def __init__(self, prompt, num_of_round):
|
9 |
self.prompt = prompt
|
@@ -28,25 +28,28 @@ class Conversation:
|
|
28 |
message = response["choices"][0]["message"]["content"]
|
29 |
self.messages.append({"role": "assistant", "content": message})
|
30 |
|
31 |
-
if len(self.messages) > self.num_of_round*2 + 1:
|
32 |
-
del self.messages[1:3]
|
33 |
return message
|
34 |
-
|
35 |
|
36 |
import gradio as gr
|
|
|
37 |
prompt = """你是一个中国厨师,用中文回答做菜的问题。你的回答需要满足以下要求:
|
38 |
1. 你的回答必须是中文
|
39 |
2. 回答限制在100个字以内"""
|
40 |
|
41 |
conv = Conversation(prompt, 10)
|
42 |
|
|
|
43 |
def answer(question, history=[]):
|
44 |
history.append(question)
|
45 |
response = conv.ask(question)
|
46 |
history.append(response)
|
47 |
-
responses = [(u,b) for u,b in zip(history[::2], history[1::2])]
|
48 |
return responses, history
|
49 |
|
|
|
50 |
with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as demo:
|
51 |
chatbot = gr.Chatbot(elem_id="chatbot")
|
52 |
state = gr.State([])
|
@@ -56,4 +59,4 @@ with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as d
|
|
56 |
|
57 |
txt.submit(answer, [txt, state], [chatbot, state])
|
58 |
|
59 |
-
demo.launch()
|
|
|
|
|
1 |
import openai
|
2 |
import os
|
3 |
|
4 |
openai.api_key = os.environ.get("OPENAI_API_KEY")
|
5 |
|
6 |
+
|
7 |
class Conversation:
|
8 |
def __init__(self, prompt, num_of_round):
|
9 |
self.prompt = prompt
|
|
|
28 |
message = response["choices"][0]["message"]["content"]
|
29 |
self.messages.append({"role": "assistant", "content": message})
|
30 |
|
31 |
+
if len(self.messages) > self.num_of_round * 2 + 1:
|
32 |
+
del self.messages[1:3]
|
33 |
return message
|
34 |
+
|
35 |
|
36 |
import gradio as gr
|
37 |
+
|
38 |
prompt = """你是一个中国厨师,用中文回答做菜的问题。你的回答需要满足以下要求:
|
39 |
1. 你的回答必须是中文
|
40 |
2. 回答限制在100个字以内"""
|
41 |
|
42 |
conv = Conversation(prompt, 10)
|
43 |
|
44 |
+
|
45 |
def answer(question, history=[]):
|
46 |
history.append(question)
|
47 |
response = conv.ask(question)
|
48 |
history.append(response)
|
49 |
+
responses = [(u, b) for u, b in zip(history[::2], history[1::2])]
|
50 |
return responses, history
|
51 |
|
52 |
+
|
53 |
with gr.Blocks(css="#chatbot{height:300px} .overflow-y-auto{height:500px}") as demo:
|
54 |
chatbot = gr.Chatbot(elem_id="chatbot")
|
55 |
state = gr.State([])
|
|
|
59 |
|
60 |
txt.submit(answer, [txt, state], [chatbot, state])
|
61 |
|
62 |
+
demo.launch()
|