camel-ai 0.2.36__py3-none-any.whl → 0.2.38__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of camel-ai might be problematic. Click here for more details.

Files changed (84) hide show
  1. camel/__init__.py +1 -1
  2. camel/agents/__init__.py +2 -0
  3. camel/agents/repo_agent.py +579 -0
  4. camel/configs/aiml_config.py +20 -19
  5. camel/configs/anthropic_config.py +25 -27
  6. camel/configs/cohere_config.py +11 -10
  7. camel/configs/deepseek_config.py +16 -16
  8. camel/configs/gemini_config.py +8 -8
  9. camel/configs/groq_config.py +18 -19
  10. camel/configs/internlm_config.py +8 -8
  11. camel/configs/litellm_config.py +26 -24
  12. camel/configs/mistral_config.py +8 -8
  13. camel/configs/moonshot_config.py +11 -11
  14. camel/configs/nvidia_config.py +13 -13
  15. camel/configs/ollama_config.py +14 -15
  16. camel/configs/openai_config.py +3 -3
  17. camel/configs/openrouter_config.py +9 -9
  18. camel/configs/qwen_config.py +8 -8
  19. camel/configs/reka_config.py +12 -11
  20. camel/configs/samba_config.py +14 -14
  21. camel/configs/sglang_config.py +15 -16
  22. camel/configs/siliconflow_config.py +18 -17
  23. camel/configs/togetherai_config.py +18 -19
  24. camel/configs/vllm_config.py +18 -19
  25. camel/configs/yi_config.py +7 -8
  26. camel/configs/zhipuai_config.py +8 -9
  27. camel/datagen/evol_instruct/__init__.py +20 -0
  28. camel/datagen/evol_instruct/evol_instruct.py +424 -0
  29. camel/datagen/evol_instruct/scorer.py +166 -0
  30. camel/datagen/evol_instruct/templates.py +268 -0
  31. camel/datasets/static_dataset.py +25 -23
  32. camel/environments/models.py +10 -1
  33. camel/environments/single_step.py +296 -136
  34. camel/extractors/__init__.py +16 -1
  35. camel/interpreters/docker_interpreter.py +1 -1
  36. camel/interpreters/e2b_interpreter.py +1 -1
  37. camel/interpreters/subprocess_interpreter.py +1 -1
  38. camel/loaders/__init__.py +2 -2
  39. camel/loaders/{panda_reader.py → pandas_reader.py} +61 -30
  40. camel/memories/context_creators/score_based.py +198 -67
  41. camel/models/aiml_model.py +9 -3
  42. camel/models/anthropic_model.py +11 -3
  43. camel/models/azure_openai_model.py +9 -3
  44. camel/models/base_audio_model.py +6 -0
  45. camel/models/base_model.py +4 -0
  46. camel/models/deepseek_model.py +9 -3
  47. camel/models/gemini_model.py +9 -3
  48. camel/models/groq_model.py +9 -3
  49. camel/models/internlm_model.py +8 -2
  50. camel/models/model_factory.py +4 -0
  51. camel/models/moonshot_model.py +8 -2
  52. camel/models/nemotron_model.py +9 -3
  53. camel/models/nvidia_model.py +9 -3
  54. camel/models/ollama_model.py +9 -3
  55. camel/models/openai_audio_models.py +5 -3
  56. camel/models/openai_compatible_model.py +9 -3
  57. camel/models/openai_model.py +9 -3
  58. camel/models/openrouter_model.py +9 -3
  59. camel/models/qwen_model.py +9 -3
  60. camel/models/samba_model.py +9 -3
  61. camel/models/sglang_model.py +11 -4
  62. camel/models/siliconflow_model.py +8 -2
  63. camel/models/stub_model.py +2 -1
  64. camel/models/togetherai_model.py +9 -3
  65. camel/models/vllm_model.py +9 -3
  66. camel/models/yi_model.py +9 -3
  67. camel/models/zhipuai_model.py +9 -3
  68. camel/retrievers/auto_retriever.py +14 -0
  69. camel/storages/__init__.py +2 -0
  70. camel/storages/vectordb_storages/__init__.py +2 -0
  71. camel/storages/vectordb_storages/tidb.py +332 -0
  72. camel/toolkits/__init__.py +7 -0
  73. camel/toolkits/browser_toolkit.py +84 -61
  74. camel/toolkits/openai_agent_toolkit.py +131 -0
  75. camel/toolkits/searxng_toolkit.py +207 -0
  76. camel/toolkits/thinking_toolkit.py +230 -0
  77. camel/types/enums.py +4 -0
  78. camel/utils/chunker/code_chunker.py +9 -15
  79. camel/verifiers/base.py +28 -5
  80. camel/verifiers/python_verifier.py +321 -68
  81. {camel_ai-0.2.36.dist-info → camel_ai-0.2.38.dist-info}/METADATA +103 -8
  82. {camel_ai-0.2.36.dist-info → camel_ai-0.2.38.dist-info}/RECORD +84 -75
  83. {camel_ai-0.2.36.dist-info → camel_ai-0.2.38.dist-info}/WHEEL +0 -0
  84. {camel_ai-0.2.36.dist-info → camel_ai-0.2.38.dist-info}/licenses/LICENSE +0 -0
