MatteoScript commited on
Commit
146c720
·
verified ·
1 Parent(s): cfb4270

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -2
main.py CHANGED
@@ -158,7 +158,6 @@ def clean_schema_property(prop):
158
  result["properties"] = {"parameter": {"type": "string"}}
159
  return result
160
 
161
-
162
  def convert_payload_for_gemini(payload: ChatCompletionRequest):
163
  if hasattr(payload, "model_dump"):
164
  payload_converted = json.loads(payload.model_dump_json())
@@ -166,6 +165,8 @@ def convert_payload_for_gemini(payload: ChatCompletionRequest):
166
  payload_converted = payload.copy()
167
  else:
168
  raise ValueError("Formato payload non supportato")
 
 
169
  if "tools" in payload_converted:
170
  payload_converted["tools"] = convert_openai_schema_for_gemini(payload_converted["tools"])
171
  new_payload = ChatCompletionRequest.model_validate(payload_converted)
@@ -180,12 +181,16 @@ def call_api_sync(params: ChatCompletionRequest):
180
  if params.messages:
181
  params.messages = sanitize_messages(params.messages)
182
  params = convert_payload_for_gemini(params)
 
183
  print(params)
184
  response_format = getattr(params, 'response_format', None)
185
  if response_format and getattr(response_format, 'type', None) == 'json_schema':
186
  response = client.beta.chat.completions.parse(**params.model_dump())
187
  else:
188
  response = client.chat.completions.create(**params.model_dump())
 
 
 
189
  return response
190
  except Exception as e:
191
  if "429" in str(e):
@@ -229,7 +234,6 @@ async def health_check():
229
  @app.post("/v1/chat/completions", dependencies=[Depends(verify_api_key)])
230
  async def chat_completions(req: ChatCompletionRequest):
231
  try:
232
- print(req)
233
  if not req.messages:
234
  raise HTTPException(status_code=400, detail="Nessun messaggio fornito")
235
  if not req.stream:
 
158
  result["properties"] = {"parameter": {"type": "string"}}
159
  return result
160
 
 
161
  def convert_payload_for_gemini(payload: ChatCompletionRequest):
162
  if hasattr(payload, "model_dump"):
163
  payload_converted = json.loads(payload.model_dump_json())
 
165
  payload_converted = payload.copy()
166
  else:
167
  raise ValueError("Formato payload non supportato")
168
+ payload_converted.pop("metadata", None)
169
+ payload_converted.pop("store", None)
170
  if "tools" in payload_converted:
171
  payload_converted["tools"] = convert_openai_schema_for_gemini(payload_converted["tools"])
172
  new_payload = ChatCompletionRequest.model_validate(payload_converted)
 
181
  if params.messages:
182
  params.messages = sanitize_messages(params.messages)
183
  params = convert_payload_for_gemini(params)
184
+ print('------------------------------------- INPUT --------------------------------')
185
  print(params)
186
  response_format = getattr(params, 'response_format', None)
187
  if response_format and getattr(response_format, 'type', None) == 'json_schema':
188
  response = client.beta.chat.completions.parse(**params.model_dump())
189
  else:
190
  response = client.chat.completions.create(**params.model_dump())
191
+ print('------------------------------------- OUTPUT -------------------------------')
192
+ print(response)
193
+ print("")
194
  return response
195
  except Exception as e:
196
  if "429" in str(e):
 
234
  @app.post("/v1/chat/completions", dependencies=[Depends(verify_api_key)])
235
  async def chat_completions(req: ChatCompletionRequest):
236
  try:
 
237
  if not req.messages:
238
  raise HTTPException(status_code=400, detail="Nessun messaggio fornito")
239
  if not req.stream: