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

fix: model token_limit and gemini dependency (#719)

Wendong-Fane38125d6c742
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml
index f270778e7..946cc4ab7 100644
--- a/.github/ISSUE_TEMPLATE/bug_report.yml
+++ b/.github/ISSUE_TEMPLATE/bug_report.yml
@@ -27,7 +27,7 @@ body:
attributes:
label: What version of camel are you using?
description: Run command `python3 -c 'print(__import__("camel").__version__)'` in your shell and paste the output here.
- placeholder: E.g., 0.1.5.6
+ placeholder: E.g., 0.1.5.7
validations:
required: true
diff --git a/README.md b/README.md
index 4a36e3766..e5eda0a71 100644
--- a/README.md
+++ b/README.md
@@ -110,7 +110,7 @@ conda create --name camel python=3.9
conda activate camel
# Clone github repo
-git clone -b v0.1.5.6 https://github.com/camel-ai/camel.git
+git clone -b v0.1.5.7 https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
diff --git a/camel/__init__.py b/camel/__init__.py
index ea2b8ceea..9b54c10e6 100644
--- a/camel/__init__.py
+++ b/camel/__init__.py
@@ -12,7 +12,7 @@
# limitations under the License.
# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========
-__version__ = '0.1.5.6'
+__version__ = '0.1.5.7'
__all__ = [
'__version__',
diff --git a/camel/configs/gemini_config.py b/camel/configs/gemini_config.py
index 8e5c39939..757905a6f 100644
--- a/camel/configs/gemini_config.py
+++ b/camel/configs/gemini_config.py
@@ -15,10 +15,19 @@
from collections.abc import Iterable
from dataclasses import asdict, dataclass
-from typing import Optional
+from typing import TYPE_CHECKING, Optional
from camel.configs.base_config import BaseConfig
+if TYPE_CHECKING:
+ from google.generativeai.protos import Schema
+ from google.generativeai.types.content_types import (
+ FunctionLibraryType,
+ ToolConfigType,
+ )
+ from google.generativeai.types.helper_types import RequestOptionsType
+ from google.generativeai.types.safety_types import SafetySettingOptions
+
@dataclass(frozen=True)
class GeminiConfig(BaseConfig):
@@ -72,14 +81,6 @@ class GeminiConfig(BaseConfig):
Options for the request.
"""
- from google.generativeai.protos import Schema
- from google.generativeai.types.content_types import (
- FunctionLibraryType,
- ToolConfigType,
- )
- from google.generativeai.types.helper_types import RequestOptionsType
- from google.generativeai.types.safety_types import SafetySettingOptions
-
candidate_count: Optional[int] = None
stop_sequences: Optional[Iterable[str]] = None
max_output_tokens: Optional[int] = None
@@ -87,11 +88,11 @@ class GeminiConfig(BaseConfig):
top_p: Optional[float] = None
top_k: Optional[int] = None
response_mime_type: Optional[str] = None
- response_schema: Optional[Schema] = None
- safety_settings: Optional[SafetySettingOptions] = None
- tools: Optional[FunctionLibraryType] = None
- tool_config: Optional[ToolConfigType] = None
- request_options: Optional[RequestOptionsType] = None
+ response_schema: Optional['Schema'] = None
+ safety_settings: Optional['SafetySettingOptions'] = None
+ tools: Optional['FunctionLibraryType'] = None
+ tool_config: Optional['ToolConfigType'] = None
+ request_options: Optional['RequestOptionsType'] = None
Gemini_API_PARAMS = {param for param in asdict(GeminiConfig()).keys()}
diff --git a/camel/models/base_model.py b/camel/models/base_model.py
index 9937f07ba..7df7c0ce3 100644
--- a/camel/models/base_model.py
+++ b/camel/models/base_model.py
@@ -109,7 +109,10 @@ class BaseModelBackend(ABC):
Returns:
int: The maximum token limit for the given model.
"""
- return self.model_type.token_limit
+ return (
+ self.model_config_dict.get("max_tokens")
+ or self.model_type.token_limit
+ )
@property
def stream(self) -> bool:
diff --git a/camel/models/litellm_model.py b/camel/models/litellm_model.py
index 83b0b77a4..a8e7e0d3e 100644
--- a/camel/models/litellm_model.py
+++ b/camel/models/litellm_model.py
@@ -138,3 +138,19 @@ class LiteLLMModel:
f"Unexpected argument `{param}` is "
"input into LiteLLM model backend."
)
+
+ @property
+ def token_limit(self) -> int:
+ """Returns the maximum token limit for the given model.
+
+ Returns:
+ int: The maximum token limit for the given model.
+ """
+ max_tokens = self.model_config_dict.get("max_tokens")
+ if isinstance(max_tokens, int):
+ return max_tokens
+ print(
+ "Must set `max_tokens` as an integer in `model_config_dict` when"
+ " setting up the model. Using 4096 as default value."
+ )
+ return 4096
diff --git a/camel/models/ollama_model.py b/camel/models/ollama_model.py
index a7de1fd0d..4afe6c0d3 100644
--- a/camel/models/ollama_model.py
+++ b/camel/models/ollama_model.py
@@ -104,6 +104,22 @@ class OllamaModel:
)
return response
+ @property
+ def token_limit(self) -> int:
+ """Returns the maximum token limit for the given model.
+
+ Returns:
+ int: The maximum token limit for the given model.
+ """
+ max_tokens = self.model_config_dict.get("max_tokens")
+ if isinstance(max_tokens, int):
+ return max_tokens
+ print(
+ "Must set `max_tokens` as an integer in `model_config_dict` when"
+ " setting up the model. Using 4096 as default value."
+ )
+ return 4096
+
@property
def stream(self) -> bool:
r"""Returns whether the model is in stream mode, which sends partial
diff --git a/camel/models/zhipuai_model.py b/camel/models/zhipuai_model.py
index 32d402d5a..62025ea92 100644
--- a/camel/models/zhipuai_model.py
+++ b/camel/models/zhipuai_model.py
@@ -118,7 +118,6 @@ class ZhipuAIModel(BaseModelBackend):
f"Unexpected argument `{param}` is "
"input into ZhipuAI model backend."
)
- pass
@property
def stream(self) -> bool:
diff --git a/docs/conf.py b/docs/conf.py
index 3e186e48c..ae648c3dc 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -27,7 +27,7 @@ sys.path.insert(0, os.path.abspath('..'))
project = 'CAMEL'
copyright = '2023, CAMEL-AI.org'
author = 'CAMEL-AI.org'
-release = '0.1.5.6'
+release = '0.1.5.7'
html_favicon = (
'https://raw.githubusercontent.com/camel-ai/camel/master/misc/favicon.png'
diff --git a/docs/get_started/setup.md b/docs/get_started/setup.md
index 5aeea5598..7256c50fe 100644
--- a/docs/get_started/setup.md
+++ b/docs/get_started/setup.md
@@ -61,7 +61,7 @@ conda create --name camel python=3.10
conda activate camel
# Clone github repo
-git clone -b v0.1.5.6 https://github.com/camel-ai/camel.git
+git clone -b v0.1.5.7 https://github.com/camel-ai/camel.git
# Change directory into project directory
cd camel
diff --git a/pyproject.toml b/pyproject.toml
index c198e8cb1..8b3ce8855 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "camel-ai"
-version = "0.1.5.6"
+version = "0.1.5.7"
authors = ["CAMEL-AI.org"]
description = "Communicative Agents for AI Society Study"
readme = "README.md"