AminFaraji commited on
Commit
5123c13
·
verified ·
1 Parent(s): 6b6a76f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -27,6 +27,40 @@ memory = ConversationBufferWindowMemory(
27
  )
28
 
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  chain = ConversationChain(
31
  llm=llm,
32
 
 
27
  )
28
 
29
 
30
+
31
+
32
+ from langchain import PromptTemplate
33
+ query_text = "when did alice see mad hatter"
34
+
35
+ results = db.similarity_search_with_relevance_scores(query_text, k=3)
36
+ if len(results) == 0 or results[0][1] < 0.5:
37
+ print(f"Unable to find matching results.")
38
+
39
+
40
+ context_text = "\n\n---\n\n".join([doc.page_content for doc, _score in results ])
41
+
42
+ template = """
43
+ The following is a conversation between a human an AI. Answer question based only on the conversation.
44
+
45
+ Current conversation:
46
+ {history}
47
+
48
+ """
49
+
50
+
51
+
52
+ s="""
53
+
54
+ \n question: {input}
55
+
56
+ \n answer:""".strip()
57
+
58
+
59
+ prompt = PromptTemplate(input_variables=["history", "input"], template=template+context_text+'\n'+s)
60
+
61
+
62
+
63
+
64
  chain = ConversationChain(
65
  llm=llm,
66