@@ -26,6 +26,7 @@ class BaseAudioModel(ABC):
26
26
  self,
27
27
  api_key: Optional[str] = None,
28
28
  url: Optional[str] = None,
29
+ timeout: Optional[float] = None,
29
30
  ) -> None:
30
31
  r"""Initialize an instance of BaseAudioModel.
31
32
 
@@ -36,9 +37,14 @@ class BaseAudioModel(ABC):
36
37
  url (Optional[str]): Base URL for the audio API. If not provided,
37
38
  will use a default URL or look for an environment variable
38
39
  specific to the implementation.
40
+ timeout (Optional[float], optional): The timeout value in seconds
41
+ for API calls. If not provided, will fall back to the
42
+ MODEL_TIMEOUT environment variable or default to 180 seconds.
43
+ (default: :obj:`None`)
39
44
  """
40
45
  self._api_key = api_key
41
46
  self._url = url
47
+ self._timeout = timeout
42
48
 
43
49
  @abstractmethod
44
50
  def text_to_speech(
@@ -69,6 +69,8 @@ class BaseModelBackend(ABC, metaclass=ModelBackendMeta):
69
69
  token_counter (Optional[BaseTokenCounter], optional): Token
70
70
  counter to use for the model. If not provided,
71
71
  :obj:`OpenAITokenCounter` will be used. (default: :obj:`None`)
72
+ timeout (Optional[float], optional): The timeout value in seconds for
73
+ API calls. (default: :obj:`None`)
72
74
  """
73
75
 
74
76
  def __init__(
@@ -78,6 +80,7 @@ class BaseModelBackend(ABC, metaclass=ModelBackendMeta):
78
80
  api_key: Optional[str] = None,
79
81
  url: Optional[str] = None,
80
82
  token_counter: Optional[BaseTokenCounter] = None,
83
+ timeout: Optional[float] = None,
81
84
  ) -> None:
82
85
  self.model_type: UnifiedModelType = UnifiedModelType(model_type)
83
86
  if model_config_dict is None:
@@ -86,6 +89,7 @@ class BaseModelBackend(ABC, metaclass=ModelBackendMeta):
86
89
  self._api_key = api_key
87
90
  self._url = url
88
91
  self._token_counter = token_counter
92
+ self._timeout = timeout
89
93
  self.check_model_config()
90
94
 
91
95
  @property
@@ -60,6 +60,10 @@ class DeepSeekModel(BaseModelBackend):
60
60
  token_counter (Optional[BaseTokenCounter], optional): Token counter to
61
61
  use for the model. If not provided, :obj:`OpenAITokenCounter`
62
62
  will be used. (default: :obj:`None`)
63
+ timeout (Optional[float], optional): The timeout value in seconds for
64
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
65
+ environment variable or default to 180 seconds.
66
+ (default: :obj:`None`)
63
67
 
64
68
  References:
65
69
  https://api-docs.deepseek.com/
@@ -77,6 +81,7 @@ class DeepSeekModel(BaseModelBackend):
77
81
  api_key: Optional[str] = None,
78
82
  url: Optional[str] = None,
79
83
  token_counter: Optional[BaseTokenCounter] = None,
84
+ timeout: Optional[float] = None,
80
85
  ) -> None:
81
86
  if model_config_dict is None:
82
87
  model_config_dict = DeepSeekConfig().as_dict()
@@ -85,19 +90,20 @@ class DeepSeekModel(BaseModelBackend):
85
90
  "DEEPSEEK_API_BASE_URL",
86
91
  "https://api.deepseek.com",
87
92
  )
93
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
88
94
  super().__init__(
89
- model_type, model_config_dict, api_key, url, token_counter
95
+ model_type, model_config_dict, api_key, url, token_counter, timeout
90
96
  )
91
97
 
92
98
  self._client = OpenAI(
93
- timeout=180,
99
+ timeout=self._timeout,
94
100
  max_retries=3,
95
101
  api_key=self._api_key,
96
102
  base_url=self._url,
97
103
  )
98
104
 
99
105
  self._async_client = AsyncOpenAI(
100
- timeout=180,
106
+ timeout=self._timeout,
101
107
  max_retries=3,
102
108
  api_key=self._api_key,
103
109
  base_url=self._url,
@@ -51,6 +51,10 @@ class GeminiModel(BaseModelBackend):
51
51
  use for the model. If not provided, :obj:`OpenAITokenCounter(
52
52
  ModelType.GPT_4O_MINI)` will be used.
53
53
  (default: :obj:`None`)
54
+ timeout (Optional[float], optional): The timeout value in seconds for
55
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
56
+ environment variable or default to 180 seconds.
57
+ (default: :obj:`None`)
54
58
  """
55
59
 
56
60
  @api_keys_required(
@@ -65,6 +69,7 @@ class GeminiModel(BaseModelBackend):
65
69
  api_key: Optional[str] = None,
66
70
  url: Optional[str] = None,
67
71
  token_counter: Optional[BaseTokenCounter] = None,
72
+ timeout: Optional[float] = None,
68
73
  ) -> None:
69
74
  if model_config_dict is None:
70
75
  model_config_dict = GeminiConfig().as_dict()
@@ -73,17 +78,18 @@ class GeminiModel(BaseModelBackend):
73
78
  "GEMINI_API_BASE_URL",
74
79
  "https://generativelanguage.googleapis.com/v1beta/openai/",
75
80
  )
