diff --git a/playground/demos/optimize_llm_stack/vortex.py b/playground/demos/optimize_llm_stack/vortex.py index 85571f5a..25756a81 100644 --- a/playground/demos/optimize_llm_stack/vortex.py +++ b/playground/demos/optimize_llm_stack/vortex.py @@ -3,35 +3,34 @@ import subprocess from dotenv import load_dotenv -from swarms.memory import WeaviateClient -from swarms.models.vllm import vLLM +from swarms.models import OpenAIChat from swarms.structs import Agent from swarms.utils.phoenix_handler import phoenix_trace_decorator -try: - import modal -except ImportError: - print(f"modal not installed, please install it with `pip install modal`") - subprocess.run(["pip", "install", "modal"]) - - +import modal load_dotenv() # Model -llm = vLLM() +llm = OpenAIChat( + openai_api_key=os.getenv("OPENAI_API_KEY"), + model_name="gpt-4", + max_tokens=4000, +) # Modal stub = modal.Stub(name="swarms") # Agent -@phoenix_trace_decorator +@phoenix_trace_decorator( + "This function is an agent and is traced by Phoenix." +) @stub.function(gpu="any") def agent(task: str): agent = Agent( - llm = llm, - max_loops=1, + llm=llm, + max_loops=1, ) out = agent.run(task=task) - return out \ No newline at end of file + return out diff --git a/pyproject.toml b/pyproject.toml index 31891686..26cf54ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "2.6.6" +version = "2.6.7" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] diff --git a/swarms/memory/__init__.py b/swarms/memory/__init__.py index 80657afc..284b9b4f 100644 --- a/swarms/memory/__init__.py +++ b/swarms/memory/__init__.py @@ -1,11 +1,6 @@ -try: - from swarms.memory.weaviate import WeaviateClient -except ImportError: - pass from swarms.memory.base_vectordb import VectorDatabase __all__ = [ - "WeaviateClient", "VectorDatabase", ] diff --git a/swarms/memory/weaviate.py b/swarms/memory/weaviate.py deleted file mode 100644 index 2f06e302..00000000 --- a/swarms/memory/weaviate.py +++ /dev/null @@ -1,216 +0,0 @@ -""" -Weaviate API Client -""" -import os -import subprocess -from typing import Any, Dict, List, Optional - -from swarms.memory.base_vectordb import VectorDatabase - -try: - import weaviate -except ImportError as error: - print("pip install weaviate-client") - subprocess.run(["pip", "install", "weaviate-client"]) - - -class WeaviateClient(VectorDatabase): - """ - - Weaviate API Client - Interface to Weaviate, a vector database with a GraphQL API. - - Args: - http_host (str): The HTTP host of the Weaviate server. - http_port (str): The HTTP port of the Weaviate server. - http_secure (bool): Whether to use HTTPS. - grpc_host (Optional[str]): The gRPC host of the Weaviate server. - grpc_port (Optional[str]): The gRPC port of the Weaviate server. - grpc_secure (Optional[bool]): Whether to use gRPC over TLS. - auth_client_secret (Optional[Any]): The authentication client secret. - additional_headers (Optional[Dict[str, str]]): Additional headers to send with requests. - additional_config (Optional[weaviate.AdditionalConfig]): Additional configuration for the client. - - Methods: - create_collection: Create a new collection in Weaviate. - add: Add an object to a specified collection. - query: Query objects from a specified collection. - update: Update an object in a specified collection. - delete: Delete an object from a specified collection. - - Examples: - >>> from swarms.memory import WeaviateClient - """ - - def __init__( - self, - http_host: str, - http_port: str, - http_secure: bool, - grpc_host: Optional[str] = None, - grpc_port: Optional[str] = None, - grpc_secure: Optional[bool] = None, - auth_client_secret: Optional[Any] = None, - additional_headers: Optional[Dict[str, str]] = None, - additional_config: Optional[weaviate.AdditionalConfig] = None, - connection_params: Dict[str, Any] = None, - *args, - **kwargs, - ): - super().__init__(*args, **kwargs) - self.http_host = http_host - self.http_port = http_port - self.http_secure = http_secure - self.grpc_host = grpc_host - self.grpc_port = grpc_port - self.grpc_secure = grpc_secure - self.auth_client_secret = auth_client_secret - self.additional_headers = additional_headers - self.additional_config = additional_config - self.connection_params = connection_params - - # If connection_params are provided, use them to initialize the client. - connection_params = weaviate.ConnectionParams.from_params( - http_host=http_host, - http_port=http_port, - http_secure=http_secure, - grpc_host=grpc_host, - grpc_port=grpc_port, - grpc_secure=grpc_secure, - ) - - # If additional headers are provided, add them to the connection params. - self.client = weaviate.WeaviateClient( - connection_params=connection_params, - auth_client_secret=auth_client_secret, - additional_headers=additional_headers, - additional_config=additional_config, - ) - - def create_collection( - self, - name: str, - properties: List[Dict[str, Any]], - vectorizer_config: Any = None, - ): - """Create a new collection in Weaviate. - - Args: - name (str): _description_ - properties (List[Dict[str, Any]]): _description_ - vectorizer_config (Any, optional): _description_. Defaults to None. - """ - try: - out = self.client.collections.create( - name=name, - vectorizer_config=vectorizer_config, - properties=properties, - ) - print(out) - except Exception as error: - print(f"Error creating collection: {error}") - raise - - def add(self, collection_name: str, properties: Dict[str, Any]): - """Add an object to a specified collection. - - Args: - collection_name (str): _description_ - properties (Dict[str, Any]): _description_ - - Returns: - _type_: _description_ - """ - try: - collection = self.client.collections.get(collection_name) - return collection.data.insert(properties) - except Exception as error: - print(f"Error adding object: {error}") - raise - - def query( - self, collection_name: str, query: str, limit: int = 10 - ): - """Query objects from a specified collection. - - Args: - collection_name (str): _description_ - query (str): _description_ - limit (int, optional): _description_. Defaults to 10. - - Returns: - _type_: _description_ - """ - try: - collection = self.client.collections.get(collection_name) - response = collection.query.bm25(query=query, limit=limit) - return [o.properties for o in response.objects] - except Exception as error: - print(f"Error querying objects: {error}") - raise - - def update( - self, - collection_name: str, - object_id: str, - properties: Dict[str, Any], - ): - """UPdate an object in a specified collection. - - Args: - collection_name (str): _description_ - object_id (str): _description_ - properties (Dict[str, Any]): _description_ - """ - try: - collection = self.client.collections.get(collection_name) - collection.data.update(object_id, properties) - except Exception as error: - print(f"Error updating object: {error}") - raise - - def delete(self, collection_name: str, object_id: str): - """Delete an object from a specified collection. - - Args: - collection_name (str): _description_ - object_id (str): _description_ - """ - try: - collection = self.client.collections.get(collection_name) - collection.data.delete_by_id(object_id) - except Exception as error: - print(f"Error deleting object: {error}") - raise - - -# # Example usage -# connection_params = { -# "http_host": "YOUR_HTTP_HOST", -# "http_port": "YOUR_HTTP_PORT", -# "http_secure": True, -# "grpc_host": "YOUR_gRPC_HOST", -# "grpc_port": "YOUR_gRPC_PORT", -# "grpc_secure": True, -# "auth_client_secret": weaviate.AuthApiKey("YOUR_APIKEY"), -# "additional_headers": {"X-OpenAI-Api-Key": "YOUR_OPENAI_APIKEY"}, -# "additional_config": weaviate.AdditionalConfig( -# startup_period=10, timeout=(5, 15) -# ), -# } - -# weaviate_client = WeaviateClient(connection_params) - - -# # Example usage -# weaviate_client = WeaviateClient( -# http_host="YOUR_HTTP_HOST", -# http_port="YOUR_HTTP_PORT", -# http_secure=True, -# grpc_host="YOUR_gRPC_HOST", -# grpc_port="YOUR_gRPC_PORT", -# grpc_secure=True, -# auth_client_secret=weaviate.AuthApiKey("YOUR_APIKEY"), -# additional_headers={"X-OpenAI-Api-Key": "YOUR_OPENAI_APIKEY"}, -# additional_config=weaviate.AdditionalConfig(startup_period=10, timeout=(5, 15)) -# ) diff --git a/swarms/models/__init__.py b/swarms/models/__init__.py index 604b4f58..539d849b 100644 --- a/swarms/models/__init__.py +++ b/swarms/models/__init__.py @@ -9,10 +9,10 @@ from swarms.models.openai_models import ( OpenAIChat, ) # noqa: E402 -try: - from swarms.models.vllm import vLLM # noqa: E402 -except ImportError: - pass +# try: +# from swarms.models.vllm import vLLM # noqa: E402 +# except ImportError: +# pass # from swarms.models.zephyr import Zephyr # noqa: E402 from swarms.models.biogpt import BioGPT # noqa: E402 @@ -64,5 +64,5 @@ __all__ = [ # "Dalle3", # "DistilWhisperModel", "GPT4VisionAPI", - "vLLM", + # "vLLM", ] diff --git a/swarms/utils/__init__.py b/swarms/utils/__init__.py index f1ac4f06..7dadd2f7 100644 --- a/swarms/utils/__init__.py +++ b/swarms/utils/__init__.py @@ -6,7 +6,7 @@ from swarms.utils.parse_code import ( from swarms.utils.pdf_to_text import pdf_to_text try: - from swarms.utils.phoenix_handler import phoenix_trace_decorator + from swarms.utils.phoenix_handler import phoenix_trace_decorator except ImportError: pass @@ -15,5 +15,5 @@ __all__ = [ "SubprocessCodeInterpreter", "extract_code_in_backticks_in_string", "pdf_to_text", - "phoenix_trace_decorator" + "phoenix_trace_decorator", ] diff --git a/swarms/utils/phoenix_handler.py b/swarms/utils/phoenix_handler.py index a7820be8..641e01cf 100644 --- a/swarms/utils/phoenix_handler.py +++ b/swarms/utils/phoenix_handler.py @@ -3,14 +3,7 @@ import sys import traceback import functools -try: - import phoenix as px -except Exception as error: - print(f"Error importing phoenix: {error}") - print("Please install phoenix: pip install phoenix") - subprocess.run( - [sys.executable, "-m", "pip", "install", "arize-mlflow"] - ) +import phoenix as px def phoenix_trace_decorator(doc_string):