victoriaono
commited on
Commit
•
ff9d83f
1
Parent(s):
1cc6224
Add past inputs and outputs to messages
Browse files
app.py
CHANGED
@@ -11,6 +11,10 @@ retrieval_model_name = 'output/sentence-transformer-finetuned/'
|
|
11 |
|
12 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
13 |
|
|
|
|
|
|
|
|
|
14 |
# Attempt to load the necessary models and provide feedback on success or failure
|
15 |
try:
|
16 |
retrieval_model = SentenceTransformer(retrieval_model_name)
|
@@ -63,12 +67,11 @@ def generate_response(user_query, relevant_segment):
|
|
63 |
Generate a response emphasizing the bot's capability in providing chess information.
|
64 |
"""
|
65 |
try:
|
66 |
-
system_message = "You are a chess chatbot specialized in providing information on chess rules, strategies, and terminology."
|
67 |
user_message = f"Here's the information on chess: {relevant_segment}"
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
response = openai.ChatCompletion.create(
|
73 |
model="gpt-3.5-turbo",
|
74 |
messages=messages,
|
@@ -78,7 +81,15 @@ def generate_response(user_query, relevant_segment):
|
|
78 |
frequency_penalty=0,
|
79 |
presence_penalty=0
|
80 |
)
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
except Exception as e:
|
83 |
print(f"Error in generating response: {e}")
|
84 |
return f"Error in generating response: {e}"
|
|
|
11 |
|
12 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
13 |
|
14 |
+
system_message = "You are a chess chatbot specialized in providing information on chess rules, strategies, and terminology."
|
15 |
+
# Initial system message to set the behavior of the assistant
|
16 |
+
messages = [{"role": "system", "content": system_message}]
|
17 |
+
|
18 |
# Attempt to load the necessary models and provide feedback on success or failure
|
19 |
try:
|
20 |
retrieval_model = SentenceTransformer(retrieval_model_name)
|
|
|
67 |
Generate a response emphasizing the bot's capability in providing chess information.
|
68 |
"""
|
69 |
try:
|
|
|
70 |
user_message = f"Here's the information on chess: {relevant_segment}"
|
71 |
+
|
72 |
+
# Append user's message to messages list
|
73 |
+
messages.append({"role": "user", "content": user_message})
|
74 |
+
|
75 |
response = openai.ChatCompletion.create(
|
76 |
model="gpt-3.5-turbo",
|
77 |
messages=messages,
|
|
|
81 |
frequency_penalty=0,
|
82 |
presence_penalty=0
|
83 |
)
|
84 |
+
|
85 |
+
# Extract the response text
|
86 |
+
output_text = response['choices'][0]['message']['content'].strip()
|
87 |
+
|
88 |
+
# Append assistant's message to messages list for context
|
89 |
+
messages.append({"role": "assistant", "content": output_text})
|
90 |
+
|
91 |
+
return output_text
|
92 |
+
|
93 |
except Exception as e:
|
94 |
print(f"Error in generating response: {e}")
|
95 |
return f"Error in generating response: {e}"
|