81
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
76
82
  super().__init__(
77
- model_type, model_config_dict, api_key, url, token_counter
83
+ model_type, model_config_dict, api_key, url, token_counter, timeout
78
84
  )
79
85
  self._client = OpenAI(
80
- timeout=180,
86
+ timeout=self._timeout,
81
87
  max_retries=3,
82
88
  api_key=self._api_key,
83
89
  base_url=self._url,
84
90
  )
85
91
  self._async_client = AsyncOpenAI(
86
- timeout=180,
92
+ timeout=self._timeout,
87
93
  max_retries=3,
88
94
  api_key=self._api_key,
89
95
  base_url=self._url,
@@ -51,6 +51,10 @@ class GroqModel(BaseModelBackend):
51
51
  use for the model. If not provided, :obj:`OpenAITokenCounter(
52
52
  ModelType.GPT_4O_MINI)` will be used.
53
53
  (default: :obj:`None`)
54
+ timeout (Optional[float], optional): The timeout value in seconds for
55
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
56
+ environment variable or default to 180 seconds.
57
+ (default: :obj:`None`)
54
58
  """
55
59
 
56
60
  @api_keys_required([("api_key", "GROQ_API_KEY")])
@@ -61,6 +65,7 @@ class GroqModel(BaseModelBackend):
61
65
  api_key: Optional[str] = None,
62
66
  url: Optional[str] = None,
63
67
  token_counter: Optional[BaseTokenCounter] = None,
68
+ timeout: Optional[float] = None,
64
69
  ) -> None:
65
70
  if model_config_dict is None:
66
71
  model_config_dict = GroqConfig().as_dict()
@@ -68,17 +73,18 @@ class GroqModel(BaseModelBackend):
68
73
  url = url or os.environ.get(
69
74
  "GROQ_API_BASE_URL", "https://api.groq.com/openai/v1"
70
75
  )
76
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
71
77
  super().__init__(
72
- model_type, model_config_dict, api_key, url, token_counter
78
+ model_type, model_config_dict, api_key, url, token_counter, timeout
73
79
  )
74
80
  self._client = OpenAI(
75
- timeout=180,
81
+ timeout=self._timeout,
76
82
  max_retries=3,
77
83
  api_key=self._api_key,
78
84
  base_url=self._url,
79
85
  )
80
86
  self._async_client = AsyncOpenAI(
81
- timeout=180,
87
+ timeout=self._timeout,
82
88
  max_retries=3,
83
89
  api_key=self._api_key,
84
90
  base_url=self._url,
@@ -51,6 +51,10 @@ class InternLMModel(BaseModelBackend):
51
51
  use for the model. If not provided, :obj:`OpenAITokenCounter(
52
52
  ModelType.GPT_4O_MINI)` will be used.
53
53
  (default: :obj:`None`)
54
+ timeout (Optional[float], optional): The timeout value in seconds for
55
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
56
+ environment variable or default to 180 seconds.
57
+ (default: :obj:`None`)
54
58
  """
55
59
 
56
60
  @api_keys_required(
@@ -65,6 +69,7 @@ class InternLMModel(BaseModelBackend):
65
69
  api_key: Optional[str] = None,
66
70
  url: Optional[str] = None,
67
71
  token_counter: Optional[BaseTokenCounter] = None,
72
+ timeout: Optional[float] = None,
68
73
  ) -> None:
69
74
  if model_config_dict is None:
70
75
  model_config_dict = InternLMConfig().as_dict()
@@ -73,11 +78,12 @@ class InternLMModel(BaseModelBackend):
73
78
  "INTERNLM_API_BASE_URL",
74
79
  "https://internlm-chat.intern-ai.org.cn/puyu/api/v1",
75
80
  )
