diff --git a/examples/rag_pipeline.py b/examples/rag_pipeline.py index ae6e7b7bc..47137c0a4 100644 --- a/examples/rag_pipeline.py +++ b/examples/rag_pipeline.py @@ -1,7 +1,6 @@ """RAG pipeline""" import asyncio -from functools import wraps from pydantic import BaseModel @@ -18,6 +17,7 @@ from metagpt.rag.schema import ( FAISSRetrieverConfig, LLMRankerConfig, ) +from metagpt.utils.exceptions import handle_exception DOC_PATH = EXAMPLE_DATA_PATH / "rag/writer.txt" QUESTION = "What are key qualities to be a good writer?" @@ -28,17 +28,6 @@ TRAVEL_QUESTION = "What does Bob like?" LLM_TIP = "If you not sure, just answer I don't know." -def catch_exception(func): - @wraps(func) - async def wrapper(*args, **kwargs): - try: - return await func(*args, **kwargs) - except Exception as e: - logger.error(f"{func.__name__} exception: {e}") - - return wrapper - - class Player(BaseModel): """To demonstrate rag add objs.""" @@ -122,7 +111,7 @@ class RAGExample: self.engine.add_docs([travel_filepath]) await self.run_pipeline(question=travel_question, print_title=False) - @catch_exception + @handle_exception async def add_objects(self, print_title=True): """This example show how to add objects. @@ -180,21 +169,21 @@ class RAGExample: """ self._print_title("Init And Query ChromaDB") - # 1.save index + # 1. save index output_dir = DATA_PATH / "rag" SimpleEngine.from_docs( input_files=[TRAVEL_DOC_PATH], retriever_configs=[ChromaRetrieverConfig(persist_path=output_dir)], ) - # 2.load index + # 2. load index engine = SimpleEngine.from_index(index_config=ChromaIndexConfig(persist_path=output_dir)) - # 3.query + # 3. query answer = await engine.aquery(TRAVEL_QUESTION) self._print_query_result(answer) - @catch_exception + @handle_exception async def init_and_query_es(self): """This example show how to use es. how to save and load index. will print something like: @@ -205,17 +194,17 @@ class RAGExample: """ self._print_title("Init And Query Elasticsearch") - # 1.create es index and save docs + # 1. create es index and save docs store_config = ElasticsearchStoreConfig(index_name="travel", es_url="http://127.0.0.1:9200") engine = SimpleEngine.from_docs( input_files=[TRAVEL_DOC_PATH], retriever_configs=[ElasticsearchRetrieverConfig(store_config=store_config)], ) - # 2.load index + # 2. load index engine = SimpleEngine.from_index(index_config=ElasticsearchIndexConfig(store_config=store_config)) - # 3.query + # 3. query answer = await engine.aquery(TRAVEL_QUESTION) self._print_query_result(answer) diff --git a/requirements.txt b/requirements.txt index fef56e810..da8aa26b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,16 +10,6 @@ typer==0.9.0 # godot==0.1.1 # google_api_python_client==2.93.0 # Used by search_engine.py lancedb==0.4.0 -llama-index-core==0.10.15 -llama-index-embeddings-azure-openai==0.1.6 -llama-index-embeddings-openai==0.1.5 -llama-index-llms-azure-openai==0.1.4 -llama-index-readers-file==0.1.4 -llama-index-retrievers-bm25==0.1.3 -llama-index-vector-stores-faiss==0.1.1 -llama-index-vector-stores-elasticsearch==0.1.6 -llama-index-postprocessor-colbert-rerank==0.1.1 -chromadb==0.4.23 loguru==0.6.0 meilisearch==0.21.0 numpy==1.24.3 diff --git a/setup.py b/setup.py index f834b4c44..c728872ef 100644 --- a/setup.py +++ b/setup.py @@ -36,6 +36,8 @@ extras_require = { "llama-index-readers-file==0.1.4", "llama-index-retrievers-bm25==0.1.3", "llama-index-vector-stores-faiss==0.1.1", + "llama-index-vector-stores-elasticsearch==0.1.6", + "llama-index-postprocessor-colbert-rerank==0.1.1", "chromadb==0.4.23", ], }