camel-ai 0.2.9__py3-none-any.whl → 0.2.11__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.
- camel/__init__.py +10 -5
- camel/agents/__init__.py +4 -4
- camel/agents/base.py +4 -4
- camel/agents/chat_agent.py +106 -42
- camel/agents/critic_agent.py +4 -4
- camel/agents/deductive_reasoner_agent.py +8 -5
- camel/agents/embodied_agent.py +4 -4
- camel/agents/knowledge_graph_agent.py +4 -4
- camel/agents/role_assignment_agent.py +4 -4
- camel/agents/search_agent.py +4 -4
- camel/agents/task_agent.py +4 -4
- camel/agents/tool_agents/__init__.py +4 -4
- camel/agents/tool_agents/base.py +4 -4
- camel/agents/tool_agents/hugging_face_tool_agent.py +4 -4
- camel/bots/__init__.py +4 -4
- camel/bots/discord_app.py +4 -4
- camel/bots/slack/__init__.py +4 -4
- camel/bots/slack/models.py +4 -4
- camel/bots/slack/slack_app.py +4 -4
- camel/bots/telegram_bot.py +4 -4
- camel/configs/__init__.py +13 -4
- camel/configs/anthropic_config.py +4 -4
- camel/configs/base_config.py +4 -4
- camel/configs/cohere_config.py +76 -0
- camel/configs/deepseek_config.py +134 -0
- camel/configs/gemini_config.py +85 -127
- camel/configs/groq_config.py +4 -4
- camel/configs/litellm_config.py +4 -4
- camel/configs/mistral_config.py +4 -7
- camel/configs/nvidia_config.py +70 -0
- camel/configs/ollama_config.py +4 -4
- camel/configs/openai_config.py +32 -7
- camel/configs/qwen_config.py +4 -4
- camel/configs/reka_config.py +4 -4
- camel/configs/samba_config.py +4 -4
- camel/configs/togetherai_config.py +4 -4
- camel/configs/vllm_config.py +14 -5
- camel/configs/yi_config.py +4 -4
- camel/configs/zhipuai_config.py +4 -4
- camel/embeddings/__init__.py +6 -4
- camel/embeddings/base.py +4 -4
- camel/embeddings/mistral_embedding.py +4 -4
- camel/embeddings/openai_compatible_embedding.py +91 -0
- camel/embeddings/openai_embedding.py +4 -4
- camel/embeddings/sentence_transformers_embeddings.py +4 -4
- camel/embeddings/vlm_embedding.py +8 -5
- camel/generators.py +4 -4
- camel/human.py +4 -4
- camel/interpreters/__init__.py +4 -4
- camel/interpreters/base.py +4 -4
- camel/interpreters/docker_interpreter.py +11 -6
- camel/interpreters/internal_python_interpreter.py +4 -4
- camel/interpreters/interpreter_error.py +4 -4
- camel/interpreters/ipython_interpreter.py +4 -4
- camel/interpreters/subprocess_interpreter.py +11 -6
- camel/loaders/__init__.py +4 -4
- camel/loaders/apify_reader.py +4 -4
- camel/loaders/base_io.py +4 -4
- camel/loaders/chunkr_reader.py +4 -4
- camel/loaders/firecrawl_reader.py +4 -7
- camel/loaders/jina_url_reader.py +4 -4
- camel/loaders/unstructured_io.py +4 -4
- camel/logger.py +112 -0
- camel/memories/__init__.py +4 -4
- camel/memories/agent_memories.py +4 -4
- camel/memories/base.py +4 -4
- camel/memories/blocks/__init__.py +4 -4
- camel/memories/blocks/chat_history_block.py +4 -4
- camel/memories/blocks/vectordb_block.py +4 -4
- camel/memories/context_creators/__init__.py +4 -4
- camel/memories/context_creators/score_based.py +4 -4
- camel/memories/records.py +4 -4
- camel/messages/__init__.py +20 -4
- camel/messages/base.py +118 -11
- camel/messages/conversion/__init__.py +31 -0
- camel/messages/conversion/alpaca.py +122 -0
- camel/messages/conversion/conversation_models.py +178 -0
- camel/messages/conversion/sharegpt/__init__.py +20 -0
- camel/messages/conversion/sharegpt/function_call_formatter.py +49 -0
- camel/messages/conversion/sharegpt/hermes/__init__.py +19 -0
- camel/messages/conversion/sharegpt/hermes/hermes_function_formatter.py +128 -0
- camel/messages/func_message.py +50 -4
- camel/models/__init__.py +13 -4
- camel/models/anthropic_model.py +4 -4
- camel/models/azure_openai_model.py +4 -4
- camel/models/base_model.py +4 -4
- camel/models/cohere_model.py +282 -0
- camel/models/deepseek_model.py +139 -0
- camel/models/gemini_model.py +61 -146
- camel/models/groq_model.py +4 -4
- camel/models/litellm_model.py +4 -4
- camel/models/mistral_model.py +4 -4
- camel/models/model_factory.py +13 -4
- camel/models/model_manager.py +212 -0
- camel/models/nemotron_model.py +4 -4
- camel/models/nvidia_model.py +141 -0
- camel/models/ollama_model.py +4 -4
- camel/models/openai_audio_models.py +4 -4
- camel/models/openai_compatible_model.py +4 -4
- camel/models/openai_model.py +43 -4
- camel/models/qwen_model.py +4 -4
- camel/models/reka_model.py +4 -4
- camel/models/samba_model.py +6 -5
- camel/models/stub_model.py +4 -4
- camel/models/togetherai_model.py +4 -4
- camel/models/vllm_model.py +4 -4
- camel/models/yi_model.py +4 -4
- camel/models/zhipuai_model.py +4 -4
- camel/personas/__init__.py +17 -0
- camel/personas/persona.py +103 -0
- camel/personas/persona_hub.py +293 -0
- camel/prompts/__init__.py +6 -4
- camel/prompts/ai_society.py +4 -4
- camel/prompts/base.py +4 -4
- camel/prompts/code.py +4 -4
- camel/prompts/evaluation.py +4 -4
- camel/prompts/generate_text_embedding_data.py +4 -4
- camel/prompts/image_craft.py +4 -4
- camel/prompts/misalignment.py +4 -4
- camel/prompts/multi_condition_image_craft.py +4 -4
- camel/prompts/object_recognition.py +4 -4
- camel/prompts/persona_hub.py +61 -0
- camel/prompts/prompt_templates.py +4 -4
- camel/prompts/role_description_prompt_template.py +4 -4
- camel/prompts/solution_extraction.py +4 -4
- camel/prompts/task_prompt_template.py +4 -4
- camel/prompts/translation.py +4 -4
- camel/prompts/video_description_prompt.py +4 -4
- camel/responses/__init__.py +4 -4
- camel/responses/agent_responses.py +4 -4
- camel/retrievers/__init__.py +4 -4
- camel/retrievers/auto_retriever.py +4 -4
- camel/retrievers/base.py +4 -4
- camel/retrievers/bm25_retriever.py +4 -4
- camel/retrievers/cohere_rerank_retriever.py +7 -9
- camel/retrievers/vector_retriever.py +26 -9
- camel/runtime/__init__.py +29 -0
- camel/runtime/api.py +93 -0
- camel/runtime/base.py +45 -0
- camel/runtime/configs.py +56 -0
- camel/runtime/docker_runtime.py +404 -0
- camel/runtime/llm_guard_runtime.py +199 -0
- camel/runtime/remote_http_runtime.py +204 -0
- camel/runtime/utils/__init__.py +20 -0
- camel/runtime/utils/function_risk_toolkit.py +58 -0
- camel/runtime/utils/ignore_risk_toolkit.py +72 -0
- camel/schemas/__init__.py +17 -0
- camel/schemas/base.py +45 -0
- camel/schemas/openai_converter.py +116 -0
- camel/societies/__init__.py +4 -4
- camel/societies/babyagi_playing.py +8 -5
- camel/societies/role_playing.py +4 -4
- camel/societies/workforce/__init__.py +4 -4
- camel/societies/workforce/base.py +4 -4
- camel/societies/workforce/prompts.py +4 -4
- camel/societies/workforce/role_playing_worker.py +4 -4
- camel/societies/workforce/single_agent_worker.py +4 -4
- camel/societies/workforce/task_channel.py +4 -4
- camel/societies/workforce/utils.py +4 -4
- camel/societies/workforce/worker.py +4 -4
- camel/societies/workforce/workforce.py +7 -7
- camel/storages/__init__.py +4 -4
- camel/storages/graph_storages/__init__.py +4 -4
- camel/storages/graph_storages/base.py +4 -4
- camel/storages/graph_storages/graph_element.py +4 -4
- camel/storages/graph_storages/nebula_graph.py +4 -4
- camel/storages/graph_storages/neo4j_graph.py +4 -4
- camel/storages/key_value_storages/__init__.py +4 -4
- camel/storages/key_value_storages/base.py +4 -4
- camel/storages/key_value_storages/in_memory.py +4 -4
- camel/storages/key_value_storages/json.py +4 -4
- camel/storages/key_value_storages/redis.py +4 -4
- camel/storages/object_storages/__init__.py +4 -4
- camel/storages/object_storages/amazon_s3.py +4 -4
- camel/storages/object_storages/azure_blob.py +4 -4
- camel/storages/object_storages/base.py +4 -4
- camel/storages/object_storages/google_cloud.py +4 -4
- camel/storages/vectordb_storages/__init__.py +4 -4
- camel/storages/vectordb_storages/base.py +4 -4
- camel/storages/vectordb_storages/milvus.py +4 -4
- camel/storages/vectordb_storages/qdrant.py +4 -4
- camel/tasks/__init__.py +4 -4
- camel/tasks/task.py +4 -4
- camel/tasks/task_prompt.py +4 -4
- camel/terminators/__init__.py +4 -4
- camel/terminators/base.py +4 -4
- camel/terminators/response_terminator.py +4 -4
- camel/terminators/token_limit_terminator.py +4 -4
- camel/toolkits/__init__.py +16 -17
- camel/toolkits/arxiv_toolkit.py +4 -4
- camel/toolkits/ask_news_toolkit.py +7 -18
- camel/toolkits/base.py +4 -4
- camel/toolkits/code_execution.py +57 -10
- camel/toolkits/dalle_toolkit.py +4 -7
- camel/toolkits/data_commons_toolkit.py +4 -4
- camel/toolkits/function_tool.py +220 -69
- camel/toolkits/github_toolkit.py +4 -4
- camel/toolkits/google_maps_toolkit.py +4 -4
- camel/toolkits/google_scholar_toolkit.py +4 -4
- camel/toolkits/human_toolkit.py +53 -0
- camel/toolkits/linkedin_toolkit.py +4 -4
- camel/toolkits/math_toolkit.py +4 -7
- camel/toolkits/meshy_toolkit.py +185 -0
- camel/toolkits/notion_toolkit.py +4 -4
- camel/toolkits/open_api_specs/biztoc/__init__.py +4 -4
- camel/toolkits/open_api_specs/coursera/__init__.py +4 -4
- camel/toolkits/open_api_specs/create_qr_code/__init__.py +4 -4
- camel/toolkits/open_api_specs/klarna/__init__.py +4 -4
- camel/toolkits/open_api_specs/nasa_apod/__init__.py +4 -4
- camel/toolkits/open_api_specs/outschool/__init__.py +4 -4
- camel/toolkits/open_api_specs/outschool/paths/__init__.py +4 -4
- camel/toolkits/open_api_specs/outschool/paths/get_classes.py +4 -4
- camel/toolkits/open_api_specs/outschool/paths/search_teachers.py +4 -4
- camel/toolkits/open_api_specs/security_config.py +4 -4
- camel/toolkits/open_api_specs/speak/__init__.py +4 -4
- camel/toolkits/open_api_specs/web_scraper/__init__.py +4 -4
- camel/toolkits/open_api_specs/web_scraper/paths/__init__.py +4 -4
- camel/toolkits/open_api_specs/web_scraper/paths/scraper.py +4 -4
- camel/toolkits/open_api_toolkit.py +4 -4
- camel/toolkits/reddit_toolkit.py +4 -4
- camel/toolkits/retrieval_toolkit.py +4 -4
- camel/toolkits/search_toolkit.py +49 -29
- camel/toolkits/slack_toolkit.py +4 -4
- camel/toolkits/twitter_toolkit.py +13 -13
- camel/toolkits/video_toolkit.py +211 -0
- camel/toolkits/weather_toolkit.py +4 -7
- camel/toolkits/whatsapp_toolkit.py +6 -6
- camel/types/__init__.py +6 -4
- camel/types/enums.py +118 -15
- camel/types/openai_types.py +6 -4
- camel/types/unified_model_type.py +9 -4
- camel/utils/__init__.py +35 -33
- camel/utils/async_func.py +4 -4
- camel/utils/commons.py +26 -9
- camel/utils/constants.py +4 -4
- camel/utils/response_format.py +63 -0
- camel/utils/token_counting.py +8 -5
- {camel_ai-0.2.9.dist-info → camel_ai-0.2.11.dist-info}/METADATA +108 -56
- camel_ai-0.2.11.dist-info/RECORD +252 -0
- camel_ai-0.2.9.dist-info/RECORD +0 -215
- {camel_ai-0.2.9.dist-info → camel_ai-0.2.11.dist-info}/LICENSE +0 -0
- {camel_ai-0.2.9.dist-info → camel_ai-0.2.11.dist-info}/WHEEL +0 -0
camel/types/enums.py
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the
|
|
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
|
|
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
|
-
#
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
|
+
import os
|
|
14
15
|
from enum import Enum, EnumMeta
|
|
15
16
|
from typing import cast
|
|
16
17
|
|
|
@@ -26,7 +27,7 @@ class RoleType(Enum):
|
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
class ModelType(UnifiedModelType, Enum):
|
|
29
|
-
DEFAULT = "gpt-4o-mini"
|
|
30
|
+
DEFAULT = os.getenv("DEFAULT_MODEL_TYPE", "gpt-4o-mini")
|
|
30
31
|
|
|
31
32
|
GPT_3_5_TURBO = "gpt-3.5-turbo"
|
|
32
33
|
GPT_4 = "gpt-4"
|
|
@@ -64,11 +65,22 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
64
65
|
CLAUDE_3_5_SONNET = "claude-3-5-sonnet-20240620"
|
|
65
66
|
|
|
66
67
|
# Nvidia models
|
|
67
|
-
|
|
68
|
+
NVIDIA_NEMOTRON_340B_INSTRUCT = "nvidia/nemotron-4-340b-instruct"
|
|
69
|
+
NVIDIA_NEMOTRON_340B_REWARD = "nvidia/nemotron-4-340b-reward"
|
|
70
|
+
NVIDIA_YI_LARGE = "01-ai/yi-large"
|
|
71
|
+
NVIDIA_MISTRAL_LARGE = "mistralai/mistral-large"
|
|
72
|
+
NVIDIA_MIXTRAL_8X7B = "mistralai/mixtral-8x7b-instruct"
|
|
73
|
+
NVIDIA_LLAMA3_70B = "meta/llama3-70b"
|
|
74
|
+
NVIDIA_LLAMA3_1_8B_INSTRUCT = "meta/llama-3.1-8b-instruct"
|
|
75
|
+
NVIDIA_LLAMA3_1_70B_INSTRUCT = "meta/llama-3.1-70b-instruct"
|
|
76
|
+
NVIDIA_LLAMA3_1_405B_INSTRUCT = "meta/llama-3.1-405b-instruct"
|
|
77
|
+
NVIDIA_LLAMA3_2_1B_INSTRUCT = "meta/llama-3.2-1b-instruct"
|
|
78
|
+
NVIDIA_LLAMA3_2_3B_INSTRUCT = "meta/llama-3.2-3b-instruct"
|
|
68
79
|
|
|
69
80
|
# Gemini models
|
|
70
81
|
GEMINI_1_5_FLASH = "gemini-1.5-flash"
|
|
71
82
|
GEMINI_1_5_PRO = "gemini-1.5-pro"
|
|
83
|
+
GEMINI_EXP_1114 = "gemini-exp-1114"
|
|
72
84
|
|
|
73
85
|
# Mistral AI models
|
|
74
86
|
MISTRAL_3B = "ministral-3b-latest"
|
|
@@ -87,6 +99,13 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
87
99
|
REKA_FLASH = "reka-flash"
|
|
88
100
|
REKA_EDGE = "reka-edge"
|
|
89
101
|
|
|
102
|
+
# Cohere models
|
|
103
|
+
COHERE_COMMAND_R_PLUS = "command-r-plus"
|
|
104
|
+
COHERE_COMMAND_R = "command-r"
|
|
105
|
+
COHERE_COMMAND_LIGHT = "command-light"
|
|
106
|
+
COHERE_COMMAND = "command"
|
|
107
|
+
COHERE_COMMAND_NIGHTLY = "command-nightly"
|
|
108
|
+
|
|
90
109
|
# Qwen models (Aliyun)
|
|
91
110
|
QWEN_MAX = "qwen-max"
|
|
92
111
|
QWEN_PLUS = "qwen-plus"
|
|
@@ -97,6 +116,11 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
97
116
|
QWEN_MATH_PLUS = "qwen-math-plus"
|
|
98
117
|
QWEN_MATH_TURBO = "qwen-math-turbo"
|
|
99
118
|
QWEN_CODER_TURBO = "qwen-coder-turbo"
|
|
119
|
+
QWEN_2_5_CODER_32B = "qwen2.5-coder-32b-instruct"
|
|
120
|
+
QWEN_2_5_72B = "qwen2.5-72b-instruct"
|
|
121
|
+
QWEN_2_5_32B = "qwen2.5-32b-instruct"
|
|
122
|
+
QWEN_2_5_14B = "qwen2.5-14b-instruct"
|
|
123
|
+
QWEN_QWQ_32B = "qwq-32b-preview"
|
|
100
124
|
|
|
101
125
|
# Yi models (01-ai)
|
|
102
126
|
YI_LIGHTNING = "yi-lightning"
|
|
@@ -109,6 +133,9 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
109
133
|
YI_LARGE_RAG = "yi-large-rag"
|
|
110
134
|
YI_LARGE_FC = "yi-large-fc"
|
|
111
135
|
|
|
136
|
+
# DeepSeek models
|
|
137
|
+
DEEPSEEK_CHAT = "deepseek-chat"
|
|
138
|
+
|
|
112
139
|
def __str__(self):
|
|
113
140
|
return self.value
|
|
114
141
|
|
|
@@ -148,6 +175,7 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
148
175
|
ModelType.GPT_4,
|
|
149
176
|
ModelType.GPT_4_TURBO,
|
|
150
177
|
ModelType.GPT_4O,
|
|
178
|
+
ModelType.GPT_4O_MINI,
|
|
151
179
|
}
|
|
152
180
|
|
|
153
181
|
@property
|
|
@@ -208,13 +236,19 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
208
236
|
|
|
209
237
|
@property
|
|
210
238
|
def is_nvidia(self) -> bool:
|
|
211
|
-
r"""Returns whether this type of models is
|
|
212
|
-
|
|
213
|
-
Returns:
|
|
214
|
-
bool: Whether this type of models is nvidia.
|
|
215
|
-
"""
|
|
239
|
+
r"""Returns whether this type of models is a NVIDIA model."""
|
|
216
240
|
return self in {
|
|
217
|
-
ModelType.
|
|
241
|
+
ModelType.NVIDIA_NEMOTRON_340B_INSTRUCT,
|
|
242
|
+
ModelType.NVIDIA_NEMOTRON_340B_REWARD,
|
|
243
|
+
ModelType.NVIDIA_YI_LARGE,
|
|
244
|
+
ModelType.NVIDIA_MISTRAL_LARGE,
|
|
245
|
+
ModelType.NVIDIA_LLAMA3_70B,
|
|
246
|
+
ModelType.NVIDIA_MIXTRAL_8X7B,
|
|
247
|
+
ModelType.NVIDIA_LLAMA3_1_8B_INSTRUCT,
|
|
248
|
+
ModelType.NVIDIA_LLAMA3_1_70B_INSTRUCT,
|
|
249
|
+
ModelType.NVIDIA_LLAMA3_1_405B_INSTRUCT,
|
|
250
|
+
ModelType.NVIDIA_LLAMA3_2_1B_INSTRUCT,
|
|
251
|
+
ModelType.NVIDIA_LLAMA3_2_3B_INSTRUCT,
|
|
218
252
|
}
|
|
219
253
|
|
|
220
254
|
@property
|
|
@@ -227,6 +261,7 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
227
261
|
return self in {
|
|
228
262
|
ModelType.GEMINI_1_5_FLASH,
|
|
229
263
|
ModelType.GEMINI_1_5_PRO,
|
|
264
|
+
ModelType.GEMINI_EXP_1114,
|
|
230
265
|
}
|
|
231
266
|
|
|
232
267
|
@property
|
|
@@ -242,6 +277,21 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
242
277
|
ModelType.REKA_FLASH,
|
|
243
278
|
}
|
|
244
279
|
|
|
280
|
+
@property
|
|
281
|
+
def is_cohere(self) -> bool:
|
|
282
|
+
r"""Returns whether this type of models is a Cohere model.
|
|
283
|
+
|
|
284
|
+
Returns:
|
|
285
|
+
bool: Whether this type of models is Cohere.
|
|
286
|
+
"""
|
|
287
|
+
return self in {
|
|
288
|
+
ModelType.COHERE_COMMAND_R_PLUS,
|
|
289
|
+
ModelType.COHERE_COMMAND_R,
|
|
290
|
+
ModelType.COHERE_COMMAND_LIGHT,
|
|
291
|
+
ModelType.COHERE_COMMAND,
|
|
292
|
+
ModelType.COHERE_COMMAND_NIGHTLY,
|
|
293
|
+
}
|
|
294
|
+
|
|
245
295
|
@property
|
|
246
296
|
def is_yi(self) -> bool:
|
|
247
297
|
r"""Returns whether this type of models is Yi model.
|
|
@@ -273,6 +323,17 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
273
323
|
ModelType.QWEN_MATH_PLUS,
|
|
274
324
|
ModelType.QWEN_MATH_TURBO,
|
|
275
325
|
ModelType.QWEN_CODER_TURBO,
|
|
326
|
+
ModelType.QWEN_2_5_CODER_32B,
|
|
327
|
+
ModelType.QWEN_2_5_72B,
|
|
328
|
+
ModelType.QWEN_2_5_32B,
|
|
329
|
+
ModelType.QWEN_2_5_14B,
|
|
330
|
+
ModelType.QWEN_QWQ_32B,
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
@property
|
|
334
|
+
def is_deepseek(self) -> bool:
|
|
335
|
+
return self in {
|
|
336
|
+
ModelType.DEEPSEEK_CHAT,
|
|
276
337
|
}
|
|
277
338
|
|
|
278
339
|
@property
|
|
@@ -285,13 +346,16 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
285
346
|
if self is ModelType.GLM_4V:
|
|
286
347
|
return 1024
|
|
287
348
|
elif self in {
|
|
288
|
-
ModelType.NEMOTRON_4_REWARD,
|
|
289
349
|
ModelType.STUB,
|
|
290
350
|
ModelType.REKA_CORE,
|
|
291
351
|
ModelType.REKA_EDGE,
|
|
292
352
|
ModelType.REKA_FLASH,
|
|
293
353
|
ModelType.QWEN_MATH_PLUS,
|
|
294
354
|
ModelType.QWEN_MATH_TURBO,
|
|
355
|
+
ModelType.COHERE_COMMAND,
|
|
356
|
+
ModelType.COHERE_COMMAND_LIGHT,
|
|
357
|
+
ModelType.NVIDIA_NEMOTRON_340B_INSTRUCT,
|
|
358
|
+
ModelType.NVIDIA_NEMOTRON_340B_REWARD,
|
|
295
359
|
}:
|
|
296
360
|
return 4_096
|
|
297
361
|
elif self in {
|
|
@@ -303,6 +367,7 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
303
367
|
ModelType.GLM_3_TURBO,
|
|
304
368
|
ModelType.GLM_4,
|
|
305
369
|
ModelType.QWEN_VL_PLUS,
|
|
370
|
+
ModelType.NVIDIA_LLAMA3_70B,
|
|
306
371
|
}:
|
|
307
372
|
return 8_192
|
|
308
373
|
elif self in {
|
|
@@ -324,9 +389,16 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
324
389
|
ModelType.YI_LARGE_FC,
|
|
325
390
|
ModelType.QWEN_MAX,
|
|
326
391
|
ModelType.QWEN_VL_MAX,
|
|
392
|
+
ModelType.NVIDIA_YI_LARGE,
|
|
393
|
+
ModelType.NVIDIA_MISTRAL_LARGE,
|
|
394
|
+
ModelType.NVIDIA_MIXTRAL_8X7B,
|
|
395
|
+
ModelType.QWEN_QWQ_32B,
|
|
327
396
|
}:
|
|
328
397
|
return 32_768
|
|
329
|
-
elif self in {
|
|
398
|
+
elif self in {
|
|
399
|
+
ModelType.MISTRAL_MIXTRAL_8x22B,
|
|
400
|
+
ModelType.DEEPSEEK_CHAT,
|
|
401
|
+
}:
|
|
330
402
|
return 64_000
|
|
331
403
|
elif self in {
|
|
332
404
|
ModelType.CLAUDE_2_0,
|
|
@@ -344,6 +416,18 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
344
416
|
ModelType.MISTRAL_PIXTRAL_12B,
|
|
345
417
|
ModelType.MISTRAL_8B,
|
|
346
418
|
ModelType.MISTRAL_3B,
|
|
419
|
+
ModelType.QWEN_2_5_CODER_32B,
|
|
420
|
+
ModelType.QWEN_2_5_72B,
|
|
421
|
+
ModelType.QWEN_2_5_32B,
|
|
422
|
+
ModelType.QWEN_2_5_14B,
|
|
423
|
+
ModelType.COHERE_COMMAND_R,
|
|
424
|
+
ModelType.COHERE_COMMAND_R_PLUS,
|
|
425
|
+
ModelType.COHERE_COMMAND_NIGHTLY,
|
|
426
|
+
ModelType.NVIDIA_LLAMA3_1_8B_INSTRUCT,
|
|
427
|
+
ModelType.NVIDIA_LLAMA3_1_70B_INSTRUCT,
|
|
428
|
+
ModelType.NVIDIA_LLAMA3_1_405B_INSTRUCT,
|
|
429
|
+
ModelType.NVIDIA_LLAMA3_2_1B_INSTRUCT,
|
|
430
|
+
ModelType.NVIDIA_LLAMA3_2_3B_INSTRUCT,
|
|
347
431
|
}:
|
|
348
432
|
return 128_000
|
|
349
433
|
elif self in {
|
|
@@ -371,6 +455,7 @@ class ModelType(UnifiedModelType, Enum):
|
|
|
371
455
|
elif self in {
|
|
372
456
|
ModelType.GEMINI_1_5_FLASH,
|
|
373
457
|
ModelType.GEMINI_1_5_PRO,
|
|
458
|
+
ModelType.GEMINI_EXP_1114, # Not given in docs, assuming the same
|
|
374
459
|
}:
|
|
375
460
|
return 1_048_576
|
|
376
461
|
elif self in {
|
|
@@ -505,7 +590,7 @@ class OpenAPIName(Enum):
|
|
|
505
590
|
|
|
506
591
|
|
|
507
592
|
class ModelPlatformType(Enum):
|
|
508
|
-
DEFAULT = "openai"
|
|
593
|
+
DEFAULT = os.getenv("DEFAULT_MODEL_PLATFORM_TYPE", "openai")
|
|
509
594
|
|
|
510
595
|
OPENAI = "openai"
|
|
511
596
|
AZURE = "azure"
|
|
@@ -521,8 +606,11 @@ class ModelPlatformType(Enum):
|
|
|
521
606
|
TOGETHER = "together"
|
|
522
607
|
OPENAI_COMPATIBLE_MODEL = "openai-compatible-model"
|
|
523
608
|
SAMBA = "samba-nova"
|
|
609
|
+
COHERE = "cohere"
|
|
524
610
|
YI = "lingyiwanwu"
|
|
525
611
|
QWEN = "tongyi-qianwen"
|
|
612
|
+
NVIDIA = "nvidia"
|
|
613
|
+
DEEPSEEK = "deepseek"
|
|
526
614
|
|
|
527
615
|
@property
|
|
528
616
|
def is_openai(self) -> bool:
|
|
@@ -595,6 +683,11 @@ class ModelPlatformType(Enum):
|
|
|
595
683
|
r"""Returns whether this platform is Samba Nova."""
|
|
596
684
|
return self is ModelPlatformType.SAMBA
|
|
597
685
|
|
|
686
|
+
@property
|
|
687
|
+
def is_cohere(self) -> bool:
|
|
688
|
+
r"""Returns whether this platform is Cohere."""
|
|
689
|
+
return self is ModelPlatformType.COHERE
|
|
690
|
+
|
|
598
691
|
@property
|
|
599
692
|
def is_yi(self) -> bool:
|
|
600
693
|
r"""Returns whether this platform is Yi."""
|
|
@@ -605,6 +698,16 @@ class ModelPlatformType(Enum):
|
|
|
605
698
|
r"""Returns whether this platform is Qwen."""
|
|
606
699
|
return self is ModelPlatformType.QWEN
|
|
607
700
|
|
|
701
|
+
@property
|
|
702
|
+
def is_nvidia(self) -> bool:
|
|
703
|
+
r"""Returns whether this platform is Nvidia."""
|
|
704
|
+
return self is ModelPlatformType.NVIDIA
|
|
705
|
+
|
|
706
|
+
@property
|
|
707
|
+
def is_deepseek(self) -> bool:
|
|
708
|
+
r"""Returns whether this platform is DeepSeek."""
|
|
709
|
+
return self is ModelPlatformType.DEEPSEEK
|
|
710
|
+
|
|
608
711
|
|
|
609
712
|
class AudioModelType(Enum):
|
|
610
713
|
TTS_1 = "tts-1"
|
camel/types/openai_types.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the
|
|
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
|
|
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
|
-
#
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
# isort: skip_file
|
|
15
15
|
from openai.types.chat.chat_completion import ChatCompletion, Choice
|
|
16
16
|
from openai.types.chat.chat_completion_assistant_message_param import (
|
|
@@ -31,6 +31,7 @@ from openai.types.chat.chat_completion_user_message_param import (
|
|
|
31
31
|
ChatCompletionUserMessageParam,
|
|
32
32
|
)
|
|
33
33
|
from openai.types.completion_usage import CompletionUsage
|
|
34
|
+
from openai.types.chat import ParsedChatCompletion
|
|
34
35
|
from openai._types import NOT_GIVEN, NotGiven
|
|
35
36
|
|
|
36
37
|
Choice = Choice
|
|
@@ -45,3 +46,4 @@ ChatCompletionFunctionMessageParam = ChatCompletionFunctionMessageParam
|
|
|
45
46
|
CompletionUsage = CompletionUsage
|
|
46
47
|
NOT_GIVEN = NOT_GIVEN
|
|
47
48
|
NotGiven = NotGiven
|
|
49
|
+
ParsedChatCompletion = ParsedChatCompletion
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the
|
|
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
|
|
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
|
-
#
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
import logging
|
|
15
15
|
from threading import Lock
|
|
16
16
|
from typing import TYPE_CHECKING, ClassVar, Dict, Union, cast
|
|
@@ -98,6 +98,11 @@ class UnifiedModelType(str):
|
|
|
98
98
|
r"""Returns whether the model is a Reka model."""
|
|
99
99
|
return True
|
|
100
100
|
|
|
101
|
+
@property
|
|
102
|
+
def is_cohere(self) -> bool:
|
|
103
|
+
r"""Returns whether the model is a Cohere model."""
|
|
104
|
+
return True
|
|
105
|
+
|
|
101
106
|
@property
|
|
102
107
|
def is_yi(self) -> bool:
|
|
103
108
|
r"""Returns whether the model is a Yi model."""
|
camel/utils/__init__.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the
|
|
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
|
|
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
|
-
#
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
|
|
15
15
|
from .commons import (
|
|
16
16
|
AgentOpsMeta,
|
|
@@ -36,6 +36,7 @@ from .commons import (
|
|
|
36
36
|
track_agent,
|
|
37
37
|
)
|
|
38
38
|
from .constants import Constants
|
|
39
|
+
from .response_format import get_pydantic_model
|
|
39
40
|
from .token_counting import (
|
|
40
41
|
AnthropicTokenCounter,
|
|
41
42
|
BaseTokenCounter,
|
|
@@ -47,33 +48,34 @@ from .token_counting import (
|
|
|
47
48
|
)
|
|
48
49
|
|
|
49
50
|
__all__ = [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
51
|
+
"print_text_animated",
|
|
52
|
+
"get_prompt_template_key_words",
|
|
53
|
+
"get_first_int",
|
|
54
|
+
"download_tasks",
|
|
55
|
+
"get_task_list",
|
|
56
|
+
"check_server_running",
|
|
57
|
+
"AnthropicTokenCounter",
|
|
58
|
+
"get_system_information",
|
|
59
|
+
"to_pascal",
|
|
60
|
+
"get_model_encoding",
|
|
61
|
+
"BaseTokenCounter",
|
|
62
|
+
"OpenAITokenCounter",
|
|
63
|
+
"LiteLLMTokenCounter",
|
|
64
|
+
"Constants",
|
|
65
|
+
"text_extract_from_web",
|
|
66
|
+
"create_chunks",
|
|
67
|
+
"dependencies_required",
|
|
68
|
+
"api_keys_required",
|
|
69
|
+
"is_docker_running",
|
|
70
|
+
"GeminiTokenCounter",
|
|
71
|
+
"MistralTokenCounter",
|
|
72
|
+
"get_pydantic_major_version",
|
|
73
|
+
"get_pydantic_object_schema",
|
|
74
|
+
"func_string_to_callable",
|
|
75
|
+
"json_to_function_code",
|
|
76
|
+
"agentops_decorator",
|
|
77
|
+
"AgentOpsMeta",
|
|
78
|
+
"track_agent",
|
|
79
|
+
"handle_http_error",
|
|
80
|
+
"get_pydantic_model",
|
|
79
81
|
]
|
camel/utils/async_func.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the
|
|
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
|
|
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
|
-
#
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
import asyncio
|
|
15
15
|
from copy import deepcopy
|
|
16
16
|
|
camel/utils/commons.py
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the
|
|
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
|
|
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
|
-
#
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
import importlib
|
|
15
|
+
import logging
|
|
15
16
|
import os
|
|
16
17
|
import platform
|
|
17
18
|
import re
|
|
@@ -39,14 +40,19 @@ import pydantic
|
|
|
39
40
|
import requests
|
|
40
41
|
from pydantic import BaseModel
|
|
41
42
|
|
|
43
|
+
from camel.logger import get_logger
|
|
42
44
|
from camel.types import TaskType
|
|
43
45
|
|
|
44
46
|
from .constants import Constants
|
|
45
47
|
|
|
46
48
|
F = TypeVar('F', bound=Callable[..., Any])
|
|
47
49
|
|
|
50
|
+
logger = get_logger(__name__)
|
|
48
51
|
|
|
49
|
-
|
|
52
|
+
|
|
53
|
+
def print_text_animated(
|
|
54
|
+
text, delay: float = 0.02, end: str = "", log_level: int = logging.INFO
|
|
55
|
+
):
|
|
50
56
|
r"""Prints the given text with an animated effect.
|
|
51
57
|
|
|
52
58
|
Args:
|
|
@@ -55,11 +61,22 @@ def print_text_animated(text, delay: float = 0.02, end: str = ""):
|
|
|
55
61
|
(default: :obj:`0.02`)
|
|
56
62
|
end (str, optional): The end character to print after each
|
|
57
63
|
character of text. (default: :obj:`""`)
|
|
64
|
+
log_level (int, optional): The log level to use.
|
|
65
|
+
See https://docs.python.org/3/library/logging.html#levels
|
|
66
|
+
(default: :obj:`logging.INFO`)
|
|
58
67
|
"""
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
if logger.isEnabledFor(log_level):
|
|
69
|
+
# timestamp and other prefixes
|
|
70
|
+
logger.log(log_level, '')
|
|
71
|
+
|
|
72
|
+
for char in text:
|
|
73
|
+
print(char, end=end, flush=True)
|
|
74
|
+
time.sleep(delay)
|
|
75
|
+
# Close the log entry
|
|
76
|
+
logger.log(log_level, '')
|
|
77
|
+
else:
|
|
78
|
+
# This may be relevant for logging frameworks
|
|
79
|
+
logger.log(log_level, text)
|
|
63
80
|
|
|
64
81
|
|
|
65
82
|
def get_prompt_template_key_words(template: str) -> Set[str]:
|
camel/utils/constants.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the
|
|
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
|
|
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
|
-
#
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class Constants:
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
import inspect
|
|
18
|
+
import json
|
|
19
|
+
from typing import Callable, Type, Union
|
|
20
|
+
|
|
21
|
+
from pydantic import BaseModel, create_model
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_pydantic_model(
|
|
25
|
+
input_data: Union[str, Type[BaseModel], Callable],
|
|
26
|
+
) -> Type[BaseModel]:
|
|
27
|
+
r"""A multi-purpose function that can be used as a normal function,
|
|
28
|
+
a class decorator, or a function decorator.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
input_data (Union[str, type, Callable]):
|
|
32
|
+
- If a string is provided, it should be a JSON-encoded string
|
|
33
|
+
that will be converted into a BaseModel.
|
|
34
|
+
- If a function is provided, it will be decorated such that
|
|
35
|
+
its arguments are converted into a BaseModel.
|
|
36
|
+
- If a BaseModel class is provided, it will be returned directly.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
Type[BaseModel]: The BaseModel class that will be used to
|
|
40
|
+
structure the input data.
|
|
41
|
+
"""
|
|
42
|
+
if isinstance(input_data, str):
|
|
43
|
+
data_dict = json.loads(input_data)
|
|
44
|
+
TemporaryModel = create_model( # type: ignore[call-overload]
|
|
45
|
+
"TemporaryModel",
|
|
46
|
+
**{key: (type(value), None) for key, value in data_dict.items()},
|
|
47
|
+
)
|
|
48
|
+
return TemporaryModel(**data_dict).__class__
|
|
49
|
+
|
|
50
|
+
elif callable(input_data):
|
|
51
|
+
WrapperClass = create_model( # type: ignore[call-overload]
|
|
52
|
+
f"{input_data.__name__.capitalize()}Model",
|
|
53
|
+
**{
|
|
54
|
+
name: (param.annotation, ...)
|
|
55
|
+
for name, param in inspect.signature(
|
|
56
|
+
input_data
|
|
57
|
+
).parameters.items()
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
return WrapperClass
|
|
61
|
+
if issubclass(input_data, BaseModel):
|
|
62
|
+
return input_data
|
|
63
|
+
raise ValueError("Invalid input data provided.")
|
camel/utils/token_counting.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the
|
|
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
|
|
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
|
-
#
|
|
13
|
+
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
|
|
14
14
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
@@ -22,6 +22,7 @@ from typing import TYPE_CHECKING, List, Optional
|
|
|
22
22
|
|
|
23
23
|
from PIL import Image
|
|
24
24
|
|
|
25
|
+
from camel.logger import get_logger
|
|
25
26
|
from camel.types import (
|
|
26
27
|
ModelType,
|
|
27
28
|
OpenAIImageType,
|
|
@@ -44,6 +45,8 @@ SQUARE_PIXELS = 512
|
|
|
44
45
|
SQUARE_TOKENS = 170
|
|
45
46
|
EXTRA_TOKENS = 85
|
|
46
47
|
|
|
48
|
+
logger = get_logger(__name__)
|
|
49
|
+
|
|
47
50
|
|
|
48
51
|
def get_model_encoding(value_for_tiktoken: str):
|
|
49
52
|
r"""Get model encoding from tiktoken.
|
|
@@ -65,7 +68,7 @@ def get_model_encoding(value_for_tiktoken: str):
|
|
|
65
68
|
]:
|
|
66
69
|
encoding = tiktoken.get_encoding("o200k_base")
|
|
67
70
|
else:
|
|
68
|
-
|
|
71
|
+
logger.info("Model not found. Using cl100k_base encoding.")
|
|
69
72
|
encoding = tiktoken.get_encoding("cl100k_base")
|
|
70
73
|
return encoding
|
|
71
74
|
|