Commit
·
b27faad
1
Parent(s):
dbb1600
Clear gpt history attempt 2
Browse files
app.py
CHANGED
|
@@ -43,11 +43,11 @@ instructions = {
|
|
| 43 |
}
|
| 44 |
|
| 45 |
def grad_demo():
|
| 46 |
-
gpt_history = []
|
| 47 |
with gr.Blocks() as demo:
|
|
|
|
| 48 |
def user(user_message, history):
|
| 49 |
gpt_history.append({"role": ChatRoles.USER, "content": user_message})
|
| 50 |
-
print(gpt_history)
|
| 51 |
return "", history + [[user_message, None]]
|
| 52 |
def bot(history):
|
| 53 |
step = len(history)
|
|
@@ -57,9 +57,12 @@ def grad_demo():
|
|
| 57 |
bot_message = get_assistant_response(gpt_history)
|
| 58 |
history[-1][1] = bot_message
|
| 59 |
gpt_history.append({"role": ChatRoles.ASSISTANT, "content": bot_message})
|
| 60 |
-
print(gpt_history)
|
| 61 |
return history
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
msg = gr.Textbox()
|
| 64 |
clear = gr.Button("Clear")
|
| 65 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
def grad_demo():
|
|
|
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
+
gpt_history = []
|
| 48 |
def user(user_message, history):
|
| 49 |
gpt_history.append({"role": ChatRoles.USER, "content": user_message})
|
| 50 |
+
print(f"Length of gpt_history: {gpt_history}")
|
| 51 |
return "", history + [[user_message, None]]
|
| 52 |
def bot(history):
|
| 53 |
step = len(history)
|
|
|
|
| 57 |
bot_message = get_assistant_response(gpt_history)
|
| 58 |
history[-1][1] = bot_message
|
| 59 |
gpt_history.append({"role": ChatRoles.ASSISTANT, "content": bot_message})
|
| 60 |
+
print(f"Length of gpt_history: {gpt_history}")
|
| 61 |
return history
|
| 62 |
+
def initialize():
|
| 63 |
+
gpt_history.clear()
|
| 64 |
+
return bot([[None, None]])
|
| 65 |
+
chatbot = gr.Chatbot(value = initialize)
|
| 66 |
msg = gr.Textbox()
|
| 67 |
clear = gr.Button("Clear")
|
| 68 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|