Update app.py
Browse files
app.py
CHANGED
|
@@ -38,19 +38,28 @@ def add_text(history, text):
|
|
| 38 |
def add_file(history, file):
|
| 39 |
history = history + [((file.name,), None)]
|
| 40 |
return history
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
def answer(question, history=None):
|
| 47 |
-
if history is None:
|
| 48 |
-
history = []
|
| 49 |
-
history.append(question)
|
| 50 |
-
response = conv.ask(question)
|
| 51 |
-
history.append(response)
|
| 52 |
-
responses = [(u,b) for u,b in zip(history[::2], history[1::2])]
|
| 53 |
-
return responses, history
|
| 54 |
|
| 55 |
prompt = """假如你是GPT-4,你可以回答用户提问的任何问题"""
|
| 56 |
conv = Conversation(prompt, 10)
|
|
|
|
| 38 |
def add_file(history, file):
|
| 39 |
history = history + [((file.name,), None)]
|
| 40 |
return history
|
| 41 |
+
|
| 42 |
+
def bot(history, chatbot):
|
| 43 |
+
prompt = ". ".join([m["content"] for m in history if m["role"] == "user"])
|
| 44 |
+
response = openai.Completion.create(
|
| 45 |
+
engine="davinci",
|
| 46 |
+
prompt=prompt,
|
| 47 |
+
temperature=0.5,
|
| 48 |
+
max_tokens=100,
|
| 49 |
+
top_p=1.0
|
| 50 |
+
)
|
| 51 |
+
message = response["choices"][0]["text"]
|
| 52 |
+
chatbot.add_message(content=message, role="assistant")
|
| 53 |
+
|
| 54 |
+
# def answer(question, history=None):
|
| 55 |
+
# if history is None:
|
| 56 |
+
# history = []
|
| 57 |
+
# history.append(question)
|
| 58 |
+
# response = conv.ask(question)
|
| 59 |
+
# history.append(response)
|
| 60 |
+
# responses = [(u,b) for u,b in zip(history[::2], history[1::2])]
|
| 61 |
+
# return responses, history
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
prompt = """假如你是GPT-4,你可以回答用户提问的任何问题"""
|
| 65 |
conv = Conversation(prompt, 10)
|