Spaces:
Build error
Build error
Commit
•
2901a7a
1
Parent(s):
ffb4fe4
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,7 @@ initial_instructions = {
|
|
25 |
}
|
26 |
|
27 |
# Initialize the conversation history with initial instructions
|
28 |
-
conversation_history = [
|
29 |
|
30 |
def setup_openai(api_key):
|
31 |
openai.api_key = api_key
|
@@ -36,7 +36,7 @@ def ask_joe(api_key, message):
|
|
36 |
setup_openai(api_key)
|
37 |
|
38 |
# Add the user's message to the conversation history
|
39 |
-
conversation_history.append(
|
40 |
|
41 |
# Use the conversation history as the input to the model
|
42 |
response = openai.ChatCompletion.create(
|
@@ -50,12 +50,12 @@ def ask_joe(api_key, message):
|
|
50 |
model_message = response.choices[0].message['content'].strip()
|
51 |
|
52 |
# Add the model's message to the conversation history
|
53 |
-
conversation_history.append(
|
54 |
|
55 |
# Write the conversation history to a file
|
56 |
with open('conversation_history.txt', 'w') as f:
|
57 |
-
for
|
58 |
-
f.write(f'{role.capitalize()}: {content}\n')
|
59 |
|
60 |
time.sleep(1) # sleep for a bit for better UI experience
|
61 |
return model_message
|
@@ -63,15 +63,11 @@ def ask_joe(api_key, message):
|
|
63 |
def reset_conversation(api_key):
|
64 |
global conversation_history
|
65 |
# Reset the conversation history with initial instructions
|
66 |
-
conversation_history = [
|
67 |
return "Conversation reset"
|
68 |
|
69 |
api_key = gr.inputs.Textbox(label="OpenAI API Key")
|
70 |
message = gr.inputs.Textbox(label="Your question")
|
71 |
output_message = gr.outputs.Textbox(label="Joe's answer")
|
72 |
|
73 |
-
reset_interface
|
74 |
-
ask_joe_interface = gr.Interface(fn=ask_joe, inputs=[api_key, message], outputs=output_message)
|
75 |
-
|
76 |
-
ask_joe_interface.launch()
|
77 |
-
reset_interface.launch()
|
|
|
25 |
}
|
26 |
|
27 |
# Initialize the conversation history with initial instructions
|
28 |
+
conversation_history = [initial_instructions]
|
29 |
|
30 |
def setup_openai(api_key):
|
31 |
openai.api_key = api_key
|
|
|
36 |
setup_openai(api_key)
|
37 |
|
38 |
# Add the user's message to the conversation history
|
39 |
+
conversation_history.append({"role": "user", "content": message})
|
40 |
|
41 |
# Use the conversation history as the input to the model
|
42 |
response = openai.ChatCompletion.create(
|
|
|
50 |
model_message = response.choices[0].message['content'].strip()
|
51 |
|
52 |
# Add the model's message to the conversation history
|
53 |
+
conversation_history.append({"role": "assistant", "content": model_message})
|
54 |
|
55 |
# Write the conversation history to a file
|
56 |
with open('conversation_history.txt', 'w') as f:
|
57 |
+
for message in conversation_history:
|
58 |
+
f.write(f'{message["role"].capitalize()}: {message["content"]}\n')
|
59 |
|
60 |
time.sleep(1) # sleep for a bit for better UI experience
|
61 |
return model_message
|
|
|
63 |
def reset_conversation(api_key):
|
64 |
global conversation_history
|
65 |
# Reset the conversation history with initial instructions
|
66 |
+
conversation_history = [initial_instructions]
|
67 |
return "Conversation reset"
|
68 |
|
69 |
api_key = gr.inputs.Textbox(label="OpenAI API Key")
|
70 |
message = gr.inputs.Textbox(label="Your question")
|
71 |
output_message = gr.outputs.Textbox(label="Joe's answer")
|
72 |
|
73 |
+
reset_interface
|
|
|
|
|
|
|
|