mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-06-29 03:31:40 +08:00
feat: 更新 Gemini 模型列表并优化思考过程展示
This commit is contained in:
@@ -29,8 +29,9 @@ async def list_models(
|
||||
logger.info("Handling Gemini models list request")
|
||||
api_key = await key_manager.get_next_working_key()
|
||||
logger.info(f"Using API key: {api_key}")
|
||||
return model_service.get_gemini_models(api_key)
|
||||
|
||||
models_json = model_service.get_gemini_models(api_key)
|
||||
models_json["models"].append({"name": "models/gemini-2.0-flash-exp-search", "version": "2.0", "displayName": "Gemini 2.0 Flash Search Experimental", "description": "Gemini 2.0 Flash Search Experimental", "inputTokenLimit": 32767, "outputTokenLimit": 8192, "supportedGenerationMethods": ["generateContent", "countTokens"], "temperature": 1, "topP": 0.95, "topK": 64, "maxTemperature": 2})
|
||||
return models_json
|
||||
|
||||
@router.post("/models/{model_name}:generateContent")
|
||||
async def generate_content(
|
||||
|
||||
@@ -18,7 +18,6 @@ logger = get_openai_logger()
|
||||
security_service = SecurityService(settings.ALLOWED_TOKENS, settings.AUTH_TOKEN)
|
||||
key_manager = KeyManager(settings.API_KEYS)
|
||||
model_service = ModelService(settings.MODEL_SEARCH)
|
||||
chat_service = ChatService(settings.BASE_URL, key_manager)
|
||||
embedding_service = EmbeddingService(settings.BASE_URL)
|
||||
|
||||
|
||||
@@ -42,6 +41,7 @@ async def chat_completion(
|
||||
authorization: str = Header(None),
|
||||
token: str = Depends(security_service.verify_authorization),
|
||||
):
|
||||
chat_service = ChatService(settings.BASE_URL, key_manager)
|
||||
logger.info("-" * 50 + "chat_completion" + "-" * 50)
|
||||
logger.info(f"Handling chat completion request for model: {request.model}")
|
||||
logger.info(f"Request: \n{request.model_dump_json(indent=2)}")
|
||||
|
||||
@@ -10,7 +10,7 @@ class Settings(BaseSettings):
|
||||
TOOLS_CODE_EXECUTION_ENABLED: bool = False
|
||||
SHOW_SEARCH_LINK: bool = True
|
||||
SHOW_THINKING_PROCESS: bool = True
|
||||
AUTH_TOKEN: str
|
||||
AUTH_TOKEN: str = ""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@@ -96,7 +96,7 @@ class ChatService:
|
||||
if self.thinking_first:
|
||||
self.thinking_first = False
|
||||
self.thinking_status = True
|
||||
text = "【思考过程】\n\n" + parts[0].get("text")
|
||||
text = "> thinking\n\n" + parts[0].get("text")
|
||||
else:
|
||||
text = parts[0].get("text")
|
||||
|
||||
@@ -105,15 +105,15 @@ class ChatService:
|
||||
if self.thinking_first:
|
||||
self.thinking_first = False
|
||||
text = (
|
||||
"【思考过程】\n\n"
|
||||
"> thinking\n\n"
|
||||
+ parts[0].get("text")
|
||||
+ "\n---\n【输出结果】\n\n"
|
||||
+ "\n\n---\n> output\n\n"
|
||||
+ parts[1].get("text")
|
||||
)
|
||||
else:
|
||||
text = (
|
||||
parts[0].get("text")
|
||||
+ "\n---\n【输出结果】\n\n"
|
||||
+ "\n\n---\n> output\n\n"
|
||||
+ parts[1].get("text")
|
||||
)
|
||||
else:
|
||||
@@ -182,9 +182,7 @@ class ChatService:
|
||||
"index": 0,
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"content": response["candidates"][0]["content"]["parts"][0][
|
||||
"text"
|
||||
],
|
||||
"content": response["candidates"][0]["content"]["parts"][0]["text"],
|
||||
},
|
||||
"finish_reason": finish_reason,
|
||||
}
|
||||
@@ -200,14 +198,20 @@ class ChatService:
|
||||
candidate = response["candidates"][0]
|
||||
if "thinking" in model:
|
||||
if settings.SHOW_THINKING_PROCESS:
|
||||
text = (
|
||||
"【思考过程】\n\n"
|
||||
+ candidate["content"]["parts"][0]["text"]
|
||||
+ "\n---\n【输出结果】\n\n"
|
||||
+ candidate["content"]["parts"][1]["text"]
|
||||
)
|
||||
if len(candidate["content"]["parts"]) == 2:
|
||||
text = (
|
||||
"> thinking\n\n"
|
||||
+ candidate["content"]["parts"][0]["text"]
|
||||
+ "\n\n---\n> output\n\n"
|
||||
+ candidate["content"]["parts"][1]["text"]
|
||||
)
|
||||
else:
|
||||
text = candidate["content"]["parts"][0]["text"]
|
||||
else:
|
||||
text = candidate["content"]["parts"][1]["text"]
|
||||
if len(candidate["content"]["parts"]) == 2:
|
||||
text = candidate["content"]["parts"][1]["text"]
|
||||
else:
|
||||
text = candidate["content"]["parts"][0]["text"]
|
||||
else:
|
||||
text = candidate["content"]["parts"][0]["text"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user