Update chat.py
Browse files
chat.py
CHANGED
@@ -82,9 +82,21 @@ retriever = vectorstore_persisted.as_retriever(
|
|
82 |
)
|
83 |
|
84 |
|
85 |
-
def make_completion(
|
86 |
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
try:
|
90 |
|
@@ -107,28 +119,13 @@ def predict(input, history):
|
|
107 |
Predict the response of the chatbot and complete a running list of chat history.
|
108 |
"""
|
109 |
|
110 |
-
|
111 |
-
context_list = [d.page_content for d in relevant_document_chunks]
|
112 |
-
context_for_query = "\n".join(context_list)
|
113 |
-
|
114 |
-
user_message = {
|
115 |
-
'role': 'user',
|
116 |
-
'content': qna_user_message_template.format(
|
117 |
-
context=context_for_query,
|
118 |
-
question=input
|
119 |
-
)
|
120 |
-
}
|
121 |
-
|
122 |
-
history.append(user_message)
|
123 |
-
|
124 |
-
response = make_completion(history)
|
125 |
|
|
|
126 |
history.append({"role": "assistant", "content": response})
|
127 |
|
128 |
-
# Extract only the user question from the input
|
129 |
-
|
130 |
messages = [
|
131 |
-
(history[i]["content"]
|
132 |
for i in range(0, len(history)-1, 2)
|
133 |
]
|
134 |
|
|
|
82 |
)
|
83 |
|
84 |
|
85 |
+
def make_completion(input:str, history: List[Message]) -> Optional[str]:
|
86 |
|
87 |
+
relevant_document_chunks = retriever.invoke(input)
|
88 |
+
context_list = [d.page_content for d in relevant_document_chunks]
|
89 |
+
context_for_query = "\n".join(context_list)
|
90 |
+
|
91 |
+
user_message = [{
|
92 |
+
'role': 'user',
|
93 |
+
'content': qna_user_message_template.format(
|
94 |
+
context=context_for_query,
|
95 |
+
question=input
|
96 |
+
)
|
97 |
+
}]
|
98 |
+
|
99 |
+
prompt = [{'role':'system', 'content': qna_system_message}] + history + user_message
|
100 |
|
101 |
try:
|
102 |
|
|
|
119 |
Predict the response of the chatbot and complete a running list of chat history.
|
120 |
"""
|
121 |
|
122 |
+
response = make_completion(input, history)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
+
history.append({"role": "user", "content": input})
|
125 |
history.append({"role": "assistant", "content": response})
|
126 |
|
|
|
|
|
127 |
messages = [
|
128 |
+
(history[i]["content"], history[i+1]["content"])
|
129 |
for i in range(0, len(history)-1, 2)
|
130 |
]
|
131 |
|