Spaces:
Running
Running
Upload 4 files
Browse files
app.py
CHANGED
@@ -537,8 +537,8 @@ def chat_completions():
|
|
537 |
completion_tokens = response.candidates_token_count
|
538 |
total_tokens = response.total_token_count
|
539 |
finish_reason = response.finish_reason
|
540 |
-
json_dumps = response.json_dumps
|
541 |
-
logger.info(f"AI响应处理成功↓\n{json_dumps}")
|
542 |
if is_thinking and show_thoughts:
|
543 |
text_content = response.thoughts + '\n' + text_content
|
544 |
except StopCandidateException as e:
|
|
|
537 |
completion_tokens = response.candidates_token_count
|
538 |
total_tokens = response.total_token_count
|
539 |
finish_reason = response.finish_reason
|
540 |
+
# json_dumps = response.json_dumps
|
541 |
+
# logger.info(f"AI响应处理成功↓\n{json_dumps}")
|
542 |
if is_thinking and show_thoughts:
|
543 |
text_content = response.thoughts + '\n' + text_content
|
544 |
except StopCandidateException as e:
|
func.py
CHANGED
@@ -35,7 +35,7 @@ def authenticate_request(request):
|
|
35 |
return True, None, None
|
36 |
|
37 |
def process_messages_for_gemini(messages):
|
38 |
-
|
39 |
errors = []
|
40 |
system_instruction_text = ""
|
41 |
is_system_phase = True
|
@@ -53,11 +53,11 @@ def process_messages_for_gemini(messages):
|
|
53 |
is_system_phase = False
|
54 |
|
55 |
if role == 'user':
|
56 |
-
|
57 |
elif role == 'system':
|
58 |
-
|
59 |
elif role == 'assistant':
|
60 |
-
|
61 |
else:
|
62 |
errors.append(f"Invalid role: {role}")
|
63 |
elif isinstance(content, list):
|
@@ -100,13 +100,13 @@ def process_messages_for_gemini(messages):
|
|
100 |
|
101 |
if parts:
|
102 |
if role in ['user', 'system']:
|
103 |
-
|
104 |
elif role in ['assistant']:
|
105 |
-
|
106 |
else:
|
107 |
errors.append(f"Invalid role: {role}")
|
108 |
|
109 |
if errors:
|
110 |
-
return
|
111 |
else:
|
112 |
-
return
|
|
|
35 |
return True, None, None
|
36 |
|
37 |
def process_messages_for_gemini(messages):
|
38 |
+
gemini_history = []
|
39 |
errors = []
|
40 |
system_instruction_text = ""
|
41 |
is_system_phase = True
|
|
|
53 |
is_system_phase = False
|
54 |
|
55 |
if role == 'user':
|
56 |
+
gemini_history.append({"role": "user", "parts": [{"text": content}]})
|
57 |
elif role == 'system':
|
58 |
+
gemini_history.append({"role": "user", "parts": [{"text": content}]})
|
59 |
elif role == 'assistant':
|
60 |
+
gemini_history.append({"role": "model", "parts": [{"text": content}]})
|
61 |
else:
|
62 |
errors.append(f"Invalid role: {role}")
|
63 |
elif isinstance(content, list):
|
|
|
100 |
|
101 |
if parts:
|
102 |
if role in ['user', 'system']:
|
103 |
+
gemini_history.append({"role": "user", "parts": parts})
|
104 |
elif role in ['assistant']:
|
105 |
+
gemini_history.append({"role": "model", "parts": parts})
|
106 |
else:
|
107 |
errors.append(f"Invalid role: {role}")
|
108 |
|
109 |
if errors:
|
110 |
+
return gemini_history, {"parts": [{"text": system_instruction_text}]}, (jsonify({'error': errors}), 400)
|
111 |
else:
|
112 |
+
return gemini_history, {"parts": [{"text": system_instruction_text}]}, None
|