81
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
76
82
  super().__init__(
77
- model_type, model_config_dict, api_key, url, token_counter
83
+ model_type, model_config_dict, api_key, url, token_counter, timeout
78
84
  )
79
85
  self._client = OpenAI(
80
- timeout=180,
86
+ timeout=self._timeout,
81
87
  max_retries=3,
82
88
  api_key=self._api_key,
83
89
  base_url=self._url,
@@ -60,6 +60,7 @@ class ModelFactory:
60
60
  token_counter: Optional[BaseTokenCounter] = None,
61
61
  api_key: Optional[str] = None,
62
62
  url: Optional[str] = None,
63
+ timeout: Optional[int] = None,
63
64
  ) -> BaseModelBackend:
64
65
  r"""Creates an instance of `BaseModelBackend` of the specified type.
65
66
 
@@ -79,6 +80,8 @@ class ModelFactory:
79
80
  with the model service. (default: :obj:`None`)
80
81
  url (Optional[str], optional): The url to the model service.
81
82
  (default: :obj:`None`)
83
+ timeout (Optional[float], optional): The timeout value in seconds
84
+ for API calls. (default: :obj:`None`)
82
85
 
83
86
  Returns:
84
87
  BaseModelBackend: The initialized backend.
@@ -157,4 +160,5 @@ class ModelFactory:
157
160
  api_key=api_key,
158
161
  url=url,
159
162
  token_counter=token_counter,
163
+ timeout=timeout,
160
164
  )
@@ -52,6 +52,10 @@ class MoonshotModel(BaseModelBackend):
52
52
  use for the model. If not provided, :obj:`OpenAITokenCounter(
53
53
  ModelType.GPT_4)` will be used.
54
54
  (default: :obj:`None`)
55
+ timeout (Optional[float], optional): The timeout value in seconds for
56
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
57
+ environment variable or default to 180 seconds.
58
+ (default: :obj:`None`)
55
59
  """
56
60
 
57
61
  @api_keys_required([("api_key", "MOONSHOT_API_KEY")])
@@ -62,6 +66,7 @@ class MoonshotModel(BaseModelBackend):
62
66
  api_key: Optional[str] = None,
63
67
  url: Optional[str] = None,
64
68
  token_counter: Optional[BaseTokenCounter] = None,
69
+ timeout: Optional[float] = None,
65
70
  ) -> None:
