plantuml-agent / src /retriever_tool.py
savi8sant8s's picture
Finished initial app
f6662f9
raw
history blame
866 Bytes
from langchain_community.retrievers import BM25Retriever
from smolagents import Tool
class RetrieverTool(Tool):
name = "retriever"
description = "Retrieves relevant chunks from the PlantUML reference guide."
inputs = {
"query": {
"type": "string",
"description": "The information to search for in the PlantUML documentation.",
}
}
output_type = "string"
def __init__(self, docs, **kwargs):
super().__init__(**kwargs)
self.retriever = BM25Retriever.from_documents(docs, k=10)
def forward(self, query: str) -> str:
assert isinstance(query, str), "Query must be a string"
docs = self.retriever.invoke(query)
return "\nRetrieved documents:\n" + "".join(
[f"\n\n===== Document {i} =====\n{doc.page_content}" for i, doc in enumerate(docs)]
)