mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
c010ec8b71
- `.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>
17 lines
425 B
Python
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"])
|