š« CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
feat: Integrate samba nova model (#852)
Wendong-Fandc8c0467b377
diff --git a/camel/agents/chat_agent.py b/camel/agents/chat_agent.pyindex 95fc6c2e2..3ad16a596 100644--- a/camel/agents/chat_agent.py+++ b/camel/agents/chat_agent.py@@ -112,9 +112,6 @@ class ChatAgent(BaseAgent):model (BaseModelBackend, optional): The model backend to use forgenerating responses. (default: :obj:`OpenAIModel` with`GPT_4O_MINI`)- api_key (str, optional): The API key for authenticating with the- LLM service. Only OpenAI and Anthropic model supported (default:- :obj:`None`)memory (AgentMemory, optional): The agent memory for managing chatmessages. If `None`, a :obj:`ChatHistoryMemory` will be used.(default: :obj:`None`)@@ -138,7 +135,6 @@ class ChatAgent(BaseAgent):self,system_message: BaseMessage,model: Optional[BaseModelBackend] = None,- api_key: Optional[str] = None,memory: Optional[AgentMemory] = None,message_window_size: Optional[int] = None,token_limit: Optional[int] = None,@@ -150,7 +146,6 @@ class ChatAgent(BaseAgent):self.system_message = system_messageself.role_name: str = system_message.role_nameself.role_type: RoleType = system_message.role_type- self._api_key = api_keyself.model_backend: BaseModelBackend = (modelif model is not None@@ -158,7 +153,6 @@ class ChatAgent(BaseAgent):model_platform=ModelPlatformType.OPENAI,model_type=ModelType.GPT_4O_MINI,model_config_dict=ChatGPTConfig().as_dict(),- api_key=self._api_key,))self.output_language: Optional[str] = output_languagediff --git a/camel/configs/__init__.py b/camel/configs/__init__.pyindex 00182606b..20fc03740 100644--- a/camel/configs/__init__.py+++ b/camel/configs/__init__.py@@ -19,6 +19,7 @@ from .litellm_config import LITELLM_API_PARAMS, LiteLLMConfigfrom .mistral_config import MISTRAL_API_PARAMS, MistralConfigfrom .ollama_config import OLLAMA_API_PARAMS, OllamaConfigfrom .openai_config import OPENAI_API_PARAMS, ChatGPTConfig, OpenSourceConfig+from .samba_config import SAMBA_API_PARAMS, SambaConfigfrom .togetherai_config import TOGETHERAI_API_PARAMS, TogetherAIConfigfrom .vllm_config import VLLM_API_PARAMS, VLLMConfigfrom .zhipuai_config import ZHIPUAI_API_PARAMS, ZhipuAIConfig@@ -44,6 +45,8 @@ __all__ = ['VLLM_API_PARAMS','MistralConfig','MISTRAL_API_PARAMS',+ 'SambaConfig',+ 'SAMBA_API_PARAMS','TogetherAIConfig','TOGETHERAI_API_PARAMS',]diff --git a/camel/configs/samba_config.py b/camel/configs/samba_config.pynew file mode 100644index 000000000..6b0780a25--- /dev/null+++ b/camel/configs/samba_config.py@@ -0,0 +1,50 @@+# =========== 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 Any, Dict, Optional, Union++from camel.configs.base_config import BaseConfig+++class SambaConfig(BaseConfig):+ r"""Defines the parameters for generating chat completions using the+ SambaNova API.++ Args:+ max_tokens (Optional[int], optional): the maximum number of tokens to+ generate, e.g. 100. Defaults to `None`.+ stop (Optional[Union[str,list[str]]]): Stop generation if this token+ is detected. Or if one of these tokens is detected when providing+ a string list. Defaults to `None`.+ stream (Optional[bool]): If True, partial message deltas will be sent+ as data-only server-sent events as they become available.+ Currently SambaNova only support stream mode. Defaults to `True`.+ stream_options (Optional[Dict]): Additional options for streaming.+ Defaults to `{"include_usage": True}`.+ """++ max_tokens: Optional[int] = None+ stop: Optional[Union[str, list[str]]] = None+ stream: Optional[bool] = True+ stream_options: Optional[Dict] = {"include_usage": True} # noqa: RUF012++ def as_dict(self) -> dict[str, Any]:+ config_dict = super().as_dict()+ if "tools" in config_dict:+ del config_dict["tools"] # SambaNova does not support tool calling+ return config_dict+++SAMBA_API_PARAMS = {param for param in SambaConfig().model_fields.keys()}diff --git a/camel/configs/togetherai_config.py b/camel/configs/togetherai_config.pyindex 6162f9252..e64f5d18c 100644--- a/camel/configs/togetherai_config.py+++ b/camel/configs/togetherai_config.py@@ -97,7 +97,8 @@ class TogetherAIConfig(BaseConfig):def as_dict(self) -> dict[str, Any]:config_dict = super().as_dict()- config_dict.pop("tools", None) # Tool calling is not support+ if "tools" in config_dict:+ del config_dict["tools"] # Currently does not support tool callingreturn config_dictdiff --git a/camel/models/__init__.py b/camel/models/__init__.pyindex fc85db71a..63ae17381 100644--- a/camel/models/__init__.py+++ b/camel/models/__init__.py@@ -26,6 +26,7 @@ from .open_source_model import OpenSourceModelfrom .openai_audio_models import OpenAIAudioModelsfrom .openai_compatibility_model import OpenAICompatibilityModelfrom .openai_model import OpenAIModel+from .samba_model import SambaModelfrom .stub_model import StubModelfrom .togetherai_model import TogetherAIModelfrom .vllm_model import VLLMModel@@ -50,5 +51,6 @@ __all__ = ['GeminiModel','InternLMXComposerModel','OpenAICompatibilityModel',+ 'SambaModel','TogetherAIModel',]diff --git a/camel/models/groq_model.py b/camel/models/groq_model.pyindex 509f3b21d..255c820b8 100644--- a/camel/models/groq_model.py+++ b/camel/models/groq_model.py@@ -51,7 +51,7 @@ class GroqModel(BaseModelBackend):api_key (Optional[str]): The API key for authenticating with theGroq service. (default: :obj:`None`).url (Optional[str]): The url to the Groq service. (default:- :obj:`None`)+ :obj:`"https://api.groq.com/openai/v1"`)token_counter (Optional[BaseTokenCounter]): Token counter to usefor the model. If not provided, `OpenAITokenCounter(ModelType.GPT_4O_MINI)` will be used.@@ -59,13 +59,13 @@ class GroqModel(BaseModelBackend):super().__init__(model_type, model_config_dict, api_key, url, token_counter)- self._url = url or "https://api.groq.com/openai/v1"+ self._url = url or os.environ.get("GROQ_API_BASE_URL")self._api_key = api_key or os.environ.get("GROQ_API_KEY")self._client = OpenAI(timeout=60,max_retries=3,api_key=self._api_key,- base_url=self._url,+ base_url=self._url or "https://api.groq.com/openai/v1",)self._token_counter = token_counterdiff --git a/camel/models/model_factory.py b/camel/models/model_factory.pyindex 3bb360f81..2c21397be 100644--- a/camel/models/model_factory.py+++ b/camel/models/model_factory.py@@ -25,6 +25,7 @@ from camel.models.ollama_model import OllamaModelfrom camel.models.open_source_model import OpenSourceModelfrom camel.models.openai_compatibility_model import OpenAICompatibilityModelfrom camel.models.openai_model import OpenAIModel+from camel.models.samba_model import SambaModelfrom camel.models.stub_model import StubModelfrom camel.models.togetherai_model import TogetherAIModelfrom camel.models.vllm_model import VLLMModel@@ -93,6 +94,8 @@ class ModelFactory:model_class = GeminiModelelif model_platform.is_mistral and model_type.is_mistral:model_class = MistralModel+ elif model_platform.is_samba and model_type.is_samba:+ model_class = SambaModelelif model_type == ModelType.STUB:model_class = StubModelelse:diff --git a/camel/models/ollama_model.py b/camel/models/ollama_model.pyindex 207f5ca54..c5f367609 100644--- a/camel/models/ollama_model.py+++ b/camel/models/ollama_model.py@@ -11,6 +11,7 @@# See the License for the specific language governing permissions and# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+import osfrom typing import Any, Dict, List, Optional, Unionfrom openai import OpenAI, Stream@@ -40,18 +41,19 @@ class OllamaModel:model_config_dict (Dict[str, Any]): A dictionary that willbe fed into openai.ChatCompletion.create().url (Optional[str]): The url to the model service. (default:- :obj:`None`)+ :obj:`"http://localhost:11434/v1"`)token_counter (Optional[BaseTokenCounter]): Token counter to usefor the model. If not provided, `OpenAITokenCounter(ModelType.GPT_4O_MINI)` will be used."""self.model_type = model_typeself.model_config_dict = model_config_dict+ self._url = url or os.environ.get("OLLAMA_BASE_URL")# Use OpenAI cilent as interface call Ollamaself._client = OpenAI(timeout=60,max_retries=3,- base_url=url,+ base_url=self._url or "http://localhost:11434/v1",api_key="ollama", # required but ignored)self._token_counter = token_counterdiff --git a/camel/models/samba_model.py b/camel/models/samba_model.pynew file mode 100644index 000000000..4d9db897d--- /dev/null+++ b/camel/models/samba_model.py@@ -0,0 +1,291 @@+# =========== 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 SAMBA_API_PARAMS+from camel.messages import OpenAIMessage+from camel.types import ChatCompletion, ChatCompletionChunk, ModelType+from camel.utils import (+ BaseTokenCounter,+ OpenAITokenCounter,+ api_keys_required,+)+++class SambaModel:+ r"""SambaNova service interface."""++ def __init__(+ self,+ model_type: ModelType,+ model_config_dict: Dict[str, Any],+ api_key: Optional[str] = None,+ url: Optional[str] = None,+ token_counter: Optional[BaseTokenCounter] = None,+ ) -> None:+ r"""Constructor for SambaNova backend.++ Args:+ model_type (ModelType): Model for which a SambaNova backend is+ created.+ model_config_dict (Dict[str, Any]): A dictionary that will+ be fed into API request.+ api_key (Optional[str]): The API key for authenticating with the+ SambaNova service. (default: :obj:`None`)+ url (Optional[str]): The url to the SambaNova service. (default:+ :obj:`"https://fast-api.snova.ai/v1/chat/completions"`)+ token_counter (Optional[BaseTokenCounter]): Token counter to use+ for the model. If not provided, `OpenAITokenCounter(ModelType.+ GPT_4O_MINI)` will be used.+ """+ self.model_type = model_type+ self._api_key = api_key or os.environ.get("SAMBA_API_KEY")+ self._url = url or os.environ.get("SAMBA_API_BASE_URL")+ self._token_counter = token_counter+ self.model_config_dict = model_config_dict+ self.check_model_config()++ @property+ def token_counter(self) -> BaseTokenCounter:+ r"""Initialize the token counter for the model backend.++ Returns:+ BaseTokenCounter: 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 SambaNova API.++ Raises:+ ValueError: If the model configuration dictionary contains any+ unexpected arguments to SambaNova API.+ """+ for param in self.model_config_dict:+ if param not in SAMBA_API_PARAMS:+ raise ValueError(+ f"Unexpected argument `{param}` is "+ "input into SambaNova model backend."+ )++ @api_keys_required("SAMBA_API_KEY")+ def run( # type: ignore[misc]+ self, messages: List[OpenAIMessage]+ ) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:+ r"""Runs SambaNova's FastAPI service.++ 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.+ """++ if self.model_config_dict.get("stream") is True:+ return self._run_streaming(messages)+ else:+ return self._run_non_streaming(messages)++ def _run_streaming( # type: ignore[misc]+ self, messages: List[OpenAIMessage]+ ) -> Stream[ChatCompletionChunk]:+ r"""Handles streaming inference with SambaNova FastAPI.++ Args:+ messages (List[OpenAIMessage]): A list of messages representing the+ chat history in OpenAI API format.++ Returns:+ Stream[ChatCompletionChunk]: A generator yielding+ `ChatCompletionChunk` objects as they are received from the+ API.++ Raises:+ RuntimeError: If the HTTP request fails.+ """++ import httpx++ headers = {+ "Authorization": f"Basic {self._api_key}",+ "Content-Type": "application/json",+ }++ data = {+ "messages": messages,+ "max_tokens": self.token_limit,+ "stop": self.model_config_dict.get("stop"),+ "model": self.model_type.value,+ "stream": True,+ "stream_options": self.model_config_dict.get("stream_options"),+ }++ try:+ with httpx.stream(+ "POST",+ self._url or "https://fast-api.snova.ai/v1/chat/completions",+ headers=headers,+ json=data,+ ) as api_response:+ stream = Stream[ChatCompletionChunk](+ cast_to=ChatCompletionChunk,+ response=api_response,+ client=OpenAI(),+ )+ for chunk in stream:+ yield chunk+ except httpx.HTTPError as e:+ raise RuntimeError(f"HTTP request failed: {e!s}")++ def _run_non_streaming(+ self, messages: List[OpenAIMessage]+ ) -> ChatCompletion:+ r"""Handles non-streaming inference with SambaNova FastAPI.++ Args:+ messages (List[OpenAIMessage]): A list of messages representing the+ message in OpenAI API format.++ Returns:+ ChatCompletion: A `ChatCompletion` object containing the complete+ response from the API.++ Raises:+ RuntimeError: If the HTTP request fails.+ ValueError: If the JSON response cannot be decoded or is missing+ expected data.+ """++ import json++ import httpx++ headers = {+ "Authorization": f"Basic {self._api_key}",+ "Content-Type": "application/json",+ }++ data = {+ "messages": messages,+ "max_tokens": self.token_limit,+ "stop": self.model_config_dict.get("stop"),+ "model": self.model_type.value,+ "stream": True,+ "stream_options": self.model_config_dict.get("stream_options"),+ }++ try:+ with httpx.stream(+ "POST",+ self._url or "https://fast-api.snova.ai/v1/chat/completions",+ headers=headers,+ json=data,+ ) as api_response:+ samba_response = []+ for chunk in api_response.iter_text():+ if chunk.startswith('data: '):+ chunk = chunk[6:]+ if '[DONE]' in chunk:+ break+ json_data = json.loads(chunk)+ samba_response.append(json_data)+ return self._to_openai_response(samba_response)+ except httpx.HTTPError as e:+ raise RuntimeError(f"HTTP request failed: {e!s}")+ except json.JSONDecodeError as e:+ raise ValueError(f"Failed to decode JSON response: {e!s}")++ def _to_openai_response(+ self, samba_response: List[Dict[str, Any]]+ ) -> ChatCompletion:+ r"""Converts SambaNova response chunks into an OpenAI-compatible+ response.++ Args:+ samba_response (List[Dict[str, Any]]): A list of dictionaries+ representing partial responses from the SambaNova API.++ Returns:+ ChatCompletion: A `ChatCompletion` object constructed from the+ aggregated response data.++ Raises:+ ValueError: If the response data is invalid or incomplete.+ """+ # Step 1: Combine the content from each chunk+ full_content = ""+ for chunk in samba_response:+ if chunk['choices']:+ for choice in chunk['choices']:+ delta_content = choice['delta'].get('content', '')+ full_content += delta_content++ # Step 2: Create the ChatCompletion object+ # Extract relevant information from the first chunk+ first_chunk = samba_response[0]++ choices = [+ dict(+ index=0, # type: ignore[index]+ message={+ "role": 'assistant',+ "content": full_content.strip(),+ },+ finish_reason=samba_response[-1]['choices'][0]['finish_reason']+ or None,+ )+ ]++ obj = ChatCompletion.construct(+ id=first_chunk['id'],+ choices=choices,+ created=first_chunk['created'],+ model=first_chunk['model'],+ object="chat.completion",+ usage=None,+ )++ return obj++ @property+ def token_limit(self) -> int:+ r"""Returns the maximum token limit for a given model.++ Returns:+ int: The maximum token limit for the given model.+ """+ return (+ self.model_config_dict.get("max_tokens")+ or self.model_type.token_limit+ )++ @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/models/togetherai_model.py b/camel/models/togetherai_model.pyindex 2641fa486..b5bf820b6 100644--- a/camel/models/togetherai_model.py+++ b/camel/models/togetherai_model.py@@ -37,6 +37,7 @@ class TogetherAIModel:model_type: str,model_config_dict: Dict[str, Any],api_key: Optional[str] = None,+ url: Optional[str] = None,token_counter: Optional[BaseTokenCounter] = None,) -> None:r"""Constructor for TogetherAI backend.@@ -48,6 +49,8 @@ class TogetherAIModel:be fed into openai.ChatCompletion.create().api_key (Optional[str]): The API key for authenticating with theTogether service. (default: :obj:`None`)+ url (Optional[str]): The url to the Together AI service. (default:+ :obj:`"https://api.together.xyz/v1"`)token_counter (Optional[BaseTokenCounter]): Token counter to usefor the model. If not provided, `OpenAITokenCounter(ModelType.GPT_4O_MINI)` will be used.@@ -56,12 +59,13 @@ class TogetherAIModel:self.model_config_dict = model_config_dictself._token_counter = token_counterself._api_key = api_key or os.environ.get("TOGETHER_API_KEY")+ self._url = url or os.environ.get("TOGETHER_API_BASE_URL")self._client = OpenAI(timeout=60,max_retries=3,api_key=self._api_key,- base_url="https://api.together.xyz/v1",+ base_url=self._url or "https://api.together.xyz/v1",)@api_keys_required("TOGETHER_API_KEY")diff --git a/camel/models/vllm_model.py b/camel/models/vllm_model.pyindex 93082586c..c479fc064 100644--- a/camel/models/vllm_model.py+++ b/camel/models/vllm_model.py@@ -11,6 +11,7 @@# See the License for the specific language governing permissions and# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========+import osfrom typing import Any, Dict, List, Optional, Unionfrom openai import OpenAI, Stream@@ -42,7 +43,7 @@ class VLLMModel:model_config_dict (Dict[str, Any]): A dictionary that willbe fed into openai.ChatCompletion.create().url (Optional[str]): The url to the model service. (default:- :obj:`None`)+ :obj:`"http://localhost:8000/v1"`)api_key (Optional[str]): The API key for authenticating with themodel service.token_counter (Optional[BaseTokenCounter]): Token counter to use@@ -51,11 +52,12 @@ class VLLMModel:"""self.model_type = model_typeself.model_config_dict = model_config_dict+ self._url = url or os.environ.get("VLLM_BASE_URL")# Use OpenAI cilent as interface call vLLMself._client = OpenAI(timeout=60,max_retries=3,- base_url=url,+ base_url=self._url or "http://localhost:8000/v1",api_key=api_key,)self._token_counter = token_counter@@ -113,7 +115,7 @@ class VLLMModel:@propertydef token_limit(self) -> int:- """Returns the maximum token limit for the given model.+ r"""Returns the maximum token limit for the given model.Returns:int: The maximum token limit for the given model.diff --git a/camel/types/enums.py b/camel/types/enums.pyindex 2a3c64e6d..55d469373 100644--- a/camel/types/enums.py+++ b/camel/types/enums.py@@ -81,13 +81,16 @@ class ModelType(Enum):MISTRAL_MIXTRAL_8x22B = "open-mixtral-8x22b"MISTRAL_CODESTRAL_MAMBA = "open-codestral-mamba"+ # SambaNova Model+ SAMBA_LLAMA_3_1_405B = "llama3-405b"+ SAMBA_LLAMA_3_1_70B = "llama3-70b"+ SAMBA_LLAMA_3_1_8B = "llama3-8b"+@propertydef value_for_tiktoken(self) -> str:- return (- self.value- if self is not ModelType.STUB and not isinstance(self, str)- else "gpt-3.5-turbo"- )+ if self.is_openai:+ return self.value+ return "gpt-3.5-turbo"@propertydef is_openai(self) -> bool:@@ -192,6 +195,14 @@ class ModelType(Enum):def is_gemini(self) -> bool:return self in {ModelType.GEMINI_1_5_FLASH, ModelType.GEMINI_1_5_PRO}+ @property+ def is_samba(self) -> bool:+ return self in {+ ModelType.SAMBA_LLAMA_3_1_405B,+ ModelType.SAMBA_LLAMA_3_1_70B,+ ModelType.SAMBA_LLAMA_3_1_8B,+ }+@propertydef token_limit(self) -> int:r"""Returns the maximum token limit for a given model.@@ -251,6 +262,9 @@ class ModelType(Enum):ModelType.GROQ_LLAMA_3_1_8B,ModelType.GROQ_LLAMA_3_1_70B,ModelType.GROQ_LLAMA_3_1_405B,+ ModelType.SAMBA_LLAMA_3_1_405B,+ ModelType.SAMBA_LLAMA_3_1_70B,+ ModelType.SAMBA_LLAMA_3_1_8B,}:return 131_072elif self in {@@ -460,6 +474,7 @@ class ModelPlatformType(Enum):MISTRAL = "mistral"TOGETHER = "together"OPENAI_COMPATIBILITY_MODEL = "openai-compatibility-model"+ SAMBA = "samba-nova"INTERNLM = "internlm"@property@@ -528,6 +543,11 @@ class ModelPlatformType(Enum):r"""Returns whether this platform is Gemini."""return self is ModelPlatformType.GEMINI+ @property+ def is_samba(self) -> bool:+ r"""Returns whether this platform is Samba Nova."""+ return self is ModelPlatformType.SAMBA+@propertydef is_internlm(self) -> bool:r"""Returns whether this platform is InternLM."""diff --git a/examples/models/samba_model_example.py b/examples/models/samba_model_example.pynew file mode 100644index 000000000..72f0bae8f--- /dev/null+++ b/examples/models/samba_model_example.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. ===========+from camel.agents import ChatAgent+from camel.configs import SambaConfig+from camel.messages import BaseMessage+from camel.models import ModelFactory+from camel.types import ModelPlatformType, ModelType++model = ModelFactory.create(+ model_platform=ModelPlatformType.SAMBA,+ model_type=ModelType.SAMBA_LLAMA_3_1_405B,+ model_config_dict=SambaConfig(max_tokens=800).as_dict(),+)++# Define system message+sys_msg = BaseMessage.make_assistant_message(+ role_name="Assistant",+ content="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.""",+)++# Get response information+response = camel_agent.step(user_msg)+print(response.msgs[0].content)+'''+===============================================================================+Hello CAMEL AI community!++It's great to connect with a group of innovators and researchers passionate+about autonomous and communicative agents. Your work in this field has the+potential to revolutionize numerous industries and improve human lives.++What exciting projects are you currently working on? Are there any specific+challenges or areas where I can offer assistance or provide information? I'm+here to help and support your endeavors!+===============================================================================+'''diff --git a/test/models/test_samba_model.py b/test/models/test_samba_model.pynew file mode 100644index 000000000..38f87f778--- /dev/null+++ b/test/models/test_samba_model.py@@ -0,0 +1,59 @@+# =========== 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 OpenSourceConfig, SambaConfig+from camel.models import SambaModel+from camel.types import ModelType+from camel.utils import OpenAITokenCounter++[email protected]_backend+ "model_type",+ [+ ModelType.SAMBA_LLAMA_3_1_405B,+ ],+)+def test_samba_model(model_type):+ model_config_dict = SambaConfig().as_dict()+ model = SambaModel(model_type, model_config_dict)+ assert model.model_type == model_type+ assert model.model_config_dict == model_config_dict+ assert isinstance(model.token_counter, OpenAITokenCounter)+ assert isinstance(model.model_type.value_for_tiktoken, str)+ assert isinstance(model.model_type.token_limit, int)++[email protected]_backend+def test_samba_model_unexpected_argument():+ model_type = ModelType.SAMBA_LLAMA_3_1_405B+ model_config = OpenSourceConfig(+ model_path="vicuna-7b-v1.5",+ server_url="http://localhost:8000/v1",+ )+ model_config_dict = model_config.as_dict()++ with pytest.raises(+ ValueError,+ match=re.escape(+ (+ "Unexpected argument `model_path` is "+ "input into SambaNova model backend."+ )+ ),+ ):+ _ = SambaModel(model_type, model_config_dict)diff --git a/test/models/test_togetherai_model.py b/test/models/test_togetherai_model.pyindex aff6cc17d..aabdd328f 100644--- a/test/models/test_togetherai_model.py+++ b/test/models/test_togetherai_model.py@@ -11,7 +11,6 @@# See the License for the specific language governing permissions and# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========-import pytestfrom camel.configs import TogetherAIConfig