Spaces:
Paused
Paused
Upload 4 files
Browse files536 unmodified lines537538539540541542543544536 unmodified linescompletion_tokens = response.candidates_token_counttotal_tokens = response.total_token_countfinish_reason = response.finish_reasonjson_dumps = response.json_dumpslogger.info(f"AI响应处理成功↓\n{json_dumps}")if is_thinking and show_thoughts:text_content = response.thoughts + '\n' + text_contentexcept StopCandidateException as e:536 unmodified lines537538539540541542543544536 unmodified linescompletion_tokens = response.candidates_token_counttotal_tokens = response.total_token_countfinish_reason = response.finish_reason# json_dumps = response.json_dumps# logger.info(f"AI响应处理成功↓\n{json_dumps}")if is_thinking and show_thoughts:text_content = response.thoughts + '\n' + text_contentexcept StopCandidateException as e:
34 unmodified lines3536373839404111 unmodified lines535455565758596061626336 unmodified lines10010110210310410510610710810911011111234 unmodified linesreturn True, None, Nonedef process_messages_for_gemini(messages):contents = []errors = []system_instruction_text = ""is_system_phase = True11 unmodified linesis_system_phase = Falseif role == 'user':contents.append({"role": "user", "parts": [{"text": content}]})elif role == 'system':contents.append({"role": "user", "parts": [{"text": content}]})elif role == 'assistant':contents.append({"role": "model", "parts": [{"text": content}]})else:errors.append(f"Invalid role: {role}")elif isinstance(content, list):36 unmodified linesif parts:if role in ['user', 'system']:contents.append({"role": "user", "parts": parts})elif role in ['assistant']:contents.append({"role": "model", "parts": parts})else:errors.append(f"Invalid role: {role}")if errors:return contents, {"parts": [{"text": system_instruction_text}]}, (jsonify({'error': errors}), 400)else:return contents, {"parts": [{"text": system_instruction_text}]}, None34 unmodified lines3536373839404111 unmodified lines535455565758596061626336 unmodified lines10010110210310410510610710810911011111234 unmodified linesreturn True, None, Nonedef process_messages_for_gemini(messages):gemini_history = []errors = []system_instruction_text = ""is_system_phase = True11 unmodified linesis_system_phase = Falseif role == 'user':gemini_history.append({"role": "user", "parts": [{"text": content}]})elif role == 'system':gemini_history.append({"role": "user", "parts": [{"text": content}]})elif role == 'assistant':gemini_history.append({"role": "model", "parts": [{"text": content}]})else:errors.append(f"Invalid role: {role}")elif isinstance(content, list):36 unmodified linesif parts:if role in ['user', 'system']:gemini_history.append({"role": "user", "parts": parts})elif role in ['assistant']:gemini_history.append({"role": "model", "parts": parts})else:errors.append(f"Invalid role: {role}")if errors:return gemini_history, {"parts": [{"text": system_instruction_text}]}, (jsonify({'error': errors}), 400)else:return gemini_history, {"parts": [{"text": system_instruction_text}]}, None
app.py+2-2
func.py+8-8