langchain/templates/cohere-librarian/cohere_librarian/rag.py
ccurme c010ec8b71
patch: deprecate (a)get_relevant_documents (#20477)
- `.get_relevant_documents(query)` -> `.invoke(query)`
- `.get_relevant_documents(query=query)` -> `.invoke(query)`
- `.get_relevant_documents(query, callbacks=callbacks)` ->
`.invoke(query, config={"callbacks": callbacks})`
- `.get_relevant_documents(query, **kwargs)` -> `.invoke(query,
**kwargs)`

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2024-04-22 11:14:53 -04:00

17 lines
425 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.invoke(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"])