forked from TransformerOptimus/SuperAGI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring the resource manager structure
- Loading branch information
TransformerOptimus
committed
Jul 2, 2023
1 parent
2587b52
commit 09cf26d
Showing
23 changed files
with
294 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from llama_index.indices.response import ResponseMode | ||
from llama_index.schema import Document | ||
|
||
from superagi.config.config import get_config | ||
|
||
|
||
class LlamaDocumentSummary: | ||
def __init__(self, model_name=get_config("RESOURCES_EMBEDDING_MODEL_NAME", "text-davinci-003")): | ||
self.model_name = model_name | ||
|
||
def generate_summary_of_document(self, documents: list[Document]): | ||
from llama_index import LLMPredictor, ServiceContext, ResponseSynthesizer, DocumentSummaryIndex | ||
|
||
llm_predictor_chatgpt = LLMPredictor(llm=self._build_llm()) | ||
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor_chatgpt, chunk_size=1024) | ||
response_synthesizer = ResponseSynthesizer.from_args(response_mode=ResponseMode.TREE_SUMMARIZE, use_async=True) | ||
doc_summary_index = DocumentSummaryIndex.from_documents( | ||
documents=documents, | ||
service_context=service_context, | ||
response_synthesizer=response_synthesizer | ||
) | ||
|
||
return doc_summary_index.get_document_summary(documents[0].doc_id) | ||
|
||
def generate_summary_of_texts(self, texts: list[str]): | ||
from llama_index import Document | ||
documents = [Document(doc_id=f"doc_id_{i}", text=text) for i, text in enumerate(texts)] | ||
return self.generate_summary_of_document(documents) | ||
|
||
def _build_llm(self): | ||
open_ai_models = ['gpt-4', 'gpt-3.5-turbo', 'gpt-3.5-turbo-16k', 'gpt-4-32k'] | ||
if self.model_name in open_ai_models: | ||
from langchain.chat_models import ChatOpenAI | ||
|
||
openai_api_key = get_config("OPENAI_API_KEY") | ||
return ChatOpenAI(temperature=0, model_name=self.model_name, | ||
openai_api_key=openai_api_key) | ||
|
||
raise Exception(f"Model name {self.model_name} not supported for document summary") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from llama_index.vector_stores.types import VectorStore | ||
|
||
from superagi.config.config import get_config | ||
from superagi.types.vector_store_types import VectorStoreType | ||
|
||
|
||
class LlamaVectorStoreFactory: | ||
def __init__(self, vector_store_name: VectorStoreType, index_name: str): | ||
self.vector_store_name = vector_store_name | ||
self.index_name = index_name | ||
|
||
def get_vector_store(self) -> VectorStore: | ||
if self.vector_store_name == VectorStoreType.PINECONE: | ||
from llama_index.vector_stores import PineconeVectorStore | ||
return PineconeVectorStore(self.index_name) | ||
|
||
if self.vector_store_name == VectorStoreType.REDIS: | ||
redis_url = get_config("REDIS_VECTOR_STORE_URL") or "redis://super__redis:6379" | ||
from llama_index.vector_stores import RedisVectorStore | ||
return RedisVectorStore( | ||
index_name=self.index_name, | ||
redis_url=redis_url, | ||
metadata_fields=["agent_id", "resource_id"] | ||
) | ||
|
||
if self.vector_store_name == VectorStoreType.CHROMA: | ||
from llama_index.vector_stores import ChromaVectorStore | ||
import chromadb | ||
from chromadb.config import Settings | ||
chroma_host_name = get_config("CHROMA_HOST_NAME") or "localhost" | ||
chroma_port = get_config("CHROMA_PORT") or 8000 | ||
chroma_client = chromadb.Client( | ||
Settings(chroma_api_impl="rest", chroma_server_host=chroma_host_name, | ||
chroma_server_http_port=chroma_port)) | ||
chroma_collection = chroma_client.get_or_create_collection(self.index_name) | ||
return ChromaVectorStore(chroma_collection) | ||
|
||
if self.vector_store_name == VectorStoreType.QDRANT: | ||
from llama_index.vector_stores import QdrantVectorStore | ||
qdrant_host_name = get_config("QDRANT_HOST_NAME") or "localhost" | ||
qdrant_port = get_config("QDRANT_PORT") or 6333 | ||
from qdrant_client import QdrantClient | ||
qdrant_client = QdrantClient(host=qdrant_host_name, port=qdrant_port) | ||
return QdrantVectorStore(client=qdrant_client, collection_name=self.index_name) | ||
|
||
raise ValueError(str(self.vector_store_name) + " vector store is not supported yet.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.