PeterPinetree commited on
Commit
5409f73
·
verified ·
1 Parent(s): b235111

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -156,17 +156,30 @@ def respond(
156
  formatted_messages.append({"role": "user", "content": str(message)})
157
 
158
  try:
159
- # Make API call
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  response = client.chat_completion(
161
- messages=formatted_messages,
162
  max_tokens=MAX_TOKENS,
163
  temperature=TEMPERATURE,
164
  top_p=TOP_P
165
  )
166
 
167
- # Extract response
168
  bot_message = response.choices[0].message.content
169
- return [{"role": "assistant", "content": bot_message}]
170
 
171
  except Exception as e:
172
  return [{"role": "assistant", "content": f"Story magic temporarily interrupted. Please try again. (Error: {str(e)})"}]
 
156
  formatted_messages.append({"role": "user", "content": str(message)})
157
 
158
  try:
159
+ # Ensure messages are properly formatted
160
+ api_messages = [{"role": "system", "content": get_enhanced_system_prompt(genre)}]
161
+
162
+ # Add chat history
163
+ if chat_history and use_full_memory:
164
+ for user_msg, bot_msg in chat_history[-MEMORY_WINDOW:]:
165
+ api_messages.extend([
166
+ {"role": "user", "content": str(user_msg)},
167
+ {"role": "assistant", "content": str(bot_msg)}
168
+ ])
169
+
170
+ # Add current message
171
+ api_messages.append({"role": "user", "content": str(message)})
172
+
173
+ # Make API call with properly formatted messages
174
  response = client.chat_completion(
175
+ messages=api_messages,
176
  max_tokens=MAX_TOKENS,
177
  temperature=TEMPERATURE,
178
  top_p=TOP_P
179
  )
180
 
 
181
  bot_message = response.choices[0].message.content
182
+ return chat_history + [(str(message), str(bot_message))]
183
 
184
  except Exception as e:
185
  return [{"role": "assistant", "content": f"Story magic temporarily interrupted. Please try again. (Error: {str(e)})"}]