Commit
·
dbb1600
1
Parent(s):
0bcce89
Reset gpt_history
Browse files
app.py
CHANGED
|
@@ -14,7 +14,6 @@ CHAT_ENDPOINT="https://api.openai.com/v1/chat/completions"
|
|
| 14 |
CHAT_MODEL = "gpt-3.5-turbo"
|
| 15 |
CHAT_AUTH = {"Authorization": "Bearer " + openai.api_key}
|
| 16 |
MAX_TOKENS = 250
|
| 17 |
-
gpt_history = []
|
| 18 |
|
| 19 |
#TODO: handle max length limits
|
| 20 |
|
|
@@ -23,7 +22,7 @@ class ChatRoles():
|
|
| 23 |
ASSISTANT = "assistant"
|
| 24 |
USER = "user"
|
| 25 |
|
| 26 |
-
def get_assistant_response():
|
| 27 |
params = {
|
| 28 |
"model": CHAT_MODEL,
|
| 29 |
"messages": gpt_history,
|
|
@@ -44,18 +43,21 @@ instructions = {
|
|
| 44 |
}
|
| 45 |
|
| 46 |
def grad_demo():
|
|
|
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
def user(user_message, history):
|
| 49 |
gpt_history.append({"role": ChatRoles.USER, "content": user_message})
|
|
|
|
| 50 |
return "", history + [[user_message, None]]
|
| 51 |
def bot(history):
|
| 52 |
step = len(history)
|
| 53 |
print(f"STEP: {step}")
|
| 54 |
if step in instructions:
|
| 55 |
gpt_history.append({"role": ChatRoles.SYSTEM, "content": instructions[step]})
|
| 56 |
-
bot_message = get_assistant_response()
|
| 57 |
history[-1][1] = bot_message
|
| 58 |
gpt_history.append({"role": ChatRoles.ASSISTANT, "content": bot_message})
|
|
|
|
| 59 |
return history
|
| 60 |
chatbot = gr.Chatbot(value = lambda : bot([[None, None]]))
|
| 61 |
msg = gr.Textbox()
|
|
|
|
| 14 |
CHAT_MODEL = "gpt-3.5-turbo"
|
| 15 |
CHAT_AUTH = {"Authorization": "Bearer " + openai.api_key}
|
| 16 |
MAX_TOKENS = 250
|
|
|
|
| 17 |
|
| 18 |
#TODO: handle max length limits
|
| 19 |
|
|
|
|
| 22 |
ASSISTANT = "assistant"
|
| 23 |
USER = "user"
|
| 24 |
|
| 25 |
+
def get_assistant_response(gpt_history):
|
| 26 |
params = {
|
| 27 |
"model": CHAT_MODEL,
|
| 28 |
"messages": gpt_history,
|
|
|
|
| 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)
|
| 54 |
print(f"STEP: {step}")
|
| 55 |
if step in instructions:
|
| 56 |
gpt_history.append({"role": ChatRoles.SYSTEM, "content": instructions[step]})
|
| 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 |
chatbot = gr.Chatbot(value = lambda : bot([[None, None]]))
|
| 63 |
msg = gr.Textbox()
|