crewAIInc / crewAI-examples

2.63k stars 977 forks source link

Inserting in ChromaDB ERROR #67

Closed saibhaskerraju closed 6 months ago

saibhaskerraju commented 6 months ago

Hello Team,

I recently started using CrewAI and my task is to read contents on various PDFs for a particular query and later generate a summary of it.

I am using the code from here : https://docs.crewai.com/core-concepts/Tools/#using-crewai-tools . however, my code has ONE agent with two tools i.e. DirectoryReadTool and PDFSearchTool

writer = Agent( role='Content Writer', goal='Write amazing, super engaging blog post about BMW', backstory='A skilled writer with a passion for Automobiles/cars/vechiles.', tools=[docs_tools, pdf_search_tool], verbose=True, llm=azure_llm )

when I try to run the program. this is the output I see

image

The program generates a summary as instructed but i see this error. Can someone please suggest me what to do ?

Python : 3.11 Host : Docker Libraries : latest version of crewai and crewai[tools]

saibhaskerraju commented 6 months ago

I changed the embeddings to Azure OpenAI and it solved my issue

kaushalpowar commented 5 months ago

I changed the embeddings to Azure OpenAI and it solved my issue

Can you please share how did you change the embeddings from chroma to Azure OpenAI. I am facing the same issue with GithubSearchTool

saibhaskerraju commented 5 months ago

Hey @kaushalpowar, I think the new version of crewai gives you the flexibility to change the embedding and LLM via a configuration. please check the latest docs. in case, you can change for some reason, this is what i did.

navigate to this file : lib/python3.11/site-packages/embedchain/embedder/openai.py

replace the content with the below

`import os from typing import Optional from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction from langchain_openai import AzureOpenAIEmbeddings from embedchain.config import BaseEmbedderConfig from embedchain.embedder.base import BaseEmbedder from embedchain.models import VectorDimensions

class OpenAIEmbedder(BaseEmbedder): def init(self, config: Optional[BaseEmbedderConfig] = None): super().init(config=config) embeddings = AzureOpenAIEmbeddings( azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"), api_key=os.environ.get("AZURE_OPENAI_KEY"), azure_deployment=os.environ.get("AZURE_OPENAI_DEPLOYMENT_EMBEDDING") ) embedding_fn = BaseEmbedder._langchain_default_concept(embeddings) self.set_embedding_fn(embedding_fn=embedding_fn) vector_dimension = self.config.vector_dimension or VectorDimensions.OPENAI.value self.set_vector_dimension(vector_dimension=vector_dimension) `

kaushalpowar commented 5 months ago

Hey @kaushalpowar, I think the new version of crewai gives you the flexibility to change the embedding and LLM via a configuration. please check the latest docs. in case, you can change for some reason, this is what i did.

navigate to this file : lib/python3.11/site-packages/embedchain/embedder/openai.py

replace the content with the below

`import os from typing import Optional from chromadb.utils.embedding_functions import OpenAIEmbeddingFunction from langchain_openai import AzureOpenAIEmbeddings from embedchain.config import BaseEmbedderConfig from embedchain.embedder.base import BaseEmbedder from embedchain.models import VectorDimensions

class OpenAIEmbedder(BaseEmbedder): def init(self, config: Optional[BaseEmbedderConfig] = None): super().init(config=config) embeddings = AzureOpenAIEmbeddings( azure_endpoint=os.environ.get("AZURE_OPENAI_ENDPOINT"), api_key=os.environ.get("AZURE_OPENAI_KEY"), azure_deployment=os.environ.get("AZURE_OPENAI_DEPLOYMENT_EMBEDDING") ) embedding_fn = BaseEmbedder._langchain_default_concept(embeddings) self.set_embedding_fn(embedding_fn=embedding_fn) vector_dimension = self.config.vector_dimension or VectorDimensions.OPENAI.value self.set_vector_dimension(vector_dimension=vector_dimension) `

Thank you