66
71
  if model_config_dict is None:
67
72
  model_config_dict = MoonshotConfig().as_dict()
@@ -70,12 +75,13 @@ class MoonshotModel(BaseModelBackend):
70
75
  "MOONSHOT_API_BASE_URL",
71
76
  "https://api.moonshot.cn/v1",
72
77
  )
78
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
73
79
  super().__init__(
74
- model_type, model_config_dict, api_key, url, token_counter
80
+ model_type, model_config_dict, api_key, url, token_counter, timeout
75
81
  )
76
82
  self._client = OpenAI(
77
83
  api_key=self._api_key,
78
- timeout=180,
84
+ timeout=self._timeout,
79
85
  max_retries=3,
80
86
  base_url=self._url,
81
87
  )
@@ -36,6 +36,10 @@ class NemotronModel(BaseModelBackend):
36
36
  the Nvidia service. (default: :obj:`None`)
37
37
  url (Optional[str], optional): The url to the Nvidia service.
38
38
  (default: :obj:`https://integrate.api.nvidia.com/v1`)
39
+ timeout (Optional[float], optional): The timeout value in seconds for
40
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
41
+ environment variable or default to 180 seconds.
42
+ (default: :obj:`None`)
39
43
 
40
44
  Notes:
41
45
  Nemotron model doesn't support additional model config like OpenAI.
@@ -51,20 +55,22 @@ class NemotronModel(BaseModelBackend):
51
55
  model_type: Union[ModelType, str],
52
56
  api_key: Optional[str] = None,
53
57
  url: Optional[str] = None,
58
+ timeout: Optional[float] = None,
54
59
  ) -> None:
55
60
  url = url or os.environ.get(
56
61
  "NVIDIA_API_BASE_URL", "https://integrate.api.nvidia.com/v1"
57
62
  )
58
63
  api_key = api_key or os.environ.get("NVIDIA_API_KEY")
59
- super().__init__(model_type, {}, api_key, url)
64
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
65
+ super().__init__(model_type, {}, api_key, url, None, timeout)
60
66
  self._client = OpenAI(
61
- timeout=180,
67
+ timeout=self._timeout,
62
68
  max_retries=3,
63
69
  base_url=self._url,
64
70
  api_key=self._api_key,
65
71
  )
