优化日志
This commit is contained in:
parent
4de6db13f9
commit
3c4a50dc05
10 changed files with 233 additions and 36 deletions
|
|
@ -86,6 +86,7 @@ def get_settings():
|
|||
return jsonify({
|
||||
'proxy_target_url': s.get('proxy_target_url', ''),
|
||||
'proxy_api_key': s.get('proxy_api_key', ''),
|
||||
'debug_mode': s.get('debug_mode', '') or Config.DEBUG_MODE,
|
||||
'env_target_url': Config.PROXY_TARGET_URL,
|
||||
'env_api_key': '***' if Config.PROXY_API_KEY else '',
|
||||
})
|
||||
|
|
@ -99,7 +100,7 @@ def update_settings():
|
|||
return err
|
||||
data = request.get_json(force=True)
|
||||
s = settings.get()
|
||||
for key in ('proxy_target_url', 'proxy_api_key'):
|
||||
for key in ('proxy_target_url', 'proxy_api_key', 'debug_mode'):
|
||||
if key in data:
|
||||
s[key] = data[key]
|
||||
return _save_and_respond(s, '全局设置已更新')
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import json
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
import settings
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from adapters.cc_anthropic_adapter import (
|
||||
|
|
@ -79,7 +80,7 @@ bp = Blueprint('chat', __name__)
|
|||
|
||||
def _dbg(message: str) -> None:
|
||||
"""仅在调试模式下输出详细日志。"""
|
||||
if Config.DEBUG:
|
||||
if settings.get_debug_mode() in ('simple', 'verbose'):
|
||||
logger.info('[聊天补全调试] %s', message)
|
||||
|
||||
|
||||
|
|
@ -233,7 +234,7 @@ def _handle_openai_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'chat.completion.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'chunks': client_chunks,
|
||||
'chunk_count': len(client_chunks),
|
||||
'usage': last_usage,
|
||||
})
|
||||
finalize_turn(turn, usage=last_usage)
|
||||
|
|
@ -274,7 +275,7 @@ def _handle_openai_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'chat.completion.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'chunks': client_chunks,
|
||||
'chunk_count': len(client_chunks),
|
||||
'usage': last_usage,
|
||||
})
|
||||
finalize_turn(turn, usage=last_usage)
|
||||
|
|
@ -384,7 +385,7 @@ def _handle_responses_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'chat.completion.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'chunks': client_chunks,
|
||||
'chunk_count': len(client_chunks),
|
||||
})
|
||||
finalize_turn(turn)
|
||||
|
||||
|
|
@ -486,7 +487,7 @@ def _handle_gemini_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'chat.completion.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'chunks': client_chunks,
|
||||
'chunk_count': len(client_chunks),
|
||||
})
|
||||
finalize_turn(turn)
|
||||
|
||||
|
|
@ -599,7 +600,7 @@ def _handle_anthropic_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'chat.completion.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'chunks': client_chunks,
|
||||
'chunk_count': len(client_chunks),
|
||||
})
|
||||
finalize_turn(turn)
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ def messages_passthrough():
|
|||
set_stream_summary(turn, summary)
|
||||
attach_client_response(turn, {
|
||||
'type': 'messages.stream.summary',
|
||||
'events': client_events,
|
||||
'event_count': len(client_events),
|
||||
})
|
||||
finalize_turn(turn)
|
||||
except req_lib.RequestException as e:
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import json
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
import settings
|
||||
from flask import Blueprint, jsonify, request
|
||||
|
||||
from adapters.cc_anthropic_adapter import cc_to_messages_request, messages_to_cc_response
|
||||
|
|
@ -64,7 +65,7 @@ bp = Blueprint('responses', __name__)
|
|||
|
||||
def _dbg(message: str) -> None:
|
||||
"""仅在调试模式下输出详细日志。"""
|
||||
if Config.DEBUG:
|
||||
if settings.get_debug_mode() in ('simple', 'verbose'):
|
||||
logger.info('[响应生成调试] %s', message)
|
||||
|
||||
|
||||
|
|
@ -203,7 +204,7 @@ def _handle_openai_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'responses.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'events': client_events,
|
||||
'event_count': len(client_events),
|
||||
})
|
||||
finalize_turn(turn)
|
||||
return
|
||||
|
|
@ -319,7 +320,7 @@ def _handle_responses_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'responses.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'events': client_events,
|
||||
'event_count': len(client_events),
|
||||
})
|
||||
finalize_turn(turn)
|
||||
|
||||
|
|
@ -422,7 +423,7 @@ def _handle_gemini_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'responses.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'events': client_events,
|
||||
'event_count': len(client_events),
|
||||
})
|
||||
finalize_turn(turn)
|
||||
|
||||
|
|
@ -530,7 +531,7 @@ def _handle_anthropic_stream(
|
|||
attach_client_response(turn, {
|
||||
'type': 'responses.stream.summary',
|
||||
'model': ctx.client_model,
|
||||
'events': client_events,
|
||||
'event_count': len(client_events),
|
||||
})
|
||||
finalize_turn(turn)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue