camel-ai 0.2.9__py3-none-any.whl → 0.2.10__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 (236) hide show
  1. camel/__init__.py +5 -5
  2. camel/agents/__init__.py +4 -4
  3. camel/agents/base.py +4 -4
  4. camel/agents/chat_agent.py +32 -37
  5. camel/agents/critic_agent.py +4 -4
  6. camel/agents/deductive_reasoner_agent.py +4 -4
  7. camel/agents/embodied_agent.py +4 -4
  8. camel/agents/knowledge_graph_agent.py +4 -4
  9. camel/agents/role_assignment_agent.py +4 -4
  10. camel/agents/search_agent.py +4 -4
  11. camel/agents/task_agent.py +4 -4
  12. camel/agents/tool_agents/__init__.py +4 -4
  13. camel/agents/tool_agents/base.py +4 -4
  14. camel/agents/tool_agents/hugging_face_tool_agent.py +4 -4
  15. camel/bots/__init__.py +4 -4
  16. camel/bots/discord_app.py +4 -4
  17. camel/bots/slack/__init__.py +4 -4
  18. camel/bots/slack/models.py +4 -4
  19. camel/bots/slack/slack_app.py +4 -4
  20. camel/bots/telegram_bot.py +4 -4
  21. camel/configs/__init__.py +10 -4
  22. camel/configs/anthropic_config.py +4 -4
  23. camel/configs/base_config.py +4 -4
  24. camel/configs/cohere_config.py +76 -0
  25. camel/configs/deepseek_config.py +134 -0
  26. camel/configs/gemini_config.py +85 -127
  27. camel/configs/groq_config.py +4 -4
  28. camel/configs/litellm_config.py +4 -4
  29. camel/configs/mistral_config.py +4 -4
  30. camel/configs/ollama_config.py +4 -4
  31. camel/configs/openai_config.py +32 -7
  32. camel/configs/qwen_config.py +4 -4
  33. camel/configs/reka_config.py +4 -4
  34. camel/configs/samba_config.py +4 -4
  35. camel/configs/togetherai_config.py +4 -4
  36. camel/configs/vllm_config.py +4 -4
  37. camel/configs/yi_config.py +4 -4
  38. camel/configs/zhipuai_config.py +4 -4
  39. camel/embeddings/__init__.py +6 -4
  40. camel/embeddings/base.py +4 -4
  41. camel/embeddings/mistral_embedding.py +4 -4
  42. camel/embeddings/openai_compatible_embedding.py +91 -0
  43. camel/embeddings/openai_embedding.py +4 -4
  44. camel/embeddings/sentence_transformers_embeddings.py +4 -4
  45. camel/embeddings/vlm_embedding.py +4 -4
  46. camel/generators.py +4 -4
  47. camel/human.py +4 -4
  48. camel/interpreters/__init__.py +4 -4
  49. camel/interpreters/base.py +4 -4
  50. camel/interpreters/docker_interpreter.py +4 -4
  51. camel/interpreters/internal_python_interpreter.py +4 -4
  52. camel/interpreters/interpreter_error.py +4 -4
  53. camel/interpreters/ipython_interpreter.py +4 -4
  54. camel/interpreters/subprocess_interpreter.py +4 -4
  55. camel/loaders/__init__.py +4 -4
  56. camel/loaders/apify_reader.py +4 -4
  57. camel/loaders/base_io.py +4 -4
  58. camel/loaders/chunkr_reader.py +4 -4
  59. camel/loaders/firecrawl_reader.py +4 -4
  60. camel/loaders/jina_url_reader.py +4 -4
  61. camel/loaders/unstructured_io.py +4 -4
  62. camel/memories/__init__.py +4 -4
  63. camel/memories/agent_memories.py +4 -4
  64. camel/memories/base.py +4 -4
  65. camel/memories/blocks/__init__.py +4 -4
  66. camel/memories/blocks/chat_history_block.py +4 -4
  67. camel/memories/blocks/vectordb_block.py +4 -4
  68. camel/memories/context_creators/__init__.py +4 -4
  69. camel/memories/context_creators/score_based.py +4 -4
  70. camel/memories/records.py +4 -4
  71. camel/messages/__init__.py +20 -4
  72. camel/messages/base.py +108 -4
  73. camel/messages/conversion/__init__.py +29 -0
  74. camel/messages/conversion/models.py +178 -0
  75. camel/messages/conversion/sharegpt/__init__.py +20 -0
  76. camel/messages/conversion/sharegpt/function_call_formatter.py +49 -0
  77. camel/messages/conversion/sharegpt/hermes/__init__.py +19 -0
  78. camel/messages/conversion/sharegpt/hermes/hermes_function_formatter.py +128 -0
  79. camel/messages/func_message.py +50 -4
  80. camel/models/__init__.py +8 -4
  81. camel/models/anthropic_model.py +4 -4
  82. camel/models/azure_openai_model.py +4 -4
  83. camel/models/base_model.py +4 -4
  84. camel/models/cohere_model.py +282 -0
  85. camel/models/deepseek_model.py +139 -0
  86. camel/models/gemini_model.py +61 -146
  87. camel/models/groq_model.py +4 -4
  88. camel/models/litellm_model.py +4 -4
  89. camel/models/mistral_model.py +4 -4
  90. camel/models/model_factory.py +10 -4
  91. camel/models/nemotron_model.py +4 -4
  92. camel/models/ollama_model.py +4 -4
  93. camel/models/openai_audio_models.py +4 -4
  94. camel/models/openai_compatible_model.py +4 -4
  95. camel/models/openai_model.py +42 -4
  96. camel/models/qwen_model.py +4 -4
  97. camel/models/reka_model.py +4 -4
  98. camel/models/samba_model.py +6 -5
  99. camel/models/stub_model.py +4 -4
  100. camel/models/togetherai_model.py +4 -4
  101. camel/models/vllm_model.py +4 -4
  102. camel/models/yi_model.py +4 -4
  103. camel/models/zhipuai_model.py +4 -4
  104. camel/personas/__init__.py +17 -0
  105. camel/personas/persona.py +103 -0
  106. camel/personas/persona_hub.py +293 -0
  107. camel/prompts/__init__.py +6 -4
  108. camel/prompts/ai_society.py +4 -4
  109. camel/prompts/base.py +4 -4
  110. camel/prompts/code.py +4 -4
  111. camel/prompts/evaluation.py +4 -4
  112. camel/prompts/generate_text_embedding_data.py +4 -4
  113. camel/prompts/image_craft.py +4 -4
  114. camel/prompts/misalignment.py +4 -4
  115. camel/prompts/multi_condition_image_craft.py +4 -4
  116. camel/prompts/object_recognition.py +4 -4
  117. camel/prompts/persona_hub.py +61 -0
  118. camel/prompts/prompt_templates.py +4 -4
  119. camel/prompts/role_description_prompt_template.py +4 -4
  120. camel/prompts/solution_extraction.py +4 -4
  121. camel/prompts/task_prompt_template.py +4 -4
  122. camel/prompts/translation.py +4 -4
  123. camel/prompts/video_description_prompt.py +4 -4
  124. camel/responses/__init__.py +4 -4
  125. camel/responses/agent_responses.py +4 -4
  126. camel/retrievers/__init__.py +4 -4
  127. camel/retrievers/auto_retriever.py +4 -4
  128. camel/retrievers/base.py +4 -4
  129. camel/retrievers/bm25_retriever.py +4 -4
  130. camel/retrievers/cohere_rerank_retriever.py +7 -9
  131. camel/retrievers/vector_retriever.py +4 -4
  132. camel/runtime/__init__.py +29 -0
  133. camel/runtime/api.py +93 -0
  134. camel/runtime/base.py +45 -0
  135. camel/runtime/configs.py +56 -0
  136. camel/runtime/docker_runtime.py +404 -0
  137. camel/runtime/llm_guard_runtime.py +199 -0
  138. camel/runtime/remote_http_runtime.py +204 -0
  139. camel/runtime/utils/__init__.py +20 -0
  140. camel/runtime/utils/function_risk_toolkit.py +58 -0
  141. camel/runtime/utils/ignore_risk_toolkit.py +72 -0
  142. camel/schemas/__init__.py +17 -0
  143. camel/schemas/base.py +45 -0
  144. camel/schemas/openai_converter.py +116 -0
  145. camel/societies/__init__.py +4 -4
  146. camel/societies/babyagi_playing.py +4 -4
  147. camel/societies/role_playing.py +4 -4
  148. camel/societies/workforce/__init__.py +4 -4
  149. camel/societies/workforce/base.py +4 -4
  150. camel/societies/workforce/prompts.py +4 -4
  151. camel/societies/workforce/role_playing_worker.py +4 -4
  152. camel/societies/workforce/single_agent_worker.py +4 -4
  153. camel/societies/workforce/task_channel.py +4 -4
  154. camel/societies/workforce/utils.py +4 -4
  155. camel/societies/workforce/worker.py +4 -4
  156. camel/societies/workforce/workforce.py +7 -7
  157. camel/storages/__init__.py +4 -4
  158. camel/storages/graph_storages/__init__.py +4 -4
  159. camel/storages/graph_storages/base.py +4 -4
  160. camel/storages/graph_storages/graph_element.py +4 -4
  161. camel/storages/graph_storages/nebula_graph.py +4 -4
  162. camel/storages/graph_storages/neo4j_graph.py +4 -4
  163. camel/storages/key_value_storages/__init__.py +4 -4
  164. camel/storages/key_value_storages/base.py +4 -4
  165. camel/storages/key_value_storages/in_memory.py +4 -4
  166. camel/storages/key_value_storages/json.py +4 -4
  167. camel/storages/key_value_storages/redis.py +4 -4
  168. camel/storages/object_storages/__init__.py +4 -4
  169. camel/storages/object_storages/amazon_s3.py +4 -4
  170. camel/storages/object_storages/azure_blob.py +4 -4
  171. camel/storages/object_storages/base.py +4 -4
  172. camel/storages/object_storages/google_cloud.py +4 -4
  173. camel/storages/vectordb_storages/__init__.py +4 -4
  174. camel/storages/vectordb_storages/base.py +4 -4
  175. camel/storages/vectordb_storages/milvus.py +4 -4
  176. camel/storages/vectordb_storages/qdrant.py +4 -4
  177. camel/tasks/__init__.py +4 -4
  178. camel/tasks/task.py +4 -4
  179. camel/tasks/task_prompt.py +4 -4
  180. camel/terminators/__init__.py +4 -4
  181. camel/terminators/base.py +4 -4
  182. camel/terminators/response_terminator.py +4 -4
  183. camel/terminators/token_limit_terminator.py +4 -4
  184. camel/toolkits/__init__.py +13 -17
  185. camel/toolkits/arxiv_toolkit.py +4 -4
  186. camel/toolkits/ask_news_toolkit.py +7 -18
  187. camel/toolkits/base.py +4 -4
  188. camel/toolkits/code_execution.py +20 -7
  189. camel/toolkits/dalle_toolkit.py +4 -7
  190. camel/toolkits/data_commons_toolkit.py +4 -4
  191. camel/toolkits/function_tool.py +220 -69
  192. camel/toolkits/github_toolkit.py +4 -4
  193. camel/toolkits/google_maps_toolkit.py +4 -4
  194. camel/toolkits/google_scholar_toolkit.py +4 -4
  195. camel/toolkits/human_toolkit.py +52 -0
  196. camel/toolkits/linkedin_toolkit.py +4 -4
  197. camel/toolkits/math_toolkit.py +4 -7
  198. camel/toolkits/notion_toolkit.py +4 -4
  199. camel/toolkits/open_api_specs/biztoc/__init__.py +4 -4
  200. camel/toolkits/open_api_specs/coursera/__init__.py +4 -4
  201. camel/toolkits/open_api_specs/create_qr_code/__init__.py +4 -4
  202. camel/toolkits/open_api_specs/klarna/__init__.py +4 -4
  203. camel/toolkits/open_api_specs/nasa_apod/__init__.py +4 -4
  204. camel/toolkits/open_api_specs/outschool/__init__.py +4 -4
  205. camel/toolkits/open_api_specs/outschool/paths/__init__.py +4 -4
  206. camel/toolkits/open_api_specs/outschool/paths/get_classes.py +4 -4
  207. camel/toolkits/open_api_specs/outschool/paths/search_teachers.py +4 -4
  208. camel/toolkits/open_api_specs/security_config.py +4 -4
  209. camel/toolkits/open_api_specs/speak/__init__.py +4 -4
  210. camel/toolkits/open_api_specs/web_scraper/__init__.py +4 -4
  211. camel/toolkits/open_api_specs/web_scraper/paths/__init__.py +4 -4
  212. camel/toolkits/open_api_specs/web_scraper/paths/scraper.py +4 -4
  213. camel/toolkits/open_api_toolkit.py +4 -4
  214. camel/toolkits/reddit_toolkit.py +4 -4
  215. camel/toolkits/retrieval_toolkit.py +4 -4
  216. camel/toolkits/search_toolkit.py +49 -29
  217. camel/toolkits/slack_toolkit.py +4 -4
  218. camel/toolkits/twitter_toolkit.py +10 -13
  219. camel/toolkits/video_toolkit.py +211 -0
  220. camel/toolkits/weather_toolkit.py +4 -7
  221. camel/toolkits/whatsapp_toolkit.py +6 -6
  222. camel/types/__init__.py +6 -4
  223. camel/types/enums.py +77 -7
  224. camel/types/openai_types.py +6 -4
  225. camel/types/unified_model_type.py +9 -4
  226. camel/utils/__init__.py +35 -33
  227. camel/utils/async_func.py +4 -4
  228. camel/utils/commons.py +4 -4
  229. camel/utils/constants.py +4 -4
  230. camel/utils/response_format.py +63 -0
  231. camel/utils/token_counting.py +4 -4
  232. {camel_ai-0.2.9.dist-info → camel_ai-0.2.10.dist-info}/METADATA +108 -56
  233. camel_ai-0.2.10.dist-info/RECORD +246 -0
  234. camel_ai-0.2.9.dist-info/RECORD +0 -215
  235. {camel_ai-0.2.9.dist-info → camel_ai-0.2.10.dist-info}/LICENSE +0 -0
  236. {camel_ai-0.2.9.dist-info → camel_ai-0.2.10.dist-info}/WHEEL +0 -0
@@ -1,16 +1,16 @@
1
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
- # Licensed under the Apache License, Version 2.0 (the License);
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
5
5
  #
6
6
  # http://www.apache.org/licenses/LICENSE-2.0
7
7
  #
8
8
  # Unless required by applicable law or agreed to in writing, software
9
- # distributed under the License is distributed on an AS IS BASIS,
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
10
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
  from __future__ import annotations
15
15
 
16
16
  from abc import ABC
@@ -0,0 +1,76 @@
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
+ from __future__ import annotations
15
+
16
+ from typing import List, Optional
17
+
18
+ from camel.configs.base_config import BaseConfig
19
+
20
+
21
+ class CohereConfig(BaseConfig):
22
+ r"""Defines the parameters for generating chat completions using the
23
+ Cohere API.
24
+
25
+ Args:
26
+ temperature (float, optional): Sampling temperature to use, between
27
+ :obj:`0` and :obj:`2`. Higher values make the output more random,
28
+ while lower values make it more focused and deterministic.
29
+ (default: :obj:`0.3`)
30
+ documents (list, optional): A list of relevant documents that the
31
+ model can cite to generate a more accurate reply. Each document is
32
+ either a string or document object with content and metadata.
33
+ (default: :obj:`None`)
34
+ max_tokens (int, optional): The maximum number of tokens the model
35
+ will generate as part of the response. (default: :obj:`None`)
36
+ stop_sequences (List(str), optional): A list of up to 5 strings that
37
+ the model will use to stop generation. If the model generates a
38
+ string that matches any of the strings in the list, it will stop
39
+ generating tokens and return the generated text up to that point
40
+ not including the stop sequence. (default: :obj:`None`)
41
+ seed (int, optional): If specified, the backend will make a best
42
+ effort to sample tokens deterministically, such that repeated
43
+ requests with the same seed and parameters should return the same
44
+ result. However, determinism cannot be totally guaranteed.
45
+ (default: :obj:`None`)
46
+ frequency_penalty (float, optional): Min value of `0.0`, max value of
47
+ `1.0`. Used to reduce repetitiveness of generated tokens. The
48
+ higher the value, the stronger a penalty is applied to previously
49
+ present tokens, proportional to how many times they have already
50
+ appeared in the prompt or prior generation. (default: :obj:`0.0`)
51
+ presence_penalty (float, optional): Min value of `0.0`, max value of
52
+ `1.0`. Used to reduce repetitiveness of generated tokens. Similar
53
+ to `frequency_penalty`, except that this penalty is applied
54
+ equally to all tokens that have already appeared, regardless of
55
+ their exact frequencies. (default: :obj:`0.0`)
56
+ k (int, optional): Ensures only the top k most likely tokens are
57
+ considered for generation at each step. Min value of `0`, max
58
+ value of `500`. (default: :obj:`0`)
59
+ p (float, optional): Ensures that only the most likely tokens, with
60
+ total probability mass of `p`, are considered for generation at
61
+ each step. If both k and p are enabled, `p` acts after `k`. Min
62
+ value of `0.01`, max value of `0.99`. (default: :obj:`0.75`)
63
+ """
64
+
65
+ temperature: Optional[float] = 0.2
66
+ documents: Optional[list] = None
67
+ max_tokens: Optional[int] = None
68
+ stop_sequences: Optional[List[str]] = None
69
+ seed: Optional[int] = None
70
+ frequency_penalty: Optional[float] = 0.0
71
+ presence_penalty: Optional[float] = 0.0
72
+ k: Optional[int] = 0
73
+ p: Optional[float] = 0.75
74
+
75
+
76
+ COHERE_API_PARAMS = {param for param in CohereConfig().model_fields.keys()}
@@ -0,0 +1,134 @@
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
+
15
+ from __future__ import annotations
16
+
17
+ from typing import Any, Optional, Sequence, Type, Union
18
+
19
+ from pydantic import BaseModel
20
+
21
+ from camel.configs.base_config import BaseConfig
22
+ from camel.types import NOT_GIVEN, NotGiven
23
+
24
+
25
+ class DeepSeekConfig(BaseConfig):
26
+ r"""Defines the parameters for generating chat completions using the
27
+ DeepSeek API.
28
+
29
+ Args:
30
+ temperature (float, optional): Sampling temperature to use, between
31
+ :obj:`0` and :obj:`2`. Higher values make the output more random,
32
+ while lower values make it more focused and deterministic.
33
+ (default: :obj:`0.2`)
34
+ top_p (float, optional): Controls the diversity and focus of the
35
+ generated results. Higher values make the output more diverse,
36
+ while lower values make it more focused. (default: :obj:`1.0`)
37
+ response_format (object, optional): Specifies the format of the
38
+ returned content. The available values are `{"type": "text"}` or
39
+ `{"type": "json_object"}`. Setting it to `{"type": "json_object"}`
40
+ will output a standard JSON string.
41
+ (default: :obj:`{"type": "text"}`)
42
+ stream (bool, optional): If set, partial message deltas will be sent.
43
+ Tokens will be sent as data-only server-sent events (SSE) as
44
+ they become available, with the stream terminated by a
45
+ data: [DONE] message. (default: :obj:`False`)
46
+ stop (Union[str, list[str]], optional): Up to 16 sequences where
47
+ the API will stop generating further tokens. (default: :obj:`None`)
48
+ max_tokens (int, optional): The maximum number of tokens that can
49
+ be generated in the chat completion. The total length of input
50
+ tokens and generated tokens is limited by the model's context
51
+ length. (default: :obj:`None`)
52
+ presence_penalty (float, optional): Number between -2.0 and 2.0.
53
+ Positive values penalize new tokens based on whether they
54
+ appear in the text so far, increasing the model's likelihood
55
+ to talk about new topics. (default: :obj:`0.0`)
56
+ frequency_penalty (float, optional): Number between -2.0 and 2.0.
57
+ Positive values penalize new tokens based on their existing
58
+ frequency in the text so far, decreasing the model's likelihood
59
+ to repeat the same line verbatim. (default: :obj:`0`)
60
+ tools (list[FunctionTool], optional): A list of tools the model may
61
+ call. Currently, only functions are supported as a tool. Use
62
+ this to provide a list of functions the model may generate JSON
63
+ inputs for. A max of 128 functions are supported.
64
+ (default: :obj:`None`)
65
+ tool_choice (Union[dict[str, str], str], optional): Controls which
66
+ (if any) tool is called by the model. "none" means the model
67
+ will not call any tool and instead generates a message. "auto"
68
+ means the model can pick between generating a message or calling
69
+ one or more tools. "required" means the model must call one or
70
+ more tools. Specifying a particular tool via
71
+ {"type": "function", "function": {"name": "my_function"}} forces
72
+ the model to call that tool. "none" is the default when no tools
73
+ are present. "auto" is the default if tools are present.
74
+ (default: :obj:`"auto"`)
75
+ logprobs (bool, optional): Whether to return log probabilities of
76
+ the output tokens or not. If true, returns the log probabilities
77
+ of each output token returned in the content of message.
78
+ (default: :obj:`False`)
79
+ top_logprobs (int, optional): An integer between 0 and 20 specifying
80
+ the number of most likely tokens to return at each token
81
+ position, each with an associated log probability. logprobs
82
+ must be set to true if this parameter is used.
83
+ (default: :obj:`None`)
84
+ include_usage (bool, optional): When streaming, specifies whether to
85
+ include usage information in `stream_options`. (default:
86
+ :obj:`True`)
87
+ """
88
+
89
+ temperature: float = 0.2 # deepseek default: 1.0
90
+ top_p: float = 1.0
91
+ stream: bool = False
92
+ stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
93
+ max_tokens: Union[int, NotGiven] = NOT_GIVEN
94
+ presence_penalty: float = 0.0
95
+ response_format: Union[Type[BaseModel], dict, NotGiven] = NOT_GIVEN
96
+ frequency_penalty: float = 0.0
97
+ tool_choice: Optional[Union[dict[str, str], str]] = None
98
+ logprobs: bool = False
99
+ top_logprobs: Optional[int] = None
100
+
101
+ def __init__(self, include_usage: bool = True, **kwargs):
102
+ super().__init__(**kwargs)
103
+ # Only set stream_options when stream is True
104
+ # Otherwise, it will raise error when calling the API
105
+ if self.stream:
106
+ self.stream_options = {"include_usage": include_usage}
107
+
108
+ def as_dict(self) -> dict[str, Any]:
109
+ r"""Convert the current configuration to a dictionary.
110
+
111
+ This method converts the current configuration object to a dictionary
112
+ representation, which can be used for serialization or other purposes.
113
+
114
+ Returns:
115
+ dict[str, Any]: A dictionary representation of the current
116
+ configuration.
117
+ """
118
+ config_dict = self.model_dump()
119
+ if self.tools:
120
+ from camel.toolkits import FunctionTool
121
+
122
+ tools_schema = []
123
+ for tool in self.tools:
124
+ if not isinstance(tool, FunctionTool):
125
+ raise ValueError(
126
+ f"The tool {tool} should "
127
+ "be an instance of `FunctionTool`."
128
+ )
129
+ tools_schema.append(tool.get_openai_tool_schema())
130
+ config_dict["tools"] = NOT_GIVEN
131
+ return config_dict
132
+
133
+
134
+ DEEPSEEK_API_PARAMS = {param for param in DeepSeekConfig.model_fields.keys()}
@@ -1,156 +1,114 @@
1
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
- # Licensed under the Apache License, Version 2.0 (the License);
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
5
5
  #
