mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-03 12:52:37 +02:00
fix by cr
This commit is contained in:
parent
d7968fdc20
commit
8d98ce34e5
3 changed files with 11 additions and 30 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
2
setup.py
2
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",
|
||||
],
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue