🐫 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: Subprocess support for Ollma and vllm (#912)
Wendong-Fan72f8b89d8246
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.ymlindex e4201ec01..2fc95aa40 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.6.9+ placeholder: E.g., 0.1.7.0validations:required: truediff --git a/README.md b/README.mdindex 30dfaea55..99c933251 100644--- a/README.md+++ b/README.md@@ -119,7 +119,7 @@ conda create --name camel python=3.10conda activate camel# Clone github repo-git clone -b v0.1.6.9 https://github.com/camel-ai/camel.git+git clone -b v0.1.7.0 https://github.com/camel-ai/camel.git# Change directory into project directorycd cameldiff --git a/camel/__init__.py b/camel/__init__.pyindex 3690856b8..492ba07ef 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.6.9'+__version__ = '0.1.7.0'__all__ = ['__version__',diff --git a/camel/models/ollama_model.py b/camel/models/ollama_model.pyindex f7df7e740..bdc974026 100644--- a/camel/models/ollama_model.py+++ b/camel/models/ollama_model.py@@ -12,6 +12,7 @@# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========import os+import subprocessfrom typing import Any, Dict, List, Optional, Unionfrom openai import OpenAI, Stream@@ -48,17 +49,38 @@ class OllamaModel:"""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 Ollama+ self._url = (+ url+ or os.environ.get("OLLAMA_BASE_URL")+ or "http://localhost:11434/v1"+ )+ if not url and not os.environ.get("OLLAMA_BASE_URL"):+ self._start_server()+ # Use OpenAI client as interface call Ollamaself._client = OpenAI(timeout=60,max_retries=3,- base_url=self._url or "http://localhost:11434/v1",+ base_url=self._url,api_key="ollama", # required but ignored)self._token_counter = token_counterself.check_model_config()+ def _start_server(self) -> None:+ r"""Starts the Ollama server in a subprocess."""+ try:+ subprocess.Popen(+ ["ollama", "server", "--port", "11434"],+ stdout=subprocess.PIPE,+ stderr=subprocess.PIPE,+ )+ print(+ f"Ollama server started on http://localhost:11434/v1 "+ f"for {self.model_type} model"+ )+ except Exception as e:+ print(f"Failed to start Ollama server: {e}")+@propertydef token_counter(self) -> BaseTokenCounter:r"""Initialize the token counter for the model backend.diff --git a/camel/models/vllm_model.py b/camel/models/vllm_model.pyindex c479fc064..afe6496a0 100644--- a/camel/models/vllm_model.py+++ b/camel/models/vllm_model.py@@ -12,6 +12,7 @@# limitations under the License.# =========== Copyright 2023 @ CAMEL-AI.org. All Rights Reserved. ===========import os+import subprocessfrom typing import Any, Dict, List, Optional, Unionfrom openai import OpenAI, Stream@@ -52,17 +53,38 @@ class VLLMModel:"""self.model_type = model_typeself.model_config_dict = model_config_dict- self._url = url or os.environ.get("VLLM_BASE_URL")+ self._url = (+ url+ or os.environ.get("VLLM_BASE_URL")+ or "http://localhost:8000/v1"+ )+ if not url and not os.environ.get("VLLM_BASE_URL"):+ self._start_server()# Use OpenAI cilent as interface call vLLMself._client = OpenAI(timeout=60,max_retries=3,- base_url=self._url or "http://localhost:8000/v1",+ base_url=self._url,api_key=api_key,)self._token_counter = token_counterself.check_model_config()+ def _start_server(self) -> None:+ r"""Starts the vllm server in a subprocess."""+ try:+ subprocess.Popen(+ ["vllm", "server", "--port", "8000"],+ stdout=subprocess.PIPE,+ stderr=subprocess.PIPE,+ )+ print(+ f"vllm server started on http://localhost:8000/v1 "+ f"for {self.model_type} model"+ )+ except Exception as e:+ print(f"Failed to start vllm server: {e}")+@propertydef token_counter(self) -> BaseTokenCounter:r"""Initialize the token counter for the model backend.diff --git a/docs/conf.py b/docs/conf.pyindex e6b8d12d8..6e8ab1df3 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.6.9'+release = '0.1.7.0'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.mdindex f4144e2ff..0d9ebcc1f 100644--- a/docs/get_started/setup.md+++ b/docs/get_started/setup.md@@ -61,7 +61,7 @@ conda create --name camel python=3.10conda activate camel# Clone github repo-git clone -b v0.1.6.9 https://github.com/camel-ai/camel.git+git clone -b v0.1.7.0 https://github.com/camel-ai/camel.git# Change directory into project directorycd cameldiff --git a/examples/models/ollama_model_example.py b/examples/models/ollama_model_example.pyindex b48c4f1ef..1a84089ad 100644--- a/examples/models/ollama_model_example.py+++ b/examples/models/ollama_model_example.py@@ -19,8 +19,7 @@ from camel.types import ModelPlatformTypeollama_model = ModelFactory.create(model_platform=ModelPlatformType.OLLAMA,- model_type="llama3",- url="http://localhost:11434/v1",+ model_type="mistral",model_config_dict={"temperature": 0.4},)@@ -40,6 +39,8 @@ print(assistant_response.msg.content)"""===============================================================================+Ollama server started on http://localhost:11434/v1 for mistral model+Hi there! *waves* Hi to the amazing team at CAMEL AI - Autonomous andCommunicative Agents Laboratory! It's great to connect with you all. I'mexcited to learn more about your work in developing autonomous anddiff --git a/examples/models/vllm_model_example.py b/examples/models/vllm_model_example.pyindex 62d1b44ae..ea499d0cd 100644--- a/examples/models/vllm_model_example.py+++ b/examples/models/vllm_model_example.py@@ -20,7 +20,6 @@ from camel.types import ModelPlatformTypevllm_model = ModelFactory.create(model_platform=ModelPlatformType.VLLM,model_type="microsoft/Phi-3-mini-4k-instruct",- url="http://localhost:8000/v1",model_config_dict={"temperature": 0.0},api_key="vllm",)@@ -40,6 +39,9 @@ print(assistant_response.msg.content)"""===============================================================================+vllm server started on http://localhost:8000/v1 for microsoft/+Phi-3-mini-4k-instruct model+Hello! I'm Phi, an AI developed by Microsoft. How can I help you today?==============================================================================="""diff --git a/pyproject.toml b/pyproject.tomlindex e09125f79..aed0c40bf 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.6.9"+version = "0.1.7.0"authors = ["CAMEL-AI.org"]description = "Communicative Agents for AI Society Study"readme = "README.md"