Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

feat: Support OpenAI gpt 4.1 (#2188)

Wendong-Fand2f2fc6932a7
diff --git a/camel/models/litellm_model.py b/camel/models/litellm_model.py
index e0d602485..c76bb4c20 100644
--- a/camel/models/litellm_model.py
+++ b/camel/models/litellm_model.py
@@ -70,9 +70,7 @@ class LiteLLMModel(BaseModelBackend):
super().__init__(
model_type, model_config_dict, api_key, url, token_counter, timeout
)
- self.client = completion(
- timeout=self._timeout, api_key=self._api_key, base_url=self._url
- )
+ self.client = completion
def _convert_response_from_litellm_to_openai(
self, response
@@ -135,6 +133,7 @@ class LiteLLMModel(BaseModelBackend):
ChatCompletion
"""
response = self.client(
+ timeout=self._timeout,
api_key=self._api_key,
base_url=self._url,
model=self.model_type,
diff --git a/camel/types/enums.py b/camel/types/enums.py
index 73ad5c509..2adeb50cb 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -39,6 +39,9 @@ class ModelType(UnifiedModelType, Enum):
O1_PREVIEW = "o1-preview"
O1_MINI = "o1-mini"
O3_MINI = "o3-mini"
+ GPT_4_1 = "gpt-4.1-2025-04-14"
+ GPT_4_1_MINI = "gpt-4.1-mini-2025-04-14"
+ GPT_4_1_NANO = "gpt-4.1-nano-2025-04-14"
GLM_4 = "glm-4"
GLM_4V = "glm-4v"
@@ -329,6 +332,9 @@ class ModelType(UnifiedModelType, Enum):
ModelType.O1_MINI,
ModelType.O3_MINI,
ModelType.GPT_4_5_PREVIEW,
+ ModelType.GPT_4_1,
+ ModelType.GPT_4_1_MINI,
+ ModelType.GPT_4_1_NANO,
}
@property
@@ -857,6 +863,9 @@ class ModelType(UnifiedModelType, Enum):
ModelType.GLM_4_LONG,
ModelType.TOGETHER_LLAMA_4_MAVERICK,
ModelType.OPENROUTER_LLAMA_4_MAVERICK,
+ ModelType.GPT_4_1,
+ ModelType.GPT_4_1_MINI,
+ ModelType.GPT_4_1_NANO,
}:
return 1_048_576
elif self in {
diff --git a/examples/models/openai_gpt_4.1_example.py b/examples/models/openai_gpt_4.1_example.py
new file mode 100644
index 000000000..10ae65be9
--- /dev/null
+++ b/examples/models/openai_gpt_4.1_example.py
@@ -0,0 +1,44 @@
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
+
+from camel.agents import ChatAgent
+from camel.configs import ChatGPTConfig
+from camel.models import ModelFactory
+from camel.types import ModelPlatformType, ModelType
+
+gpt_4_1_model = ModelFactory.create(
+ model_platform=ModelPlatformType.OPENAI,
+ model_type=ModelType.GPT_4_1,
+ model_config_dict=ChatGPTConfig().as_dict(),
+)
+
+# Set agent
+camel_agent = ChatAgent(model=gpt_4_1_model)
+
+# Set user message
+user_msg = """Say hi to CAMEL AI, one open-source community
+ dedicated to the study of autonomous and communicative agents."""
+
+# Get response information
+response = camel_agent.step(user_msg)
+print(response.msgs[0].content)
+'''
+===============================================================================
+Hi CAMEL AI! 👋 It's great to see an open-source community dedicated to
+advancing the study of autonomous and communicative agents. Your efforts help
+push the boundaries of what's possible in AI collaboration and agentic
+systems. Looking forward to seeing the innovations and insights your community
+brings to the field! 🚀
+===============================================================================
+'''