Tim Luka Horstmann commited on
Commit
fedc11d
·
1 Parent(s): 5bf6ded

change assistant to model

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -165,9 +165,22 @@ async def stream_response_gemini(query, history):
165
  # 2) Build only user/model history as `contents`
166
  contents = []
167
  for msg in history:
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  contents.append(
169
  types.Content(
170
- role=msg["role"],
171
  parts=[ types.Part.from_text(text=msg["content"]) ]
172
  )
173
  )
 
165
  # 2) Build only user/model history as `contents`
166
  contents = []
167
  for msg in history:
168
+ # Ensure the role is compatible with Gemini API ('user' or 'model')
169
+ api_role = ""
170
+ if msg["role"] == "user":
171
+ api_role = "user"
172
+ elif msg["role"] == "assistant": # Map "assistant" from client to "model" for API
173
+ api_role = "model"
174
+ elif msg["role"] == "model": # Already correct
175
+ api_role = "model"
176
+ else:
177
+ # Log a warning or handle unrecognized roles as needed
178
+ logger.warning(f"Unrecognized role '{msg['role']}' in history. Skipping message.")
179
+ continue
180
+
181
  contents.append(
182
  types.Content(
183
+ role=api_role,
184
  parts=[ types.Part.from_text(text=msg["content"]) ]
185
  )
186
  )