6
6
  # http://www.apache.org/licenses/LICENSE-2.0
7
7
  #
8
8
  # Unless required by applicable law or agreed to in writing, software
9
- # distributed under the License is distributed on an AS IS BASIS,
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
10
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
 
15
+ from __future__ import annotations
15
16
 
16
- from collections.abc import Iterable
17
- from typing import Any, Optional
17
+ from typing import Any, Optional, Sequence, Type, Union
18
18
 
19
- from pydantic import model_validator
19
+ from pydantic import BaseModel
20
20
 
21
21
  from camel.configs.base_config import BaseConfig
22
+ from camel.types import NOT_GIVEN, NotGiven
22
23
 
23
24
 
24
25
  class GeminiConfig(BaseConfig):
25
- r"""A simple dataclass used to configure the generation parameters of
26
- `GenerativeModel.generate_content`.
26
+ r"""Defines the parameters for generating chat completions using the
27
+ Gemini API.
27
28
 
28
29
  Args:
29
- candidate_count (int, optional): Number of responses to return.
30
- stop_sequences (Iterable[str], optional): The set of character
31
- sequences (up to 5) that will stop output generation. If specified
32
- the API will stop at the first appearance of a stop sequence.
33
- The stop sequence will not be included as part of the response.
34
- max_output_tokens (int, optional): The maximum number of tokens to
35
- include in a candidate. If unset, this will default to
36
- output_token_limit specified in the model's specification.
37
- temperature (float, optional): Controls the randomness of the output.
38
- Note: The default value varies by model, see the
39
- `Model.temperature` attribute of the `Model` returned
40
- the `genai.get_model` function. Values can range from [0.0,1.0],
41
- inclusive. A value closer to 1.0 will produce responses that are
42
- more varied and creative, while a value closer to 0.0 will
43
- typically result in more straightforward responses from the model.
44
- top_p (int, optional): The maximum cumulative probability of tokens to
45
- consider when sampling. The model uses combined Top-k and nucleus
46
- sampling. Tokens are sorted based on their assigned probabilities
47
- so that only the most likely tokens are considered. Top-k sampling
48
- directly limits the maximum number of tokens to consider, while
49
- Nucleus sampling limits number of tokens
50
- based on the cumulative probability. Note: The default value varies
51
- by model, see the `Model.top_p` attribute of the `Model` returned
52
- the `genai.get_model` function.
53
- top_k (int, optional): The maximum number of tokens to consider when
54
- sampling. The model uses combined Top-k and nucleus sampling.Top-k
55
- sampling considers the set of `top_k` most probable tokens.
56
- Defaults to 40. Note: The default value varies by model, see the
57
- `Model.top_k` attribute of the `Model` returned the
58
- `genai.get_model` function.
59
- response_mime_type (str, optional): Output response mimetype of the
60
- generated candidate text. Supported mimetype:
61
- `text/plain`: (default) Text output.
62
- `application/json`: JSON response in the candidates.
63
- response_schema (Schema, optional): Specifies the format of the
64
- JSON requested if response_mime_type is `application/json`.
65
- safety_settings (SafetySettingOptions, optional):
66
- Overrides for the model's safety settings.
67
- tools (FunctionLibraryType, optional):
68
- `protos.Tools` more info coming soon.
69
- tool_config (ToolConfigType, optional):
70
- more info coming soon.
71
- request_options (RequestOptionsType, optional):
72
- Options for the request.
30
+ temperature (float, optional): Sampling temperature to use, between
31
+ :obj:`0` and :obj:`2`. Higher values make the output more random,
32
+ while lower values make it more focused and deterministic.
33
+ (default: :obj:`0.2`)
34
+ top_p (float, optional): An alternative to sampling with temperature,
35
+ called nucleus sampling, where the model considers the results of
36
+ the tokens with top_p probability mass. So :obj:`0.1` means only
37
+ the tokens comprising the top 10% probability mass are considered.
38
+ (default: :obj:`1.0`)
39
+ n (int, optional): How many chat completion choices to generate for
40
+ each input message. (default: :obj:`1`)
41
+ response_format (object, optional): An object specifying the format
42
+ that the model must output. Compatible with GPT-4 Turbo and all
43
+ GPT-3.5 Turbo models newer than gpt-3.5-turbo-1106. Setting to
44
+ {"type": "json_object"} enables JSON mode, which guarantees the
45
+ message the model generates is valid JSON. Important: when using
46
+ JSON mode, you must also instruct the model to produce JSON
47
+ yourself via a system or user message. Without this, the model
48
+ may generate an unending stream of whitespace until the generation
49
+ reaches the token limit, resulting in a long-running and seemingly
50
+ "stuck" request. Also note that the message content may be
51
+ partially cut off if finish_reason="length", which indicates the
52
+ generation exceeded max_tokens or the conversation exceeded the
53
+ max context length.
54
+ stream (bool, optional): If True, partial message deltas will be sent
55
+ as data-only server-sent events as they become available.
56
+ (default: :obj:`False`)
57
+ stop (str or list, optional): Up to :obj:`4` sequences where the API
58
+ will stop generating further tokens. (default: :obj:`None`)
59
+ max_tokens (int, optional): The maximum number of tokens to generate
60
+ in the chat completion. The total length of input tokens and
61
+ generated tokens is limited by the model's context length.
62
+ (default: :obj:`None`)
63
+ tools (list[FunctionTool], optional): A list of tools the model may
64
+ call. Currently, only functions are supported as a tool. Use this
65
+ to provide a list of functions the model may generate JSON inputs
66
+ for. A max of 128 functions are supported.
67
+ tool_choice (Union[dict[str, str], str], optional): Controls which (if
68
+ any) tool is called by the model. :obj:`"none"` means the model
69
+ will not call any tool and instead generates a message.
70
+ :obj:`"auto"` means the model can pick between generating a
71
+ message or calling one or more tools. :obj:`"required"` means the
72
+ model must call one or more tools. Specifying a particular tool
73
+ via {"type": "function", "function": {"name": "my_function"}}
74
+ forces the model to call that tool. :obj:`"none"` is the default
75
+ when no tools are present. :obj:`"auto"` is the default if tools
76
+ are present.
73
77
  """
74
78
 
75
- candidate_count: Optional[int] = None
76
- stop_sequences: Optional[Iterable[str]] = None
77
- max_output_tokens: Optional[int] = None
78
- temperature: Optional[float] = None
79
- top_p: Optional[float] = None
80
- top_k: Optional[int] = None
81
- response_mime_type: Optional[str] = None
82
- response_schema: Optional[Any] = None
83
- safety_settings: Optional[Any] = None
84
- tool_config: Optional[Any] = None
85
- request_options: Optional[Any] = None
79
+ temperature: float = 0.2 # openai default: 1.0
80
+ top_p: float = 1.0
81
+ n: int = 1
82
+ stream: bool = False
83
+ stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
84
+ max_tokens: Union[int, NotGiven] = NOT_GIVEN
85
+ response_format: Union[Type[BaseModel], dict, NotGiven] = NOT_GIVEN
86
+ tool_choice: Optional[Union[dict[str, str], str]] = None
86
87
 
87
- @model_validator(mode="before")
88
- @classmethod
89
- def model_type_checking(cls, data: Any):
90
- r"""Validate the type of tools in the configuration.
88
+ def as_dict(self) -> dict[str, Any]:
89
+ r"""Convert the current configuration to a dictionary.
91
90
 
92
- This method ensures that the tools provided in the configuration are
93
- instances of `FunctionTool`. If any tool is not an instance of
94
- `FunctionTool`, it raises a ValueError.
95
- """
96
- if isinstance(data, dict):
97
- response_schema = data.get("response_schema")
98
- safety_settings = data.get("safety_settings")
99
- tools = data.get("tools")
100
- tool_config = data.get("tool_config")
101
- request_options = data.get("request_options")
102
-
103
- if response_schema:
104
- from google.generativeai.protos import Schema
105
- from google.generativeai.types.content_types import (
106
- FunctionLibraryType,
107
- ToolConfigType,
108
- )
109
- from google.generativeai.types.helper_types import (
110
- RequestOptionsType,
111
- )
112
- from google.generativeai.types.safety_types import (
113
- SafetySettingOptions,
114
- )
115
- else:
116
- return data
91
+ This method converts the current configuration object to a dictionary
92
+ representation, which can be used for serialization or other purposes.
117
93
 
