From 9f8f060506d90d0745494e4da9cd6a0a826d803f Mon Sep 17 00:00:00 2001 From: Kirk Lin Date: Sat, 12 Jul 2025 10:12:07 +0800 Subject: [PATCH] feat(llm): Add retry mechanism for LLM API calls (#400) * feat(llm): Add retry mechanism for LLM API calls * feat: configure max_retries for LLM calls via conf.yaml --------- Co-authored-by: Willem Jiang --- conf.yaml.example | 3 +++ src/llms/llm.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/conf.yaml.example b/conf.yaml.example index 9249961..a82c177 100644 --- a/conf.yaml.example +++ b/conf.yaml.example @@ -10,6 +10,7 @@ BASIC_MODEL: base_url: https://ark.cn-beijing.volces.com/api/v3 model: "doubao-1-5-pro-32k-250115" api_key: xxxx + # max_retries: 3 # Maximum number of retries for LLM calls # verify_ssl: false # Uncomment this line to disable SSL certificate verification for self-signed certificates # Reasoning model is optional. @@ -20,6 +21,8 @@ BASIC_MODEL: # base_url: https://ark-cn-beijing.bytedance.net/api/v3 # model: "doubao-1-5-thinking-pro-m-250428" # api_key: xxxx +# max_retries: 3 # Maximum number of retries for LLM calls + # OTHER SETTINGS: # Search engine configuration (Only supports Tavily currently) diff --git a/src/llms/llm.py b/src/llms/llm.py index d20696c..15ba13b 100644 --- a/src/llms/llm.py +++ b/src/llms/llm.py @@ -70,6 +70,10 @@ def _create_llm_use_conf( if not merged_conf: raise ValueError(f"No configuration found for LLM type: {llm_type}") + # Add max_retries to handle rate limit errors + if "max_retries" not in merged_conf: + merged_conf["max_retries"] = 3 + if llm_type == "reasoning": merged_conf["api_base"] = merged_conf.pop("base_url", None)