Spaces:
Sleeping
Sleeping
Update main.py
Browse files98 unmodified lines9910010110210310410510610710810911011111229 unmodified lines1421431441451461471481491 unmodified line15115215315415515615715815916064 unmodified lines22522622722822923098 unmodified linesconverted_properties = {}for prop_name, prop_value in params["properties"].items():cleaned = clean_schema_property(prop_value)if cleaned: # Aggiungi solo se il dizionario non è vuotoconverted_properties[prop_name] = cleanedif converted_properties:converted_params["properties"] = converted_propertiesif "required" in params:converted_params["required"] = params["required"]converted_tool["function"]["parameters"] = converted_paramsconverted_schema.append(converted_tool)return converted_schemadef clean_schema_property(prop):29 unmodified linescleaned_prop = clean_schema_property(prop_value)if cleaned_prop:new_props[prop_name] = cleaned_propif not new_props: # Se vuoto, sostituisci con dummynew_props = {"dummy": {"type": "string"}}result[key] = new_propselif key == "items" and isinstance(value, dict):result[key] = clean_schema_property(value)1 unmodified lineresult[key] = [clean_schema_property(item) if isinstance(item, dict) else item for item in value]else:result[key] = valueif "type" not in result and "properties" in result and result["properties"]:result["type"] = "object"return resultdef convert_payload_for_gemini(payload: ChatCompletionRequest):if hasattr(payload, "model_dump"):payload_converted = json.loads(payload.model_dump_json())64 unmodified lines@app.post("/v1/chat/completions", dependencies=[Depends(verify_api_key)])async def chat_completions(req: ChatCompletionRequest):try:if not req.messages:raise HTTPException(status_code=400, detail="Nessun messaggio fornito")if not req.stream:98 unmodified lines9910010110210310410510610710810911011111211311411511611729 unmodified lines1471481491501511521531541 unmodified line15615715815916016116216316416516664 unmodified lines23123223323423523623798 unmodified linesconverted_properties = {}for prop_name, prop_value in params["properties"].items():cleaned = clean_schema_property(prop_value)if cleaned:converted_properties[prop_name] = cleanedif converted_properties:converted_params["properties"] = converted_propertieselse:converted_params["properties"] = {"parameter": {"type": "string"}}else:converted_params["properties"] = {"parameter": {"type": "string"}}if "required" in params:converted_params["required"] = params["required"]converted_tool["function"]["parameters"] = converted_paramsconverted_schema.append(converted_tool)print(converted_schema)return converted_schemadef clean_schema_property(prop):29 unmodified linescleaned_prop = clean_schema_property(prop_value)if cleaned_prop:new_props[prop_name] = cleaned_propif not new_props:new_props = {"parameter": {"type": "string"}}result[key] = new_propselif key == "items" and isinstance(value, dict):result[key] = clean_schema_property(value)1 unmodified lineresult[key] = [clean_schema_property(item) if isinstance(item, dict) else item for item in value]else:result[key] = valueif result.get("type") == "object" and ("properties" not in result or not result["properties"]):result["properties"] = {"parameter": {"type": "string"}}return resultdef convert_payload_for_gemini(payload: ChatCompletionRequest):if hasattr(payload, "model_dump"):payload_converted = json.loads(payload.model_dump_json())64 unmodified lines@app.post("/v1/chat/completions", dependencies=[Depends(verify_api_key)])async def chat_completions(req: ChatCompletionRequest):try:print(req)if not req.messages:raise HTTPException(status_code=400, detail="Nessun messaggio fornito")if not req.stream:
main.py+12-5