forked from i-am-alice/2nd-devs
-
Notifications
You must be signed in to change notification settings - Fork 3
/
29.py
25 lines (20 loc) · 960 Bytes
/
29.py
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
from langchain.schema import HumanMessage, SystemMessage
from langchain_openai import ChatOpenAI
from helpers import get_vector_store
query = "Write a summary of the games by AI_Devs."
# --------------------------------------------------------------
# Get related documents by similarity search
# --------------------------------------------------------------
vector_store = get_vector_store()
context = vector_store.similarity_search_with_score(query, k=1)
context_document, context_score = context[0] #Extract 1st document and its score
chat = ChatOpenAI()
response = chat.invoke([
SystemMessage(f"""
Assign the task provided by the user to the person who is most likely to complete it based on the context and nothing else.
Return the lowercase name or "general" if you can't find a match.
context###${context_document.page_content if context else ''}###
"""),
HumanMessage(query),
])
print("Notify:", response.content)