-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoreherence_rag.py
More file actions
31 lines (22 loc) · 797 Bytes
/
Copy pathcoreherence_rag.py
File metadata and controls
31 lines (22 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from langchain.chat_models import ChatCohere
from langchain.retrievers import CohereRagRetriever
from langchain.schema.document import Document
from preparing_ds import data
content = []
for i in range(len(data[0]['profile'])):
content.append(data[0]['profile'][i]['text'])
documents = [Document(page_content=text) for text in content]
rag = CohereRagRetriever(llm=ChatCohere())
query = (data[0]['input'])
index_of_query= (data[0]['input']).find("article:")
query = (data[0]['input'])[index_of_query + len("article:"):].strip()
docs = rag.get_relevant_documents(
query,
source_documents=documents
)
def _pretty_print(docs):
for doc in docs:
print(doc.metadata)
print("\n\n" + doc.page_content)
print("\n\n" + "-" * 30 + "\n\n")
_pretty_print(docs)