mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-31 10:23:18 +00:00
community[minor]: Breebs docs retriever (#16578)
- **Description:** Implementation of breeb retriever with integration tests -> libs/community/tests/integration_tests/retrievers/test_breebs.py and documentation (notebook) -> docs/docs/integrations/retrievers/breebs.ipynb. - **Dependencies:** None
This commit is contained in:
@@ -25,6 +25,7 @@ from langchain_community.retrievers.azure_cognitive_search import (
|
||||
)
|
||||
from langchain_community.retrievers.bedrock import AmazonKnowledgeBasesRetriever
|
||||
from langchain_community.retrievers.bm25 import BM25Retriever
|
||||
from langchain_community.retrievers.breebs import BreebsRetriever
|
||||
from langchain_community.retrievers.chaindesk import ChaindeskRetriever
|
||||
from langchain_community.retrievers.chatgpt_plugin_retriever import (
|
||||
ChatGPTPluginRetriever,
|
||||
@@ -78,6 +79,7 @@ __all__ = [
|
||||
"ArceeRetriever",
|
||||
"ArxivRetriever",
|
||||
"AzureCognitiveSearchRetriever",
|
||||
"BreebsRetriever",
|
||||
"ChatGPTPluginRetriever",
|
||||
"ChaindeskRetriever",
|
||||
"CohereRagRetriever",
|
||||
|
49
libs/community/langchain_community/retrievers/breebs.py
Normal file
49
libs/community/langchain_community/retrievers/breebs.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from typing import List
|
||||
|
||||
import requests
|
||||
from langchain_core.callbacks.manager import CallbackManagerForRetrieverRun
|
||||
from langchain_core.documents.base import Document
|
||||
from langchain_core.retrievers import BaseRetriever
|
||||
|
||||
|
||||
class BreebsRetriever(BaseRetriever):
|
||||
"""A retriever class for `Breebs`.
|
||||
|
||||
See https://www.breebs.com/ for more info.
|
||||
Args:
|
||||
breeb_key: The key to trigger the breeb
|
||||
(specialized knowledge pill on a specific topic).
|
||||
|
||||
To retrieve the list of all available Breebs : you can call https://breebs.promptbreeders.com/web/listbreebs
|
||||
"""
|
||||
|
||||
breeb_key: str
|
||||
url = "https://breebs.promptbreeders.com/knowledge"
|
||||
|
||||
def __init__(self, breeb_key: str):
|
||||
super().__init__(breeb_key=breeb_key)
|
||||
self.breeb_key = breeb_key
|
||||
|
||||
def _get_relevant_documents(
|
||||
self, query: str, *, run_manager: CallbackManagerForRetrieverRun
|
||||
) -> List[Document]:
|
||||
"""Retrieve context for given query.
|
||||
Note that for time being there is no score."""
|
||||
r = requests.post(
|
||||
self.url,
|
||||
json={
|
||||
"breeb_key": self.breeb_key,
|
||||
"query": query,
|
||||
},
|
||||
)
|
||||
if r.status_code != 200:
|
||||
return []
|
||||
else:
|
||||
chunks = r.json()
|
||||
return [
|
||||
Document(
|
||||
page_content=chunk["content"],
|
||||
metadata={"source": chunk["source_url"], "score": 1},
|
||||
)
|
||||
for chunk in chunks
|
||||
]
|
Reference in New Issue
Block a user