You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/templates/cohere-librarian/cohere_librarian/rag.py

17 lines
441 B
Python

from langchain.retrievers import CohereRagRetriever
from langchain_community.chat_models import ChatCohere
rag = CohereRagRetriever(llm=ChatCohere())
def get_docs_message(message):
docs = rag.get_relevant_documents(message)
message_doc = next(
(x for x in docs if x.metadata.get("type") == "model_response"), None
)
return message_doc.page_content
def librarian_rag(x):
return get_docs_message(x["message"])