From a42d0291c45edb11ba3a5f933b0a2d103d7d56c7 Mon Sep 17 00:00:00 2001 From: Wendong-Fan <133094783+Wendong-Fan@users.noreply.github.com> Date: Fri, 21 Jun 2024 19:24:40 +0800 Subject: [PATCH] feat: Add claude 3.5, update interface for zhipu example (#669) --- camel/types/enums.py | 3 +++ ...ample copy.py => zhipuai_model_example.py} | 21 ++++++++----------- poetry.lock | 8 +++---- pyproject.toml | 2 +- test/models/test_anthropic_model.py | 1 + 5 files changed, 18 insertions(+), 17 deletions(-) rename examples/models/{zhipuai_model_example copy.py => zhipuai_model_example.py} (92%) diff --git a/camel/types/enums.py b/camel/types/enums.py index 5bdfbf3a21..7d00e88c88 100644 --- a/camel/types/enums.py +++ b/camel/types/enums.py @@ -49,6 +49,7 @@ class ModelType(Enum): CLAUDE_3_OPUS = "claude-3-opus-20240229" CLAUDE_3_SONNET = "claude-3-sonnet-20240229" CLAUDE_3_HAIKU = "claude-3-haiku-20240307" + CLAUDE_3_5_SONNET = "claude-3-5-sonnet-20240620" # Nvidia models NEMOTRON_4_REWARD = "nvidia/nemotron-4-340b-reward" @@ -104,6 +105,7 @@ def is_anthropic(self) -> bool: ModelType.CLAUDE_3_OPUS, ModelType.CLAUDE_3_SONNET, ModelType.CLAUDE_3_HAIKU, + ModelType.CLAUDE_3_5_SONNET, } @property @@ -155,6 +157,7 @@ def token_limit(self) -> int: ModelType.CLAUDE_3_OPUS, ModelType.CLAUDE_3_SONNET, ModelType.CLAUDE_3_HAIKU, + ModelType.CLAUDE_3_5_SONNET, }: return 200_000 elif self is ModelType.NEMOTRON_4_REWARD: diff --git a/examples/models/zhipuai_model_example copy.py b/examples/models/zhipuai_model_example.py similarity index 92% rename from examples/models/zhipuai_model_example copy.py rename to examples/models/zhipuai_model_example.py index 72cfbadc4c..9715fde49f 100644 --- a/examples/models/zhipuai_model_example copy.py +++ b/examples/models/zhipuai_model_example.py @@ -15,7 +15,14 @@ from camel.agents import ChatAgent from camel.configs import ChatGPTConfig from camel.messages import BaseMessage -from camel.types import ModelType +from camel.models import ModelFactory +from camel.types import ModelPlatformType, ModelType + +model = ModelFactory.create( + model_platform=ModelPlatformType.ZHIPU, + model_type=ModelType.GLM_4, + model_config=ChatGPTConfig(temperature=0.2), +) # Define system message sys_msg = BaseMessage.make_assistant_message( @@ -23,18 +30,8 @@ content="You are a helpful assistant.", ) -# Set model config -model_config = ChatGPTConfig( - temperature=0.2, top_p=0.9 -) # temperature=,top_p here can not be 1 or 0. - # Set agent -camel_agent = ChatAgent( - sys_msg, - model_config=model_config, - model_type=ModelType.GLM_4, -) -camel_agent.reset() +camel_agent = ChatAgent(system_message=sys_msg, model=model) user_msg = BaseMessage.make_user_message( role_name="User", diff --git a/poetry.lock b/poetry.lock index 67682e4933..571ae688b0 100644 --- a/poetry.lock +++ b/poetry.lock @@ -218,13 +218,13 @@ typing-extensions = {version = ">=4.0.0", markers = "python_version < \"3.9\""} [[package]] name = "anthropic" -version = "0.28.1" +version = "0.29.0" description = "The official Python library for the anthropic API" optional = false python-versions = ">=3.7" files = [ - {file = "anthropic-0.28.1-py3-none-any.whl", hash = "sha256:c4773ae2b42951a6b747bed328b0d03fa412938c95c3a8b9dce70d69badb710b"}, - {file = "anthropic-0.28.1.tar.gz", hash = "sha256:e3a6d595bde241141bdc685edc393903ec95c7fa378013a71186cfb8f32b1793"}, + {file = "anthropic-0.29.0-py3-none-any.whl", hash = "sha256:d16010715129c8bc3295b74fbf4da73cfb156618bf0abb2d007255983266b76a"}, + {file = "anthropic-0.29.0.tar.gz", hash = "sha256:3eb558a232d83bdf7cdedb75663bf7ff7a8b50cc10acaa9ce6494ff295b8506a"}, ] [package.dependencies] @@ -7631,4 +7631,4 @@ vector-databases = ["pymilvus", "qdrant-client"] [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<3.12" -content-hash = "eb6da340e8bcf87e611d81f81ddde8998c8edeb17b00177719e151ec992b1b48" +content-hash = "21adba18eafa5a5ebe06249225548680380aa8d5ab740890015e78d03c06892a" diff --git a/pyproject.toml b/pyproject.toml index 723e0e3d9a..1f585d0e12 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,7 @@ colorama = "^0" jsonschema = "^4" protobuf = "^4" pathlib = "^1.0.1" -anthropic = "^0.28.0" +anthropic = "^0.29.0" docstring-parser = "^0.15" pydantic = ">=1.9,<3" curl_cffi = "0.6.2" diff --git a/test/models/test_anthropic_model.py b/test/models/test_anthropic_model.py index 178963b7eb..6ea732011e 100644 --- a/test/models/test_anthropic_model.py +++ b/test/models/test_anthropic_model.py @@ -31,6 +31,7 @@ ModelType.CLAUDE_3_OPUS, ModelType.CLAUDE_3_SONNET, ModelType.CLAUDE_3_HAIKU, + ModelType.CLAUDE_3_5_SONNET, ], ) def test_anthropic_model(model_type):