Spaces:
Paused
Paused
Upload 4 files
Browse files
app.py
CHANGED
|
@@ -97,7 +97,7 @@ class ResponseWrapper:
|
|
| 97 |
def _extract_text(self) -> str:
|
| 98 |
try:
|
| 99 |
for part in self._data['candidates'][0]['content']['parts']:
|
| 100 |
-
if
|
| 101 |
return part['text']
|
| 102 |
return ""
|
| 103 |
except (KeyError, IndexError):
|
|
@@ -519,6 +519,9 @@ def chat_completions():
|
|
| 519 |
else:
|
| 520 |
try:
|
| 521 |
text_content = response.text
|
|
|
|
|
|
|
|
|
|
| 522 |
except (AttributeError, IndexError, TypeError, ValueError) as e:
|
| 523 |
if "response.candidates" in str(e) or "response.text" in str(e):
|
| 524 |
logger.error(f"用户输入被AI安全过滤器阻止")
|
|
@@ -551,9 +554,9 @@ def chat_completions():
|
|
| 551 |
'finish_reason': 'stop'
|
| 552 |
}],
|
| 553 |
'usage': {
|
| 554 |
-
'prompt_tokens':
|
| 555 |
-
'completion_tokens':
|
| 556 |
-
'total_tokens':
|
| 557 |
}
|
| 558 |
}
|
| 559 |
logger.info(f"200!")
|
|
|
|
| 97 |
def _extract_text(self) -> str:
|
| 98 |
try:
|
| 99 |
for part in self._data['candidates'][0]['content']['parts']:
|
| 100 |
+
if 'thought' not in part:
|
| 101 |
return part['text']
|
| 102 |
return ""
|
| 103 |
except (KeyError, IndexError):
|
|
|
|
| 519 |
else:
|
| 520 |
try:
|
| 521 |
text_content = response.text
|
| 522 |
+
prompt_tokens = response.prompt_token_count
|
| 523 |
+
completion_tokens = response.candidates_token_count
|
| 524 |
+
total_tokens = response.total_token_count
|
| 525 |
except (AttributeError, IndexError, TypeError, ValueError) as e:
|
| 526 |
if "response.candidates" in str(e) or "response.text" in str(e):
|
| 527 |
logger.error(f"用户输入被AI安全过滤器阻止")
|
|
|
|
| 554 |
'finish_reason': 'stop'
|
| 555 |
}],
|
| 556 |
'usage': {
|
| 557 |
+
'prompt_tokens': prompt_tokens,
|
| 558 |
+
'completion_tokens': completion_tokens,
|
| 559 |
+
'total_tokens': total_tokens
|
| 560 |
}
|
| 561 |
}
|
| 562 |
logger.info(f"200!")
|