From 62f7ac9fa629f27fb37559fe65c722cc3ee559df Mon Sep 17 00:00:00 2001 From: Kye Date: Fri, 20 Oct 2023 02:47:43 -0400 Subject: [PATCH] bug fixes, module error swarm. instead of swarms. Former-commit-id: dbcab9a06b7e2b192de1230f6d3babe711b004dd --- README.md | 34 +++++++++++++++++++++------------- example.py | 6 ++++-- pyproject.toml | 3 ++- requirements.txt | 2 +- swarms/__init__.py | 3 +-- swarms/chunkers/base.py | 2 +- swarms/chunkers/markdown.py | 2 +- swarms/hivemind/hivemind.py | 3 +++ swarms/models/__init__.py | 3 ++- swarms/models/anthropic.py | 18 +++++++++++++----- swarms/workers/worker.py | 9 +++++---- 11 files changed, 54 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 68b46f71..2f5d6f1c 100644 --- a/README.md +++ b/README.md @@ -45,14 +45,18 @@ from swarms.workers import Worker from swarms.swarms import MultiAgentDebate, select_speaker from swarms.models import OpenAIChat + +api_key = "sk-" + llm = OpenAIChat( model_name='gpt-4', - openai_api_key="api-key", + openai_api_key=api_key, temperature=0.5 ) node = Worker( llm=llm, + openai_api_key=api_key, ai_name="Optimus Prime", ai_role="Worker in a swarm", external_tools = None, @@ -62,6 +66,7 @@ node = Worker( node2 = Worker( llm=llm, + openai_api_key=api_key, ai_name="Bumble Bee", ai_role="Worker in a swarm", external_tools = None, @@ -71,6 +76,7 @@ node2 = Worker( node3 = Worker( llm=llm, + openai_api_key=api_key, ai_name="Bumble Bee", ai_role="Worker in a swarm", external_tools = None, @@ -104,30 +110,31 @@ for result in results: - And, then place the openai api key in the Worker for the openai embedding model ```python -from swarms.models import ChatOpenAI -from swarms.workers import Worker +from swarms.models import OpenAIChat +from swarms import Worker -llm = ChatOpenAI( - model_name='gpt-4', - openai_api_key="api-key", - temperature=0.5 +api_key = "" + +llm = OpenAIChat( + openai_api_key=api_key, + temperature=0.5, ) node = Worker( llm=llm, ai_name="Optimus Prime", - #openai key for the embeddings - openai_api_key="sk-eee" + openai_api_key=api_key, ai_role="Worker in a swarm", - external_tools = None, - human_in_the_loop = False, - temperature = 0.5, + external_tools=None, + human_in_the_loop=False, + temperature=0.5, ) task = "What were the winning boston marathon times for the past 5 years (ending in 2022)? Generate a table of the year, name, country of origin, and times." response = node.run(task) print(response) + ``` ------ @@ -139,8 +146,9 @@ print(response) from swarms.models import OpenAIChat from swarms.agents import OmniModalAgent +api_key = "SK-" -llm = OpenAIChat(model_name="gpt-4") +llm = OpenAIChat(model_name="gpt-4", openai_api_key=api_key) agent = OmniModalAgent(llm) diff --git a/example.py b/example.py index 8344c74d..59a1e341 100644 --- a/example.py +++ b/example.py @@ -1,15 +1,17 @@ from swarms.models import OpenAIChat from swarms import Worker +api_key = "" + llm = OpenAIChat( - openai_api_key="Enter in your key", + openai_api_key=api_key, temperature=0.5, ) node = Worker( llm=llm, ai_name="Optimus Prime", - openai_api_key="entter in your key", + openai_api_key=api_key, ai_role="Worker in a swarm", external_tools=None, human_in_the_loop=False, diff --git a/pyproject.toml b/pyproject.toml index dbe378dd..96a337fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "1.8.2" +version = "1.9.1" description = "Swarms - Pytorch" license = "MIT" authors = ["Kye Gomez "] @@ -38,6 +38,7 @@ duckduckgo-search = "*" faiss-cpu = "*" diffusers = "*" wget = "*" +griptape = "*" httpx = "*" ggl = "*" beautifulsoup4 = "*" diff --git a/requirements.txt b/requirements.txt index e61247e5..c92b868c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,7 @@ chromadb open-interpreter tabulate colored - +griptape addict albumentations basicsr diff --git a/swarms/__init__.py b/swarms/__init__.py index 42ce223e..e1dba262 100644 --- a/swarms/__init__.py +++ b/swarms/__init__.py @@ -12,11 +12,10 @@ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" from swarms import workers from swarms.workers.worker import Worker -from swarms.chunkers import chunkers +# from swarms import chunkers from swarms import models from swarms import structs from swarms import swarms -from swarms.swarms.orchestrate import Orchestrator from swarms import agents from swarms.logo import logo print(logo) \ No newline at end of file diff --git a/swarms/chunkers/base.py b/swarms/chunkers/base.py index 6983ff27..464f51e4 100644 --- a/swarms/chunkers/base.py +++ b/swarms/chunkers/base.py @@ -3,7 +3,7 @@ from abc import ABC from typing import Optional from attr import define, field, Factory from griptape.artifacts import TextArtifact -from swarm.chunkers.chunk_seperators import ChunkSeparator +from swarms.chunkers.chunk_seperators import ChunkSeparator from griptape.tokenizers import OpenAiTokenizer diff --git a/swarms/chunkers/markdown.py b/swarms/chunkers/markdown.py index 84dc9eac..6c0e755f 100644 --- a/swarms/chunkers/markdown.py +++ b/swarms/chunkers/markdown.py @@ -1,5 +1,5 @@ from swarms.chunkers.base import BaseChunker -from swarms.chunk_seperator import ChunkSeparator +from swarms.chunkers.chunk_seperator import ChunkSeparator class MarkdownChunker(BaseChunker): diff --git a/swarms/hivemind/hivemind.py b/swarms/hivemind/hivemind.py index e3e44927..acd4d5ec 100644 --- a/swarms/hivemind/hivemind.py +++ b/swarms/hivemind/hivemind.py @@ -7,8 +7,11 @@ import concurrent.futures import logging +import faiss +from swarms.embeddings.openai import OpenAIEmbeddings from swarms.swarms.swarms import HierarchicalSwarm +from swarms.vectorstore.vectorstore import FAISS, InMemoryDocstore logging.basicConfig( level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s" diff --git a/swarms/models/__init__.py b/swarms/models/__init__.py index 67260c79..fe66dee8 100644 --- a/swarms/models/__init__.py +++ b/swarms/models/__init__.py @@ -9,4 +9,5 @@ from swarms.models.zephyr import Zephyr # MultiModal Models from swarms.models.idefics import Idefics from swarms.models.kosmos_two import Kosmos -from swarms.models.vilt import Vilt \ No newline at end of file +from swarms.models.vilt import Vilt +# from swarms.models.fuyu import Fuyu \ No newline at end of file diff --git a/swarms/models/anthropic.py b/swarms/models/anthropic.py index cada8a05..453890b9 100644 --- a/swarms/models/anthropic.py +++ b/swarms/models/anthropic.py @@ -3,7 +3,15 @@ import os class Anthropic: - """Anthropic large language models.""" + """ + + Anthropic large language models. + + + Args: + + + """ def __init__( self, @@ -41,12 +49,12 @@ class Anthropic: d["top_p"] = self.top_p return d - def generate(self, prompt, stop=None): + def run(self, task: str, stop=None): """Call out to Anthropic's completion endpoint.""" stop = stop or [] params = self._default_params() headers = {"Authorization": f"Bearer {self.anthropic_api_key}"} - data = {"prompt": prompt, "stop_sequences": stop, **params} + data = {"prompt": task, "stop_sequences": stop, **params} response = requests.post( f"{self.anthropic_api_url}/completions", headers=headers, @@ -55,12 +63,12 @@ class Anthropic: ) return response.json().get("completion") - def __call__(self, prompt, stop=None): + def __call__(self, task: str, stop=None): """Call out to Anthropic's completion endpoint.""" stop = stop or [] params = self._default_params() headers = {"Authorization": f"Bearer {self.anthropic_api_key}"} - data = {"prompt": prompt, "stop_sequences": stop, **params} + data = {"prompt": task, "stop_sequences": stop, **params} response = requests.post( f"{self.anthropic_api_url}/completions", headers=headers, diff --git a/swarms/workers/worker.py b/swarms/workers/worker.py index 68640ed9..6106bd9f 100644 --- a/swarms/workers/worker.py +++ b/swarms/workers/worker.py @@ -1,21 +1,22 @@ -import random import os +import random from typing import Dict, Union import faiss +from langchain.chains.qa_with_sources.loading import ( + load_qa_with_sources_chain, +) from langchain.docstore import InMemoryDocstore from langchain.embeddings import OpenAIEmbeddings +from langchain.tools import ReadFileTool, WriteFileTool from langchain.tools.human.tool import HumanInputRun from langchain.vectorstores import FAISS from langchain_experimental.autonomous_agents import AutoGPT from swarms.agents.message import Message from swarms.tools.autogpt import ( - ReadFileTool, WebpageQATool, - WriteFileTool, # compile, - load_qa_with_sources_chain, process_csv, ) from swarms.utils.decorators import error_decorator, timing_decorator