66
72
  self._async_client = AsyncOpenAI(
67
- timeout=180,
73
+ timeout=self._timeout,
68
74
  max_retries=3,
69
75
  base_url=self._url,
70
76
  api_key=self._api_key,
@@ -47,6 +47,10 @@ class NvidiaModel(BaseModelBackend):
47
47
  use for the model. If not provided, :obj:`OpenAITokenCounter(
48
48
  ModelType.GPT_4)` will be used.
49
49
  (default: :obj:`None`)
50
+ timeout (Optional[float], optional): The timeout value in seconds for
51
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
52
+ environment variable or default to 180 seconds.
53
+ (default: :obj:`None`)
50
54
  """
51
55
 
52
56
  @api_keys_required(
@@ -61,6 +65,7 @@ class NvidiaModel(BaseModelBackend):
61
65
  api_key: Optional[str] = None,
62
66
  url: Optional[str] = None,
63
67
  token_counter: Optional[BaseTokenCounter] = None,
68
+ timeout: Optional[float] = None,
64
69
  ) -> None:
65
70
  if model_config_dict is None:
66
71
  model_config_dict = NvidiaConfig().as_dict()
@@ -68,17 +73,18 @@ class NvidiaModel(BaseModelBackend):
68
73
  url = url or os.environ.get(
69
74
  "NVIDIA_API_BASE_URL", "https://integrate.api.nvidia.com/v1"
70
75
  )
76
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
71
77
  super().__init__(
72
- model_type, model_config_dict, api_key, url, token_counter
78
+ model_type, model_config_dict, api_key, url, token_counter, timeout
73
79
  )
74
80
  self._client = OpenAI(
75
- timeout=180,
81
+ timeout=self._timeout,
76
82
  max_retries=3,
77
83
  api_key=self._api_key,
78
84
  base_url=self._url,
79
85
  )
80
86
  self._async_client = AsyncOpenAI(
81
- timeout=180,
87
+ timeout=self._timeout,
82
88
  max_retries=3,
83
89
  api_key=self._api_key,
84
90
  base_url=self._url,
@@ -49,6 +49,10 @@ class OllamaModel(BaseModelBackend):
49
49
  use for the model. If not provided, :obj:`OpenAITokenCounter(
50
50
  ModelType.GPT_4O_MINI)` will be used.
51
51
  (default: :obj:`None`)
52
+ timeout (Optional[float], optional): The timeout value in seconds for
53
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
54
+ environment variable or default to 180 seconds.
55
+ (default: :obj:`None`)
52
56
 
53
57
  References:
54
58
  https://github.com/ollama/ollama/blob/main/docs/openai.md
@@ -61,24 +65,26 @@ class OllamaModel(BaseModelBackend):
61
65
  api_key: Optional[str] = None,
62
66
  url: Optional[str] = None,
63
67
  token_counter: Optional[BaseTokenCounter] = None,
68
+ timeout: Optional[float] = None,
64
69
  ) -> None:
65
70
  if model_config_dict is None:
66
71
  model_config_dict = OllamaConfig().as_dict()
67
72
  url = url or os.environ.get("OLLAMA_BASE_URL")
73
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
68
74
  super().__init__(
69
- model_type, model_config_dict, api_key, url, token_counter
75
+ model_type, model_config_dict, api_key, url, token_counter, timeout
70
76
  )
71
77
  if not self._url:
72
78
  self._start_server()
73
79
  # Use OpenAI client as interface call Ollama
74
80
  self._client = OpenAI(
75
- timeout=180,
81
+ timeout=self._timeout,
76
82
  max_retries=3,
77
83
  api_key="Set-but-ignored", # required but ignored
78
84
  base_url=self._url,
79
85
  )
80
86
  self._async_client = AsyncOpenAI(
81
- timeout=180,
87
+ timeout=self._timeout,
82
88
  max_retries=3,
83
89
  api_key="Set-but-ignored", # required but ignored
84
90
  base_url=self._url,
@@ -29,19 +29,21 @@ class OpenAIAudioModels(BaseAudioModel):
29
29
  self,
30
30
  api_key: Optional[str] = None,
31
31
  url: Optional[str] = None,
32
+ timeout: Optional[float] = None,
32
33
  ) -> None:
33
34
  r"""Initialize an instance of OpenAI."""
34
- super().__init__(api_key, url)
35
+ super().__init__(api_key, url, timeout)
35
36
  self._url = url or os.environ.get("OPENAI_API_BASE_URL")
36
37
  self._api_key = api_key or os.environ.get("OPENAI_API_KEY")
38
+ self._timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
37
39
  self._client = OpenAI(
38
- timeout=120,
40
+ timeout=self._timeout,
39
41
  max_retries=3,
40
42
  base_url=self._url,
41
43
  api_key=self._api_key,
42
44
  )
43
45
  self._async_client = AsyncOpenAI(
44
- timeout=120,
46
+ timeout=self._timeout,
45
47
  max_retries=3,
46
48
  base_url=self._url,
47
49
  api_key=self._api_key,
@@ -46,6 +46,10 @@ class OpenAICompatibleModel(BaseModelBackend):
46
46
  use for the model. If not provided, :obj:`OpenAITokenCounter(
47
47
  ModelType.GPT_4O_MINI)` will be used.
48
48
  (default: :obj:`None`)
49
+ timeout (Optional[float], optional): The timeout value in seconds for
50
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
51
+ environment variable or default to 180 seconds.
52
+ (default: :obj:`None`)
49
53
  """
50
54
 
51
55
  def __init__(
@@ -55,21 +59,23 @@ class OpenAICompatibleModel(BaseModelBackend):
55
59
  api_key: Optional[str] = None,
56
60
  url: Optional[str] = None,
57
61
  token_counter: Optional[BaseTokenCounter] = None,
62
+ timeout: Optional[float] = None,
58
63
  ) -> None:
59
64
  api_key = api_key or os.environ.get("OPENAI_COMPATIBILITY_API_KEY")
60
65
  url = url or os.environ.get("OPENAI_COMPATIBILITY_API_BASE_URL")
66
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
61
67
  super().__init__(
62
- model_type, model_config_dict, api_key, url, token_counter
68
+ model_type, model_config_dict, api_key, url, token_counter, timeout
63
69
  )
64
70
  self._client = OpenAI(
65
- timeout=180,
71
+ timeout=self._timeout,
66
72
  max_retries=3,
67
73
  api_key=self._api_key,
68
74
  base_url=self._url,
69
75
  )
70
76
 
71
77
  self._async_client = AsyncOpenAI(
72
- timeout=180,
78
+ timeout=self._timeout,
73
79
  max_retries=3,
74
80
  api_key=self._api_key,
75
81
  base_url=self._url,
@@ -60,6 +60,10 @@ class OpenAIModel(BaseModelBackend):
60
60
  token_counter (Optional[BaseTokenCounter], optional): Token counter to
61
61
  use for the model. If not provided, :obj:`OpenAITokenCounter` will
62
62
  be used. (default: :obj:`None`)
63
+ timeout (Optional[float], optional): The timeout value in seconds for
64
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
65
+ environment variable or default to 180 seconds.
66
+ (default: :obj:`None`)
63
67
  """
64
68
 
65
69
  @api_keys_required(
@@ -74,24 +78,26 @@ class OpenAIModel(BaseModelBackend):
74
78
  api_key: Optional[str] = None,
75
79
  url: Optional[str] = None,
76
80
  token_counter: Optional[BaseTokenCounter] = None,
81
+ timeout: Optional[float] = None,
77
82
  ) -> None:
78
83
  if model_config_dict is None:
79
84
  model_config_dict = ChatGPTConfig().as_dict()
80
85
  api_key = api_key or os.environ.get("OPENAI_API_KEY")
81
86
  url = url or os.environ.get("OPENAI_API_BASE_URL")
87
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
82
88
 
83
89
  super().__init__(
84
- model_type, model_config_dict, api_key, url, token_counter
90
+ model_type, model_config_dict, api_key, url, token_counter, timeout
85
91
  )
86
92
 
87
93
  self._client = OpenAI(
88
- timeout=180,
94
+ timeout=self._timeout,
89
95
  max_retries=3,
90
96
  base_url=self._url,
91
97
  api_key=self._api_key,
92
98
  )
93
99
  self._async_client = AsyncOpenAI(
94
- timeout=180,
100
+ timeout=self._timeout,
95
101
  max_retries=3,
96
102
  base_url=self._url,
97
103
  api_key=self._api_key,
@@ -51,6 +51,10 @@ class OpenRouterModel(BaseModelBackend):
51
51
  use for the model. If not provided, :obj:`OpenAITokenCounter(
52
52
  ModelType.GPT_4O_MINI)` will be used.
53
53
  (default: :obj:`None`)
54
+ timeout (Optional[float], optional): The timeout value in seconds for
55
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
56
+ environment variable or default to 180 seconds.
57
+ (default: :obj:`None`)
54
58
  """
55
59
 
56
60
  @api_keys_required([("api_key", "OPENROUTER_API_KEY")])
@@ -61,6 +65,7 @@ class OpenRouterModel(BaseModelBackend):
61
65
  api_key: Optional[str] = None,
62
66
  url: Optional[str] = None,
63
67
  token_counter: Optional[BaseTokenCounter] = None,
68
+ timeout: Optional[float] = None,
64
69
  ) -> None:
65
70
  if model_config_dict is None:
66
71
  model_config_dict = OpenRouterConfig().as_dict()
@@ -68,17 +73,18 @@ class OpenRouterModel(BaseModelBackend):
68
73
  url = url or os.environ.get(
69
74
  "OPENROUTER_API_BASE_URL", "https://openrouter.ai/api/v1"
70
75
  )
76
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
71
77
  super().__init__(
72
- model_type, model_config_dict, api_key, url, token_counter
78
+ model_type, model_config_dict, api_key, url, token_counter, timeout
73
79
  )
74
80
  self._client = OpenAI(
75
- timeout=180,
81
+ timeout=self._timeout,
76
82
  max_retries=3,
77
83
  api_key=self._api_key,
78
84
  base_url=self._url,
79
85
  )
80
86
  self._async_client = AsyncOpenAI(
81
- timeout=180,
87
+ timeout=self._timeout,
82
88
  max_retries=3,
83
89
  api_key=self._api_key,
84
90
  base_url=self._url,
@@ -52,6 +52,10 @@ class QwenModel(BaseModelBackend):
52
52
  use for the model. If not provided, :obj:`OpenAITokenCounter(
53
53
  ModelType.GPT_4O_MINI)` will be used.
54
54
  (default: :obj:`None`)
55
+ timeout (Optional[float], optional): The timeout value in seconds for
56
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
57
+ environment variable or default to 180 seconds.
58
+ (default: :obj:`None`)
55
59
  """
56
60
 
57
61
  @api_keys_required(
@@ -66,6 +70,7 @@ class QwenModel(BaseModelBackend):
66
70
  api_key: Optional[str] = None,
67
71
  url: Optional[str] = None,
68
72
  token_counter: Optional[BaseTokenCounter] = None,
73
+ timeout: Optional[float] = None,
69
74
  ) -> None:
70
75
  if model_config_dict is None:
71
76
  model_config_dict = QwenConfig().as_dict()
@@ -74,17 +79,18 @@ class QwenModel(BaseModelBackend):
74
79
  "QWEN_API_BASE_URL",
75
80
  "https://dashscope.aliyuncs.com/compatible-mode/v1",
76
81
  )
82
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
77
83
  super().__init__(
78
- model_type, model_config_dict, api_key, url, token_counter
84
+ model_type, model_config_dict, api_key, url, token_counter, timeout
79
85
  )
80
86
  self._client = OpenAI(
81
- timeout=180,
87
+ timeout=self._timeout,
82
88
  max_retries=3,
83
89
  api_key=self._api_key,
84
90
  base_url=self._url,
85
91
  )
86
92
  self._async_client = AsyncOpenAI(
87
- timeout=180,
93
+ timeout=self._timeout,
88
94
  max_retries=3,
89
95
  api_key=self._api_key,
90
96
  base_url=self._url,
@@ -73,6 +73,10 @@ class SambaModel(BaseModelBackend):
73
73
  token_counter (Optional[BaseTokenCounter], optional): Token counter to
74
74
  use for the model. If not provided, :obj:`OpenAITokenCounter(
75
75
  ModelType.GPT_4O_MINI)` will be used.
76
+ timeout (Optional[float], optional): The timeout value in seconds for
77
+ API calls. If not provided, will fall back to the MODEL_TIMEOUT
78
+ environment variable or default to 180 seconds.
79
+ (default: :obj:`None`)
76
80
  """
77
81
 
78
82
  @api_keys_required(
@@ -87,6 +91,7 @@ class SambaModel(BaseModelBackend):
87
91
  api_key: Optional[str] = None,
88
92
  url: Optional[str] = None,
89
93
  token_counter: Optional[BaseTokenCounter] = None,
94
+ timeout: Optional[float] = None,
90
95
  ) -> None:
91
96
  if model_config_dict is None:
92
97
  model_config_dict = SambaCloudAPIConfig().as_dict()
@@ -95,19 +100,20 @@ class SambaModel(BaseModelBackend):
95
100
  "SAMBA_API_BASE_URL",
96
101
  "https://api.sambanova.ai/v1",
97
102
  )
103
+ timeout = timeout or float(os.environ.get("MODEL_TIMEOUT", 180))
98
104
  super().__init__(
99
- model_type, model_config_dict, api_key, url, token_counter
105
+ model_type, model_config_dict, api_key, url, token_counter, timeout
100
106
  )
101
107
 
102
108
  if self._url == "https://api.sambanova.ai/v1":
103
109
  self._client = OpenAI(
104
- timeout=180,
110
+ timeout=self._timeout,
105
111
  max_retries=3,
106
112
  base_url=self._url,
107
113
  api_key=self._api_key,
108
114
  )
109
115
  self._async_client = AsyncOpenAI(
110
- timeout=180,
116
+ timeout=self._timeout,
111
117
  max_retries=3,
112
118
  base_url=self._url,
113
119
  api_key=self._api_key,