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: Add support for 01 model platform (#1093)

Xiaotian Jinaac3fa25d3df
diff --git a/camel/configs/__init__.py b/camel/configs/__init__.py
index a7b5f2ce7..ffc9bc78a 100644
--- a/camel/configs/__init__.py
+++ b/camel/configs/__init__.py
@@ -28,6 +28,7 @@ from .samba_config import (
)
from .togetherai_config import TOGETHERAI_API_PARAMS, TogetherAIConfig
from .vllm_config import VLLM_API_PARAMS, VLLMConfig
+from .yi_config import YI_API_PARAMS, YiConfig
from .zhipuai_config import ZHIPUAI_API_PARAMS, ZhipuAIConfig
__all__ = [
@@ -58,4 +59,6 @@ __all__ = [
'SAMBA_CLOUD_API_PARAMS',
'TogetherAIConfig',
'TOGETHERAI_API_PARAMS',
+ 'YiConfig',
+ 'YI_API_PARAMS',
]
diff --git a/camel/configs/yi_config.py b/camel/configs/yi_config.py
new file mode 100644
index 000000000..7e2ae3a32
--- /dev/null
+++ b/camel/configs/yi_config.py
@@ -0,0 +1,58 @@
+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========
+from __future__ import annotations
+
+from typing import Optional, Union
+
+from camel.configs.base_config import BaseConfig
+from camel.types import NOT_GIVEN, NotGiven
+
+
+class YiConfig(BaseConfig):
+ r"""Defines the parameters for generating chat completions using the
+ Yi API. You can refer to the following link for more details:
+ https://platform.lingyiwanwu.com/docs/api-reference
+
+ Args:
+ tool_choice (Union[dict[str, str], str], optional): Controls which (if
+ any) tool is called by the model. :obj:`"none"` means the model
+ will not call any tool and instead generates a message.
+ :obj:`"auto"` means the model can pick between generating a
+ message or calling one or more tools. :obj:`"required"` or
+ specifying a particular tool via
+ {"type": "function", "function": {"name": "some_function"}}
+ can be used to guide the model to use tools more strongly.
+ (default: :obj:`None`)
+ max_tokens (int, optional): Specifies the maximum number of tokens
+ the model can generate. This sets an upper limit, but does not
+ guarantee that this number will always be reached.
+ (default: :obj:`5000`)
+ top_p (float, optional): Controls the randomness of the generated
+ results. Lower values lead to less randomness, while higher
+ values increase randomness. (default: :obj:`0.9`)
+ temperature (float, optional): Controls the diversity and focus of
+ the generated results. Lower values make the output more focused,
+ while higher values make it more diverse. (default: :obj:`0.3`)
+ stream (bool, optional): If True, enables streaming output.
+ (default: :obj:`False`)
+ """
+
+ tool_choice: Optional[Union[dict[str, str], str]] = None
+ max_tokens: Union[int, NotGiven] = NOT_GIVEN
+ top_p: float = 0.9
+ temperature: float = 0.3
+ stream: bool = False
+
+
+YI_API_PARAMS = {param for param in YiConfig.model_fields.keys()}
diff --git a/camel/models/__init__.py b/camel/models/__init__.py
index 780c647c6..d8b32bc8c 100644
--- a/camel/models/__init__.py
+++ b/camel/models/__init__.py
@@ -29,6 +29,7 @@ from .samba_model import SambaModel
from .stub_model import StubModel
from .togetherai_model import TogetherAIModel
from .vllm_model import VLLMModel
+from .yi_model import YiModel
from .zhipuai_model import ZhipuAIModel
__all__ = [
@@ -51,4 +52,5 @@ __all__ = [
'RekaModel',
'SambaModel',
'TogetherAIModel',
+ 'YiModel',
]
diff --git a/camel/models/model_factory.py b/camel/models/model_factory.py
index a787187d1..83c4a6584 100644
--- a/camel/models/model_factory.py
+++ b/camel/models/model_factory.py
@@ -28,6 +28,7 @@ from camel.models.samba_model import SambaModel
from camel.models.stub_model import StubModel
from camel.models.togetherai_model import TogetherAIModel
from camel.models.vllm_model import VLLMModel
+from camel.models.yi_model import YiModel
from camel.models.zhipuai_model import ZhipuAIModel
from camel.types import ModelPlatformType, ModelType, UnifiedModelType
from camel.utils import BaseTokenCounter
@@ -108,6 +109,8 @@ class ModelFactory:
model_class = RekaModel
elif model_type == ModelType.STUB:
model_class = StubModel
+ elif model_platform.is_yi and model_type.is_yi:
+ model_class = YiModel
if model_class is None:
raise ValueError(
diff --git a/camel/models/yi_model.py b/camel/models/yi_model.py
new file mode 100644
index 000000000..3fde54924
--- /dev/null
+++ b/camel/models/yi_model.py
@@ -0,0 +1,138 @@
+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========
+
+import os
+from typing import Any, Dict, List, Optional, Union
+
+from openai import OpenAI, Stream
+
+from camel.configs import YI_API_PARAMS, YiConfig
+from camel.messages import OpenAIMessage
+from camel.models import BaseModelBackend
+from camel.types import (
+ ChatCompletion,
+ ChatCompletionChunk,
+ ModelType,
+)
+from camel.utils import (
+ BaseTokenCounter,
+ OpenAITokenCounter,
+ api_keys_required,
+)
+
+
+class YiModel(BaseModelBackend):
+ r"""Yi API in a unified BaseModelBackend interface.
+
+ Args:
+ model_type (Union[ModelType, str]): Model for which a backend is
+ created, one of Yi series.
+ model_config_dict (Optional[Dict[str, Any]], optional): A dictionary
+ that will be fed into:obj:`openai.ChatCompletion.create()`. If
+ :obj:`None`, :obj:`YiConfig().as_dict()` will be used.
+ (default: :obj:`None`)
+ api_key (Optional[str], optional): The API key for authenticating with
+ the Yi service. (default: :obj:`None`)
+ url (Optional[str], optional): The url to the Yi service.
+ (default: :obj:`https://api.lingyiwanwu.com/v1`)
+ token_counter (Optional[BaseTokenCounter], optional): Token counter to
+ use for the model. If not provided, :obj:`OpenAITokenCounter(
+ ModelType.GPT_4O_MINI)` will be used.
+ (default: :obj:`None`)
+ """
+
+ def __init__(
+ self,
+ model_type: Union[ModelType, str],
+ model_config_dict: Optional[Dict[str, Any]] = None,
+ api_key: Optional[str] = None,
+ url: Optional[str] = None,
+ token_counter: Optional[BaseTokenCounter] = None,
+ ) -> None:
+ if model_config_dict is None:
+ model_config_dict = YiConfig().as_dict()
+ api_key = api_key or os.environ.get("YI_API_KEY")
+ url = url or os.environ.get(
+ "YI_API_BASE_URL", "https://api.lingyiwanwu.com/v1"
+ )
+ super().__init__(
+ model_type, model_config_dict, api_key, url, token_counter
+ )
+ self._client = OpenAI(
+ timeout=60,
+ max_retries=3,
+ api_key=self._api_key,
+ base_url=self._url,
+ )
+
+ @api_keys_required("YI_API_KEY")
+ def run(
+ self,
+ messages: List[OpenAIMessage],
+ ) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:
+ r"""Runs inference of Yi chat completion.
+
+ Args:
+ messages (List[OpenAIMessage]): Message list with the chat history
+ in OpenAI API format.
+
+ Returns:
+ Union[ChatCompletion, Stream[ChatCompletionChunk]]:
+ `ChatCompletion` in the non-stream mode, or
+ `Stream[ChatCompletionChunk]` in the stream mode.
+ """
+ response = self._client.chat.completions.create(
+ messages=messages,
+ model=self.model_type,
+ **self.model_config_dict,
+ )
+ return response
+
+ @property
+ def token_counter(self) -> BaseTokenCounter:
+ r"""Initialize the token counter for the model backend.
+
+ Returns:
+ OpenAITokenCounter: The token counter following the model's
+ tokenization style.
+ """
+
+ if not self._token_counter:
+ self._token_counter = OpenAITokenCounter(ModelType.GPT_4O_MINI)
+ return self._token_counter
+
+ def check_model_config(self):
+ r"""Check whether the model configuration contains any
+ unexpected arguments to Yi API.
+
+ Raises:
+ ValueError: If the model configuration dictionary contains any
+ unexpected arguments to Yi API.
+ """
+ for param in self.model_config_dict:
+ if param not in YI_API_PARAMS:
+ raise ValueError(
+ f"Unexpected argument `{param}` is "
+ "input into Yi model backend."
+ )
+
+ @property
+ def stream(self) -> bool:
+ r"""Returns whether the model is in stream mode, which sends partial
+ results each time.
+
+ Returns:
+ bool: Whether the model is in stream mode.
+ """
+ return self.model_config_dict.get('stream', False)
diff --git a/camel/types/enums.py b/camel/types/enums.py
index 236c2ede5..eb89a5a61 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -87,6 +87,17 @@ class ModelType(UnifiedModelType, Enum):
REKA_FLASH = "reka-flash"
REKA_EDGE = "reka-edge"
+ # Yi models (01-ai)
+ YI_LIGHTNING = "yi-lightning"
+ YI_LARGE = "yi-large"
+ YI_MEDIUM = "yi-medium"
+ YI_LARGE_TURBO = "yi-large-turbo"
+ YI_VISION = "yi-vision"
+ YI_MEDIUM_200K = "yi-medium-200k"
+ YI_SPARK = "yi-spark"
+ YI_LARGE_RAG = "yi-large-rag"
+ YI_LARGE_FC = "yi-large-fc"
+
def __str__(self):
return self.value
@@ -220,6 +231,25 @@ class ModelType(UnifiedModelType, Enum):
ModelType.REKA_FLASH,
}
+ @property
+ def is_yi(self) -> bool:
+ r"""Returns whether this type of models is Yi model.
+
+ Returns:
+ bool: Whether this type of models is Yi.
+ """
+ return self in {
+ ModelType.YI_LIGHTNING,
+ ModelType.YI_LARGE,
+ ModelType.YI_MEDIUM,
+ ModelType.YI_LARGE_TURBO,
+ ModelType.YI_VISION,
+ ModelType.YI_MEDIUM_200K,
+ ModelType.YI_SPARK,
+ ModelType.YI_LARGE_RAG,
+ ModelType.YI_LARGE_FC,
+ }
+
@property
def token_limit(self) -> int:
r"""Returns the maximum token limit for a given model.
@@ -249,6 +279,12 @@ class ModelType(UnifiedModelType, Enum):
return 8_192
elif self in {
ModelType.GPT_3_5_TURBO,
+ ModelType.YI_LIGHTNING,
+ ModelType.YI_MEDIUM,
+ ModelType.YI_LARGE_TURBO,
+ ModelType.YI_VISION,
+ ModelType.YI_SPARK,
+ ModelType.YI_LARGE_RAG,
}:
return 16_384
elif self in {
@@ -256,6 +292,8 @@ class ModelType(UnifiedModelType, Enum):
ModelType.MISTRAL_7B,
ModelType.MISTRAL_MIXTRAL_8x7B,
ModelType.GROQ_MIXTRAL_8_7B,
+ ModelType.YI_LARGE,
+ ModelType.YI_LARGE_FC,
}:
return 32_768
elif self in {ModelType.MISTRAL_MIXTRAL_8x22B}:
@@ -290,6 +328,7 @@ class ModelType(UnifiedModelType, Enum):
ModelType.CLAUDE_3_SONNET,
ModelType.CLAUDE_3_HAIKU,
ModelType.CLAUDE_3_5_SONNET,
+ ModelType.YI_MEDIUM_200K,
}:
return 200_000
elif self in {
@@ -445,6 +484,7 @@ class ModelPlatformType(Enum):
TOGETHER = "together"
OPENAI_COMPATIBLE_MODEL = "openai-compatible-model"
SAMBA = "samba-nova"
+ YI = "lingyiwanwu"
@property
def is_openai(self) -> bool:
@@ -517,6 +557,11 @@ class ModelPlatformType(Enum):
r"""Returns whether this platform is Samba Nova."""
return self is ModelPlatformType.SAMBA
+ @property
+ def is_yi(self) -> bool:
+ r"""Returns whether this platform is Yi."""
+ return self is ModelPlatformType.YI
+
class AudioModelType(Enum):
TTS_1 = "tts-1"
diff --git a/camel/types/unified_model_type.py b/camel/types/unified_model_type.py
index 369d2cce5..d3fed082d 100644
--- a/camel/types/unified_model_type.py
+++ b/camel/types/unified_model_type.py
@@ -98,6 +98,11 @@ class UnifiedModelType(str):
r"""Returns whether the model is a Reka model."""
return True
+ @property
+ def is_yi(self) -> bool:
+ r"""Returns whether the model is a Yi model."""
+ return True
+
@property
def support_native_tool_calling(self) -> bool:
r"""Returns whether the model supports native tool calling."""
diff --git a/docs/key_modules/models.md b/docs/key_modules/models.md
index c2cdef988..813ad1a29 100644
--- a/docs/key_modules/models.md
+++ b/docs/key_modules/models.md
@@ -41,6 +41,15 @@ The following table lists currently supported model platforms by CAMEL.
| Anthropic | claude-2.0 | N |
| Gemini | gemini-1.5-pro | Y |
| Gemini | ggemini-1.5-flash | Y |
+| Lingyiwanwu | yi-lightning | N |
+| Lingyiwanwu | yi-large | N |
+| Lingyiwanwu | yi-medium | N |
+| Lingyiwanwu | yi-large-turbo | N |
+| Lingyiwanwu | yi-vision | Y |
+| Lingyiwanwu | yi-medium-200k | N |
+| Lingyiwanwu | yi-spark | N |
+| Lingyiwanwu | yi-large-rag | N |
+| Lingyiwanwu | yi-large-fc | N |
| ZhipuAI | glm-4v | Y |
| ZhipuAI | glm-4 | N |
| ZhipuAI | glm-3-turbo | N |
diff --git a/examples/models/azure_openai_model_example.py b/examples/models/azure_openai_model_example.py
index 61c553021..df6871278 100644
--- a/examples/models/azure_openai_model_example.py
+++ b/examples/models/azure_openai_model_example.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
from camel.configs import ChatGPTConfig
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType
@@ -32,19 +31,13 @@ model = ModelFactory.create(
)
# Define system message
-sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+sys_msg = "You are a helpful assistant."
# Set agent
camel_agent = ChatAgent(system_message=sys_msg, model=model)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community dedicated to the
- study of autonomous and communicative agents.""",
-)
+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)
diff --git a/examples/models/gemini_model_example.py b/examples/models/gemini_model_example.py
index 45b7aa746..21c71a0b7 100644
--- a/examples/models/gemini_model_example.py
+++ b/examples/models/gemini_model_example.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
from camel.configs import GeminiConfig
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType
@@ -24,19 +23,13 @@ model = ModelFactory.create(
)
# Define system message
-sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+sys_msg = "You are a helpful assistant."
# Set agent
camel_agent = ChatAgent(system_message=sys_msg, model=model)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community dedicated to the
- study of autonomous and communicative agents.""",
-)
+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)
diff --git a/examples/models/litellm_model_example.py b/examples/models/litellm_model_example.py
index 35009981f..c3179d94f 100644
--- a/examples/models/litellm_model_example.py
+++ b/examples/models/litellm_model_example.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
from camel.configs import LiteLLMConfig
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType
@@ -24,19 +23,13 @@ model = ModelFactory.create(
)
# Define system message
-sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+sys_msg = "You are a helpful assistant."
# Set agent
camel_agent = ChatAgent(system_message=sys_msg, model=model, token_limit=500)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community dedicated to the
- study of autonomous and communicative agents.""",
-)
+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)
diff --git a/examples/models/mistral_model_example.py b/examples/models/mistral_model_example.py
index a95db425a..e947c8859 100644
--- a/examples/models/mistral_model_example.py
+++ b/examples/models/mistral_model_example.py
@@ -29,19 +29,13 @@ model = ModelFactory.create(
)
# Define system message
-sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+sys_msg = "You are a helpful assistant."
# Set agent
camel_agent = ChatAgent(system_message=sys_msg, model=model)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community dedicated to the
- study of autonomous and communicative agents.""",
-)
+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)
diff --git a/examples/models/ollama_model_example.py b/examples/models/ollama_model_example.py
index 2aaa4c086..797c2f613 100644
--- a/examples/models/ollama_model_example.py
+++ b/examples/models/ollama_model_example.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType
@@ -23,17 +22,13 @@ ollama_model = ModelFactory.create(
model_config_dict={"temperature": 0.4},
)
-assistant_sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+assistant_sys_msg = "You are a helpful assistant."
+
agent = ChatAgent(assistant_sys_msg, model=ollama_model, token_limit=4096)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community
- dedicated to the study of autonomous and communicative agents.""",
-)
+user_msg = """Say hi to CAMEL AI, one open-source community
+ dedicated to the study of autonomous and communicative agents."""
+
assistant_response = agent.step(user_msg)
print(assistant_response.msg.content)
diff --git a/examples/models/openai_compatibility_model_examples/nemotron.py b/examples/models/openai_compatibility_model_examples/nemotron.py
index b44e05dc5..dfb3c4abe 100644
--- a/examples/models/openai_compatibility_model_examples/nemotron.py
+++ b/examples/models/openai_compatibility_model_examples/nemotron.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType
@@ -26,19 +25,14 @@ model = ModelFactory.create(
model_config_dict={"temperature": 0.4},
)
-assistant_sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+assistant_sys_msg = "You are a helpful assistant."
agent = ChatAgent(assistant_sys_msg, model=model)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to Llama-3.1-Nemotron-70B-Instruct, a large language
+user_msg = """Say hi to Llama-3.1-Nemotron-70B-Instruct, a large language
model customized by NVIDIA to improve the helpfulness of LLM generated
- responses to user queries..""",
-)
+ responses to user queries.."""
+
assistant_response = agent.step(user_msg)
print(assistant_response.msg.content)
diff --git a/examples/models/openai_compatibility_model_examples/qwen.py b/examples/models/openai_compatibility_model_examples/qwen.py
index 701285e73..e10de4739 100644
--- a/examples/models/openai_compatibility_model_examples/qwen.py
+++ b/examples/models/openai_compatibility_model_examples/qwen.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType
@@ -27,18 +26,13 @@ model = ModelFactory.create(
model_config_dict={"temperature": 0.4},
)
-assistant_sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+assistant_sys_msg = "You are a helpful assistant."
agent = ChatAgent(assistant_sys_msg, model=model, token_limit=4096)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community
- dedicated to the study of autonomous and communicative agents.""",
-)
+user_msg = """Say hi to CAMEL AI, one open-source community
+ dedicated to the study of autonomous and communicative agents."""
+
assistant_response = agent.step(user_msg)
print(assistant_response.msg.content)
diff --git a/examples/models/reka_model_example.py b/examples/models/reka_model_example.py
index 4d03838fa..75dca9f2e 100644
--- a/examples/models/reka_model_example.py
+++ b/examples/models/reka_model_example.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
from camel.configs import RekaConfig
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType
@@ -24,19 +23,13 @@ model = ModelFactory.create(
)
# Define system message
-sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+sys_msg = "You are a helpful assistant."
# Set agent
camel_agent = ChatAgent(system_message=sys_msg, model=model)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community dedicated to the
- study of autonomous and communicative agents.""",
-)
+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)
diff --git a/examples/models/togetherai_model_example.py b/examples/models/togetherai_model_example.py
index 67148883a..5cdaf301b 100644
--- a/examples/models/togetherai_model_example.py
+++ b/examples/models/togetherai_model_example.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
from camel.configs import TogetherAIConfig
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType
@@ -24,19 +23,13 @@ model = ModelFactory.create(
)
# Define system message
-sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+sys_msg = "You are a helpful assistant."
# Set agent
camel_agent = ChatAgent(system_message=sys_msg, model=model, token_limit=500)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community dedicated to the
- study of autonomous and communicative agents.""",
-)
+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)
diff --git a/examples/models/vllm_model_example.py b/examples/models/vllm_model_example.py
index ea499d0cd..ab2b9cb07 100644
--- a/examples/models/vllm_model_example.py
+++ b/examples/models/vllm_model_example.py
@@ -13,7 +13,6 @@
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
from camel.agents import ChatAgent
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType
@@ -24,16 +23,12 @@ vllm_model = ModelFactory.create(
api_key="vllm",
)
-assistant_sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+assistant_sys_msg = "You are a helpful assistant."
+
agent = ChatAgent(assistant_sys_msg, model=vllm_model, token_limit=4096)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="Say hi to CAMEL AI",
-)
+user_msg = "Say hi to CAMEL AI"
+
assistant_response = agent.step(user_msg)
print(assistant_response.msg.content)
diff --git a/examples/models/yi_model_example.py b/examples/models/yi_model_example.py
new file mode 100644
index 000000000..7bf4ba378
--- /dev/null
+++ b/examples/models/yi_model_example.py
@@ -0,0 +1,45 @@
+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========
+
+from camel.agents import ChatAgent
+from camel.configs import YiConfig
+from camel.models import ModelFactory
+from camel.types import ModelPlatformType, ModelType
+
+model = ModelFactory.create(
+ model_platform=ModelPlatformType.YI,
+ model_type=ModelType.YI_LIGHTNING,
+ model_config_dict=YiConfig(temperature=0.2).as_dict(),
+)
+
+# Define system message
+sys_msg = "You are a helpful assistant."
+
+# Set agent
+camel_agent = ChatAgent(system_message=sys_msg, model=model)
+
+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)
+'''
+===============================================================================
+Hello CAMEL AI community! šŸ‘‹ It's great to connect with an open-source group
+dedicated to the fascinating fields of autonomous and communicative agents. If
+there's anything you need assistance with or any interesting projects you're
+working on, feel free to share. I'm here to help however I can! 😊
+===============================================================================
+'''
diff --git a/examples/models/zhipuai_model_example.py b/examples/models/zhipuai_model_example.py
index eaa62c7d9..78817cfac 100644
--- a/examples/models/zhipuai_model_example.py
+++ b/examples/models/zhipuai_model_example.py
@@ -14,7 +14,6 @@
from camel.agents import ChatAgent
from camel.configs import ZhipuAIConfig
-from camel.messages import BaseMessage
from camel.models import ModelFactory
from camel.types import ModelPlatformType, ModelType
@@ -25,19 +24,13 @@ model = ModelFactory.create(
)
# Define system message
-sys_msg = BaseMessage.make_assistant_message(
- role_name="Assistant",
- content="You are a helpful assistant.",
-)
+sys_msg = "You are a helpful assistant."
# Set agent
camel_agent = ChatAgent(system_message=sys_msg, model=model)
-user_msg = BaseMessage.make_user_message(
- role_name="User",
- content="""Say hi to CAMEL AI, one open-source community
- dedicated to the study of autonomous and communicative agents.""",
-)
+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)
diff --git a/test/models/test_yi_model.py b/test/models/test_yi_model.py
new file mode 100644
index 000000000..095188dd8
--- /dev/null
+++ b/test/models/test_yi_model.py
@@ -0,0 +1,56 @@
+# =========== Copyright 2023 @ 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 @ CAMEL-AI.org. All Rights Reserved. ===========
+
+import re
+
+import pytest
+
+from camel.configs import YiConfig
+from camel.models import YiModel
+from camel.types import ModelType
+
+
+ "model_type",
+ [
+ ModelType.YI_LIGHTNING,
+ ModelType.YI_LARGE,
+ ModelType.YI_MEDIUM,
+ ModelType.YI_LARGE_TURBO,
+ ],
+)
+def test_yi_model(model_type: ModelType):
+ model = YiModel(model_type)
+ assert model.model_type == model_type
+ assert model.model_config_dict == YiConfig().as_dict()
+ assert isinstance(model.model_type.value_for_tiktoken, str)
+ assert isinstance(model.model_type.token_limit, int)
+
+
+def test_yi_model_unexpected_argument():
+ model_type = ModelType.YI_LARGE
+ model_config_dict = {"model_path": "yi-34b-chat"}
+
+ with pytest.raises(
+ ValueError,
+ match=re.escape(
+ (
+ "Unexpected argument `model_path` is "
+ "input into Yi model backend."
+ )
+ ),
+ ):
+ _ = YiModel(model_type, model_config_dict)