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 NVIDIA model platform support (#1226)

Anjie Yangf6d8df417bb3
diff --git a/.env b/.env
index 61c74f6ce..e43bf49a1 100644
--- a/.env
+++ b/.env
@@ -47,6 +47,9 @@ QWEN_API_KEY="Fill your API key here"
# LingYi API (https://platform.lingyiwanwu.com/apikeys)
YI_API_KEY="Fill your API key here"
+# NVIDIA API (https://build.nvidia.com/explore/discover)
+NVIDIA_API_KEY="Fill your API key here"
+
#===========================================
# Tools & Services API
#===========================================
@@ -58,10 +61,6 @@ SEARCH_ENGINE_ID="Fill your API key here"
# OpenWeatherMap API (https://home.openweathermap.org/users/sign_up)
OPENWEATHERMAP_API_KEY="Fill your API key here"
-# NVIDIA API (https://build.nvidia.com/explore/discover)
-NVIDIA_API_BASE_URL="Fill your API key here"
-NVIDIA_API_KEY="Fill your API key here"
-
# Neo4j Database (https://neo4j.com/)
NEO4J_URI="Fill your API key here"
NEO4J_USERNAME="Fill your User Name here"
diff --git a/camel/configs/__init__.py b/camel/configs/__init__.py
index cadf5fc00..ff4cc8c28 100644
--- a/camel/configs/__init__.py
+++ b/camel/configs/__init__.py
@@ -19,6 +19,7 @@ from .gemini_config import Gemini_API_PARAMS, GeminiConfig
from .groq_config import GROQ_API_PARAMS, GroqConfig
from .litellm_config import LITELLM_API_PARAMS, LiteLLMConfig
from .mistral_config import MISTRAL_API_PARAMS, MistralConfig
+from .nvidia_config import NVIDIA_API_PARAMS, NvidiaConfig
from .ollama_config import OLLAMA_API_PARAMS, OllamaConfig
from .openai_config import OPENAI_API_PARAMS, ChatGPTConfig
from .qwen_config import QWEN_API_PARAMS, QwenConfig
@@ -44,6 +45,8 @@ __all__ = [
'GroqConfig',
'LiteLLMConfig',
'LITELLM_API_PARAMS',
+ 'NvidiaConfig',
+ 'NVIDIA_API_PARAMS',
'OllamaConfig',
'OLLAMA_API_PARAMS',
'ZhipuAIConfig',
diff --git a/camel/configs/nvidia_config.py b/camel/configs/nvidia_config.py
new file mode 100644
index 000000000..e90ea673f
--- /dev/null
+++ b/camel/configs/nvidia_config.py
@@ -0,0 +1,70 @@
+# ========= 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 __future__ import annotations
+
+from typing import List, Optional, Union
+
+from pydantic import Field
+
+from camel.configs.base_config import BaseConfig
+from camel.types import NOT_GIVEN, NotGiven
+
+
+class NvidiaConfig(BaseConfig):
+ r"""Configuration class for NVIDIA API models.
+
+ This class defines the configuration parameters for NVIDIA's language
+ models, including temperature, sampling parameters, and response format
+ settings.
+
+ Args:
+ stream (bool, optional): Whether to stream the response.
+ (default: :obj:`False`)
+ temperature (float, optional): Controls randomness in the response.
+ Higher values make output more random, lower values make it more
+ deterministic. Range: [0.0, 2.0]. (default: :obj:`0.7`)
+ top_p (float, optional): Controls diversity via nucleus sampling.
+ Range: [0.0, 1.0]. (default: :obj:`0.95`)
+ presence_penalty (float, optional): Penalizes new tokens based on
+ whether they appear in the text so far. Range: [-2.0, 2.0].
+ (default: :obj:`0.0`)
+ frequency_penalty (float, optional): Penalizes new tokens based on
+ their frequency in the text so far. Range: [-2.0, 2.0].
+ (default: :obj:`0.0`)
+ max_tokens (Union[int, NotGiven], optional): Maximum number of tokens
+ to generate. If not provided, model will use its default maximum.
+ (default: :obj:`NOT_GIVEN`)
+ seed (Optional[int], optional): Random seed for deterministic sampling.
+ (default: :obj:`None`)
+ tools (Optional[List[Dict]], optional): List of tools available to the
+ model. This includes tools such as a text editor, a calculator, or
+ a search engine. (default: :obj:`None`)
+ tool_choice (Optional[str], optional): Tool choice configuration.
+ (default: :obj:`None`)
+ stop (Optional[List[str]], optional): List of stop sequences.
+ (default: :obj:`None`)
+ """
+
+ stream: bool = Field(default=False)
+ temperature: float = Field(default=0.7)
+ top_p: float = Field(default=0.95)
+ presence_penalty: float = Field(default=0.0)
+ frequency_penalty: float = Field(default=0.0)
+ max_tokens: Union[int, NotGiven] = Field(default=NOT_GIVEN)
+ seed: Optional[int] = Field(default=None)
+ tool_choice: Optional[str] = Field(default=None)
+ stop: Optional[List[str]] = Field(default=None)
+
+
+NVIDIA_API_PARAMS = {param for param in NvidiaConfig.model_fields.keys()}
diff --git a/camel/models/__init__.py b/camel/models/__init__.py
index d5be95679..15dad9fd2 100644
--- a/camel/models/__init__.py
+++ b/camel/models/__init__.py
@@ -23,6 +23,7 @@ from .mistral_model import MistralModel
from .model_factory import ModelFactory
from .model_manager import ModelManager, ModelProcessingError
from .nemotron_model import NemotronModel
+from .nvidia_model import NvidiaModel
from .ollama_model import OllamaModel
from .openai_audio_models import OpenAIAudioModels
from .openai_compatible_model import OpenAICompatibleModel
@@ -51,6 +52,7 @@ __all__ = [
'LiteLLMModel',
'OpenAIAudioModels',
'NemotronModel',
+ 'NvidiaModel',
'OllamaModel',
'VLLMModel',
'GeminiModel',
diff --git a/camel/models/model_factory.py b/camel/models/model_factory.py
index 3d5ca1d96..f9250b54a 100644
--- a/camel/models/model_factory.py
+++ b/camel/models/model_factory.py
@@ -22,6 +22,7 @@ from camel.models.gemini_model import GeminiModel
from camel.models.groq_model import GroqModel
from camel.models.litellm_model import LiteLLMModel
from camel.models.mistral_model import MistralModel
+from camel.models.nvidia_model import NvidiaModel
from camel.models.ollama_model import OllamaModel
from camel.models.openai_compatible_model import OpenAICompatibleModel
from camel.models.openai_model import OpenAIModel
@@ -93,6 +94,8 @@ class ModelFactory:
model_class = TogetherAIModel
elif model_platform.is_litellm:
model_class = LiteLLMModel
+ elif model_platform.is_nvidia:
+ model_class = NvidiaModel
elif model_platform.is_openai and model_type.is_openai:
model_class = OpenAIModel
diff --git a/camel/models/nvidia_model.py b/camel/models/nvidia_model.py
new file mode 100644
index 000000000..34af71363
--- /dev/null
+++ b/camel/models/nvidia_model.py
@@ -0,0 +1,141 @@
+# ========= 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. =========
+
+import os
+from typing import Any, Dict, List, Optional, Union
+
+from openai import OpenAI, Stream
+from openai.types.chat import (
+ ChatCompletion,
+ ChatCompletionChunk,
+)
+
+from camel.configs import NVIDIA_API_PARAMS, NvidiaConfig
+from camel.messages import OpenAIMessage
+from camel.models import BaseModelBackend
+from camel.types import ModelType
+from camel.utils import BaseTokenCounter, OpenAITokenCounter, api_keys_required
+
+
+class NvidiaModel(BaseModelBackend):
+ r"""NVIDIA API in a unified BaseModelBackend interface.
+
+ Args:
+ model_type (Union[ModelType, str]): Model for which a backend is
+ created, one of NVIDIA series.
+ model_config_dict (Optional[Dict[str, Any]], optional): A dictionary
+ that will be fed into:obj:`openai.ChatCompletion.create()`. If
+ :obj:`None`, :obj:`NvidiaConfig().as_dict()` will be used.
+ (default: :obj:`None`)
+ api_key (Optional[str], optional): The API key for authenticating with
+ the NVIDIA service. (default: :obj:`None`)
+ url (Optional[str], optional): The url to the NVIDIA service.
+ (default: :obj:`None`)
+ token_counter (Optional[BaseTokenCounter], optional): Token counter to
+ use for the model. If not provided, :obj:`OpenAITokenCounter(
+ ModelType.GPT_4)` 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 = NvidiaConfig().as_dict()
+ api_key = api_key or os.environ.get("NVIDIA_API_KEY")
+ url = url or os.environ.get(
+ "NVIDIA_API_BASE_URL", "https://integrate.api.nvidia.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("NVIDIA_API_KEY")
+ def run(
+ self,
+ messages: List[OpenAIMessage],
+ ) -> Union[ChatCompletion, Stream[ChatCompletionChunk]]:
+ r"""Runs inference of NVIDIA 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.
+ """
+
+ # Remove tool-related parameters if no tools are specified
+ config = dict(self.model_config_dict)
+ if not config.get('tools'): # None or empty list
+ config.pop('tools', None)
+ config.pop('tool_choice', None)
+
+ response = self._client.chat.completions.create(
+ messages=messages,
+ model=self.model_type,
+ **config,
+ )
+ 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 NVIDIA API.
+
+ Raises:
+ ValueError: If the model configuration dictionary contains any
+ unexpected arguments to NVIDIA API.
+ """
+ for param in self.model_config_dict:
+ if param not in NVIDIA_API_PARAMS:
+ raise ValueError(
+ f"Unexpected argument `{param}` is "
+ "input into NVIDIA 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 7accc698e..c623a683b 100644
--- a/camel/types/enums.py
+++ b/camel/types/enums.py
@@ -65,7 +65,17 @@ class ModelType(UnifiedModelType, Enum):
CLAUDE_3_5_SONNET = "claude-3-5-sonnet-20240620"
# Nvidia models
- NEMOTRON_4_REWARD = "nvidia/nemotron-4-340b-reward"
+ NVIDIA_NEMOTRON_340B_INSTRUCT = "nvidia/nemotron-4-340b-instruct"
+ NVIDIA_NEMOTRON_340B_REWARD = "nvidia/nemotron-4-340b-reward"
+ NVIDIA_YI_LARGE = "01-ai/yi-large"
+ NVIDIA_MISTRAL_LARGE = "mistralai/mistral-large"
+ NVIDIA_MIXTRAL_8X7B = "mistralai/mixtral-8x7b-instruct"
+ NVIDIA_LLAMA3_70B = "meta/llama3-70b"
+ NVIDIA_LLAMA3_1_8B_INSTRUCT = "meta/llama-3.1-8b-instruct"
+ NVIDIA_LLAMA3_1_70B_INSTRUCT = "meta/llama-3.1-70b-instruct"
+ NVIDIA_LLAMA3_1_405B_INSTRUCT = "meta/llama-3.1-405b-instruct"
+ NVIDIA_LLAMA3_2_1B_INSTRUCT = "meta/llama-3.2-1b-instruct"
+ NVIDIA_LLAMA3_2_3B_INSTRUCT = "meta/llama-3.2-3b-instruct"
# Gemini models
GEMINI_1_5_FLASH = "gemini-1.5-flash"
@@ -226,13 +236,19 @@ class ModelType(UnifiedModelType, Enum):
@property
def is_nvidia(self) -> bool:
- r"""Returns whether this type of models is Nvidia-released model.
-
- Returns:
- bool: Whether this type of models is nvidia.
- """
+ r"""Returns whether this type of models is a NVIDIA model."""
return self in {
- ModelType.NEMOTRON_4_REWARD,
+ ModelType.NVIDIA_NEMOTRON_340B_INSTRUCT,
+ ModelType.NVIDIA_NEMOTRON_340B_REWARD,
+ ModelType.NVIDIA_YI_LARGE,
+ ModelType.NVIDIA_MISTRAL_LARGE,
+ ModelType.NVIDIA_LLAMA3_70B,
+ ModelType.NVIDIA_MIXTRAL_8X7B,
+ ModelType.NVIDIA_LLAMA3_1_8B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_1_70B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_1_405B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_2_1B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_2_3B_INSTRUCT,
}
@property
@@ -330,7 +346,6 @@ class ModelType(UnifiedModelType, Enum):
if self is ModelType.GLM_4V:
return 1024
elif self in {
- ModelType.NEMOTRON_4_REWARD,
ModelType.STUB,
ModelType.REKA_CORE,
ModelType.REKA_EDGE,
@@ -339,6 +354,8 @@ class ModelType(UnifiedModelType, Enum):
ModelType.QWEN_MATH_TURBO,
ModelType.COHERE_COMMAND,
ModelType.COHERE_COMMAND_LIGHT,
+ ModelType.NVIDIA_NEMOTRON_340B_INSTRUCT,
+ ModelType.NVIDIA_NEMOTRON_340B_REWARD,
}:
return 4_096
elif self in {
@@ -350,6 +367,7 @@ class ModelType(UnifiedModelType, Enum):
ModelType.GLM_3_TURBO,
ModelType.GLM_4,
ModelType.QWEN_VL_PLUS,
+ ModelType.NVIDIA_LLAMA3_70B,
}:
return 8_192
elif self in {
@@ -371,6 +389,9 @@ class ModelType(UnifiedModelType, Enum):
ModelType.YI_LARGE_FC,
ModelType.QWEN_MAX,
ModelType.QWEN_VL_MAX,
+ ModelType.NVIDIA_YI_LARGE,
+ ModelType.NVIDIA_MISTRAL_LARGE,
+ ModelType.NVIDIA_MIXTRAL_8X7B,
ModelType.QWEN_QWQ_32B,
}:
return 32_768
@@ -402,6 +423,11 @@ class ModelType(UnifiedModelType, Enum):
ModelType.COHERE_COMMAND_R,
ModelType.COHERE_COMMAND_R_PLUS,
ModelType.COHERE_COMMAND_NIGHTLY,
+ ModelType.NVIDIA_LLAMA3_1_8B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_1_70B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_1_405B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_2_1B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_2_3B_INSTRUCT,
}:
return 128_000
elif self in {
@@ -583,6 +609,7 @@ class ModelPlatformType(Enum):
COHERE = "cohere"
YI = "lingyiwanwu"
QWEN = "tongyi-qianwen"
+ NVIDIA = "nvidia"
DEEPSEEK = "deepseek"
@property
@@ -671,6 +698,11 @@ class ModelPlatformType(Enum):
r"""Returns whether this platform is Qwen."""
return self is ModelPlatformType.QWEN
+ @property
+ def is_nvidia(self) -> bool:
+ r"""Returns whether this platform is Nvidia."""
+ return self is ModelPlatformType.NVIDIA
+
@property
def is_deepseek(self) -> bool:
r"""Returns whether this platform is DeepSeek."""
diff --git a/docs/key_modules/models.md b/docs/key_modules/models.md
index 157e7098c..210ae6c8c 100644
--- a/docs/key_modules/models.md
+++ b/docs/key_modules/models.md
@@ -72,7 +72,7 @@ The following table lists currently supported model platforms by CAMEL.
| Reka | reka-core | Y |
| Reka | reka-flash | Y |
| Reka | reka-edge | Y |
-| Nividia | nemotron-4-340b-reward | N |
+| Nvidia | https://docs.api.nvidia.com/nim/reference/llm-apis | ----- |
| SambaNova| https://community.sambanova.ai/t/supported-models/193 | ----- |
| Groq | https://console.groq.com/docs/models | ----- |
| Ollama | https://ollama.com/library | ----- |
diff --git a/examples/models/nemotron_model_example.py b/examples/models/nemotron_model_example.py
index de50f0429..e704a17c7 100644
--- a/examples/models/nemotron_model_example.py
+++ b/examples/models/nemotron_model_example.py
@@ -15,7 +15,7 @@
from camel.models import NemotronModel
from camel.types import ModelType
-nemotro = NemotronModel(model_type=ModelType.NEMOTRON_4_REWARD)
+nemotro = NemotronModel(model_type=ModelType.NVIDIA_NEMOTRON_340B_REWARD)
message = [
{"role": "user", "content": "I am going to Paris, what should I see?"},
diff --git a/examples/models/nvidia_model_example.py b/examples/models/nvidia_model_example.py
new file mode 100644
index 000000000..d61e481a2
--- /dev/null
+++ b/examples/models/nvidia_model_example.py
@@ -0,0 +1,145 @@
+# ========= 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 NvidiaConfig
+from camel.models import ModelFactory
+from camel.types import ModelPlatformType, ModelType
+
+model = ModelFactory.create(
+ model_platform=ModelPlatformType.NVIDIA,
+ model_type=ModelType.NVIDIA_LLAMA3_1_405B_INSTRUCT,
+ model_config_dict=NvidiaConfig(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 = """give me python code to develop a trading bot"""
+
+# Get response information
+response = camel_agent.step(user_msg)
+print(response.msgs[0].content)
+
+'''
+===============================================================================
+Here is a basic example of a trading bot in Python using the Binance API. This
+bot will buy and sell a specified cryptocurrency based on a simple moving
+average crossover strategy.
+
+**Please note that this is a simplified example and should not be used for
+actual trading without further development and testing. Trading with a bot
+carries significant risks, including financial losses.**
+
+**Required Libraries:**
+
+* `ccxt` (CryptoCurrency eXchange Trading Library)
+* `pandas` (for data manipulation)
+* `numpy` (for numerical computations)
+
+**Code:**
+```python
+import ccxt
+import pandas as pd
+import numpy as np
+
+# Set up Binance API credentials
+api_key = 'YOUR_API_KEY'
+api_secret = 'YOUR_API_SECRET'
+
+# Set up the exchange and API connection
+exchange = ccxt.binance({
+ 'apiKey': api_key,
+ 'apiSecret': api_secret,
+})
+
+# Define the trading parameters
+symbol = 'BTC/USDT' # Trading pair
+amount = 100 # Amount to trade (in USDT)
+short_window = 20 # Short moving average window (in minutes)
+long_window = 50 # Long moving average window (in minutes)
+
+# Define the trading strategy
+def strategy(data):
+ short_ma = data['Close'].rolling(window=short_window).mean()
+ long_ma = data['Close'].rolling(window=long_window).mean()
+
+ if short_ma > long_ma:
+ return 'BUY'
+ elif short_ma < long_ma:
+ return 'SELL'
+ else:
+ return 'HOLD'
+
+# Define the trading function
+def trade(exchange, symbol, amount, strategy):
+ # Get the latest candlestick data
+ data = exchange.fetch_ohlcv(symbol, timeframe='1m')
+ df = pd.DataFrame(
+ data,
+ columns=['Time', 'Open', 'High', 'Low', 'Close', 'Volume']
+ )
+
+ # Apply the trading strategy
+ signal = strategy(df)
+
+ # Execute the trade
+ if signal == 'BUY':
+ exchange.place_order(
+ symbol, 'limit', 'buy', amount, df['Close'].iloc[-1]
+ )
+ print(f'Buy {amount} {symbol} at {df["Close"].iloc[-1]}')
+ elif signal == 'SELL':
+ exchange.place_order(
+ symbol, 'limit', 'sell', amount, df['Close'].iloc[-1]
+ )
+ print(f'Sell {amount} {symbol} at {df["Close"].iloc[-1]}')
+ else:
+ print('Hold')
+
+# Run the trading bot
+while True:
+ trade(exchange, symbol, amount, strategy)
+ time.sleep(60) # Wait 1 minute before checking again
+
+```
+
+**Explanation:**
+
+1. The code sets up a connection to the Binance API using the `ccxt` library.
+2. It defines the trading parameters, including the trading pair, amount to
+ trade, and moving average windows.
+3. The `strategy` function calculates the short and long moving averages and
+ returns a trading signal (BUY, SELL, or HOLD).
+4. The `trade` function gets the latest candlestick data, applies the trading
+ strategy, and executes the trade using the `place_order` method.
+5. The code runs in an infinite loop, checking for trading signals every
+ minute.
+
+**Note:** This is a basic example and you should consider implementing
+additional features, such as:
+
+* Risk management (e.g., stop-loss, position sizing)
+* Error handling (e.g., API errors, network issues)
+* More sophisticated trading strategies
+* Support for multiple trading pairs
+* Integration with a database or logging system
+
+I hope this helps! Let me know if you have any questions or need
+further assistance.
+===============================================================================
+'''
diff --git a/test/models/test_nvidia_model.py b/test/models/test_nvidia_model.py
new file mode 100644
index 000000000..772a4f056
--- /dev/null
+++ b/test/models/test_nvidia_model.py
@@ -0,0 +1,63 @@
+# ========= 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. =========
+
+import re
+
+import pytest
+
+from camel.configs import NvidiaConfig
+from camel.models import NvidiaModel
+from camel.types import ModelType
+
+
+ "model_type",
+ [
+ ModelType.NVIDIA_NEMOTRON_340B_INSTRUCT,
+ ModelType.NVIDIA_NEMOTRON_340B_REWARD,
+ ModelType.NVIDIA_YI_LARGE,
+ ModelType.NVIDIA_MISTRAL_LARGE,
+ ModelType.NVIDIA_LLAMA3_70B,
+ ModelType.NVIDIA_MIXTRAL_8X7B,
+ ModelType.NVIDIA_LLAMA3_1_8B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_1_70B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_1_405B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_2_1B_INSTRUCT,
+ ModelType.NVIDIA_LLAMA3_2_3B_INSTRUCT,
+ ],
+)
+def test_nvidia_model(model_type: ModelType):
+ model = NvidiaModel(model_type)
+ assert model.model_type == model_type
+ assert model.model_config_dict == NvidiaConfig().as_dict()
+ assert isinstance(model.model_type.value_for_tiktoken, str)
+ assert isinstance(model.model_type.token_limit, int)
+
+
+def test_nvidia_model_unexpected_argument():
+ model_type = ModelType.NVIDIA_LLAMA3_70B
+ model_config_dict = {"model_path": "nvidia-llama3"}
+
+ with pytest.raises(
+ ValueError,
+ match=re.escape(
+ (
+ "Unexpected argument `model_path` is "
+ "input into NVIDIA model backend."
+ )
+ ),
+ ):
+ _ = NvidiaModel(model_type, model_config_dict)