118
- if response_schema and not isinstance(response_schema, Schema):
119
- raise ValueError(
120
- "The response_schema should be an instance of "
121
- "google.generativeai.protos.Schema."
122
- )
123
-
124
- if safety_settings and not isinstance(
125
- safety_settings, SafetySettingOptions
126
- ):
127
- raise ValueError(
128
- "The safety_settings should be an instance of "
129
- "google.generativeai.types.safety_types."
130
- "SafetySettingOptions."
131
- )
94
+ Returns:
95
+ dict[str, Any]: A dictionary representation of the current
96
+ configuration.
97
+ """
98
+ config_dict = self.model_dump()
99
+ if self.tools:
100
+ from camel.toolkits import FunctionTool
132
101
 
133
- if tools is not None:
134
- for tool in tools:
135
- if not isinstance(tool, FunctionLibraryType):
102
+ tools_schema = []
103
+ for tool in self.tools:
104
+ if not isinstance(tool, FunctionTool):
136
105
  raise ValueError(
137
- "The tool should be an instance of "
138
- "google.generativeai.types.content_types."
139
- "FunctionLibraryType."
106
+ f"The tool {tool} should "
107
+ "be an instance of `FunctionTool`."
140
108
  )
141
- if tool_config and not isinstance(tool_config, ToolConfigType):
142
- raise ValueError(
143
- "The tool_config should be an instance of "
144
- "google.generativeai.types.content_types.ToolConfigType."
145
- )
146
- if request_options and not isinstance(
147
- request_options, RequestOptionsType
148
- ):
149
- raise ValueError(
150
- "The request_options should be an instance of "
151
- "google.generativeai.types.helper_types.RequestOptionsType."
152
- )
153
- return data
109
+ tools_schema.append(tool.get_openai_tool_schema())
110
+ config_dict["tools"] = NOT_GIVEN
111
+ return config_dict
154
112
 
155
113
 
156
- Gemini_API_PARAMS = {param for param in GeminiConfig().model_fields.keys()}
114
+ Gemini_API_PARAMS = {param for param in GeminiConfig.model_fields.keys()}
@@ -1,16 +1,16 @@
1
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
- # Licensed under the Apache License, Version 2.0 (the License);
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
5
5
  #
6
6
  # http://www.apache.org/licenses/LICENSE-2.0
7
7
  #
8
8
  # Unless required by applicable law or agreed to in writing, software
9
- # distributed under the License is distributed on an AS IS BASIS,
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
10
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
  from __future__ import annotations
15
15
 
16
16
  from typing import Optional, Sequence, Union
@@ -1,16 +1,16 @@
1
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
- # Licensed under the Apache License, Version 2.0 (the License);
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
5
5
  #
6
6
  # http://www.apache.org/licenses/LICENSE-2.0
7
7
  #
8
8
  # Unless required by applicable law or agreed to in writing, software
9
- # distributed under the License is distributed on an AS IS BASIS,
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
10
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
  from __future__ import annotations
15
15
 
16
16
  from typing import List, Optional, Union
@@ -1,16 +1,16 @@
1
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
- # Licensed under the Apache License, Version 2.0 (the License);
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
5
5
  #
6
6
  # http://www.apache.org/licenses/LICENSE-2.0
7
7
  #
8
8
  # Unless required by applicable law or agreed to in writing, software
9
- # distributed under the License is distributed on an AS IS BASIS,
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
10
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
  from __future__ import annotations
15
15
 
16
16
  from typing import Any, Dict, Optional, Union
@@ -1,16 +1,16 @@
1
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
- # Licensed under the Apache License, Version 2.0 (the License);
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
5
5
  #
6
6
  # http://www.apache.org/licenses/LICENSE-2.0
7
7
  #
8
8
  # Unless required by applicable law or agreed to in writing, software
9
- # distributed under the License is distributed on an AS IS BASIS,
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
10
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
  from __future__ import annotations
15
15
 
16
16
  from typing import Sequence, Union
@@ -1,21 +1,21 @@
1
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
2
- # Licensed under the Apache License, Version 2.0 (the License);
1
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
3
  # you may not use this file except in compliance with the License.
4
4
  # You may obtain a copy of the License at
5
5
  #
6
6
  # http://www.apache.org/licenses/LICENSE-2.0
7
7
  #
8
8
  # Unless required by applicable law or agreed to in writing, software
9
- # distributed under the License is distributed on an AS IS BASIS,
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
10
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  # See the License for the specific language governing permissions and
12
12
  # limitations under the License.
13
- # =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
13
+ # ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
14
14
  from __future__ import annotations
15
15
 
16
- from typing import Optional, Sequence, Union
16
+ from typing import Any, Optional, Sequence, Type, Union
17
17
 
18
- from pydantic import Field
18
+ from pydantic import BaseModel, Field
19
19
 
20
20
  from camel.configs.base_config import BaseConfig
21
21
  from camel.types import NOT_GIVEN, NotGiven
@@ -104,11 +104,36 @@ class ChatGPTConfig(BaseConfig):
104
104
  stop: Union[str, Sequence[str], NotGiven] = NOT_GIVEN
105
105
  max_tokens: Union[int, NotGiven] = NOT_GIVEN
106
106
  presence_penalty: float = 0.0
107
- response_format: Union[dict, NotGiven] = NOT_GIVEN
107
+ response_format: Union[Type[BaseModel], dict, NotGiven] = NOT_GIVEN
108
108
  frequency_penalty: float = 0.0
109
109
  logit_bias: dict = Field(default_factory=dict)
110
110
  user: str = ""
111
111
  tool_choice: Optional[Union[dict[str, str], str]] = None
112
112
 
113
+ def as_dict(self) -> dict[str, Any]:
114
+ r"""Convert the current configuration to a dictionary.
115
+
116
+ This method converts the current configuration object to a dictionary
117
+ representation, which can be used for serialization or other purposes.
118
+
119
+ Returns:
120
+ dict[str, Any]: A dictionary representation of the current
121
+ configuration.
122
+ """
123
+ config_dict = self.model_dump()
124
+ if self.tools:
125
+ from camel.toolkits import FunctionTool
126
+
127
+ tools_schema = []
128
+ for tool in self.tools:
129
+ if not isinstance(tool, FunctionTool):
130
+ raise ValueError(
131
+ f"The tool {tool} should "
132
+ "be an instance of `FunctionTool`."
133
+ )
134
+ tools_schema.append(tool.get_openai_tool_schema())
135
+ config_dict["tools"] = NOT_GIVEN
136
+ return config_dict
137
+
113
138
 
114
139
  OPENAI_API_PARAMS = {param for param in ChatGPTConfig.model_fields.keys()}