Skip to content

[Bug]使用Gemini原生API调用gemini-2.0-flash-thinking-exp时请求失败 #333

Closed

Description

@Neverain

发生了什么

使用Gemini原生API调用gemini-2.0-flash-thinking-exp时请求失败。
AstrBot 请求失败。
错误类型: KeyError
错误信息: 'candidates'

如何复现?

使用Gemini原生API调用gemini-2.0-flash-thinking-exp,尝试对话,结果如下:

Image

AstrBot 版本与部署方式

3.4.17 Docker

操作系统

Linux

额外信息

日志如下:

 [22:02:28| DEBUG] [llm_request.py:67]: 提供商请求 Payload: {'prompt': '\n[User ID: (略), Nickname: (略)]\n涅可,你好', 'session_id': '582419837_None', 'image_urls': [], 'func_tool': [FuncTool(name='python_interpreter', parameters={'type': 'object', 'properties': {}}, description='Use this tool only if user really want to solve a complex problem and the problem can be solved very well by Python code. \nFor example, user can use this tool to solve math problems, edit image, docx, pptx, pdf, etc.', handler=functools.partial(<function Main.python_interpreter at 0x7126aa9f6200>, <packages.python_interpreter.main.Main object at 0x7126aac7ae90>), handler_module_path='packages.python_interpreter.main', active=False), FuncTool(name='web_search', parameters={'type': 'object', 'properties': {'query': {'type': 'string', 'description': "A search query which will be used to fetch the most relevant snippets regarding the user's query"}}}, description="Search the web for answers to the user's query\n", handler=functools.partial(<function Main.search_from_search_engine at 0x7126aa0fe3b0>, <packages.web_searcher.main.Main object at 0x7126aac7afb0>), handler_module_path='packages.web_searcher.main', active=True), FuncTool(name='fetch_url', parameters={'type': 'object', 'properties': {'url': {'type': 'string', 'description': 'The url of the website to fetch content from'}}}, description='fetch the content of a website with the given web url\n', handler=functools.partial(<function Main.fetch_website_content at 0x7126aa0fe440>, <packages.web_searcher.main.Main object at 0x7126aac7afb0>), handler_module_path='packages.web_searcher.main', active=True), FuncTool(name='reminder', parameters={'type': 'object', 'properties': {'text': {'type': 'string', 'description': 'The content of the reminder.'}, 'datetime_str': {'type': 'string', 'description': "Required when user's reminder is a single reminder. The datetime string of the reminder, Must format with %Y-%m-%d %H:%M"}, 'cron_expression': {'type': 'string', 'description': "Required when user's reminder is a repeated reminder. The cron expression of the reminder."}, 'human_readable_cron': {'type': 'string', 'description': 'Optional. The human readable cron expression of the reminder.'}}}, description='Call this function when user ask for setting a reminder. \n', handler=functools.partial(<function Main.reminder_tool at 0x7126a9fb13f0>, <packages.reminder.main.Main object at 0x7126aa0cbc10>), handler_module_path='packages.reminder.main', active=False)], 'contexts': [], 'system_prompt': '\nCurrent datetime: 2025-02-03 22:02\n设定:(略)'} 
 [22:02:28| DEBUG] [gemini_source.py:174]: google_genai_conversation: [{'role': 'user', 'parts': [{'text': '\n[User ID: (略), Nickname: (略)]\n涅可,你好'}]}] 
 [22:02:28| DEBUG] [gemini_source.py:49]: payload: {'system_instruction': {'parts': {'text': '\nCurrent datetime: 2025-02-03 22:02\n设定:(略)'}}, 'tools': [{'function_declarations': [{'name': 'web_search', 'description': "Search the web for answers to the user's query\n", 'parameters': {'type': 'object', 'properties': {'query': {'type': 'string', 'description': "A search query which will be used to fetch the most relevant snippets regarding the user's query"}}}}, {'name': 'fetch_url', 'description': 'fetch the content of a website with the given web url\n', 'parameters': {'type': 'object', 'properties': {'url': {'type': 'string', 'description': 'The url of the website to fetch content from'}}}}]}], 'contents': [{'role': 'user', 'parts': [{'text': '\n[User ID: (略), Nickname: (略)]\n涅可,你好'}]}]} 
 [22:02:28| DEBUG] [gemini_source.py:182]: result: {'error': {'code': 400, 'message': 'Function calling is not enabled for models/gemini-2.0-flash-thinking-exp', 'status': 'INVALID_ARGUMENT'}} 
 [22:02:28| ERROR] [llm_request.py:116]: Traceback (most recent call last):
  File "/AstrBot/astrbot/core/pipeline/process_stage/method/llm_request.py", line 70, in process
    llm_response = await provider.text_chat(**req.__dict__) # 请求 LLM
  File "/AstrBot/astrbot/core/provider/sources/gemini_source.py", line 244, in text_chat
    raise e
  File "/AstrBot/astrbot/core/provider/sources/gemini_source.py", line 226, in text_chat
    llm_response = await self._query(payloads, func_tool)
  File "/AstrBot/astrbot/core/provider/sources/gemini_source.py", line 184, in _query
    candidates = result["candidates"][0]['content']['parts']
KeyError: 'candidates'
 
 [22:02:28| DEBUG] [scheduler.py:22]: 执行阶段 ResultDecorateStage 
 [22:02:28| DEBUG] [scheduler.py:22]: 执行阶段 RespondStage 
 [22:02:28| INFO] [stage.py:45]: AstrBot -> (略)/(略): [Reply]AstrBot 请求失败。
错误类型: KeyError
错误信息: 'candidates' 

你愿意提交 PR 吗?

  • 是的,我愿意提交 PR!

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions