Spaces:
Running
Running
ryanrwatkins
commited on
Commit
•
96637c9
1
Parent(s):
5e67e09
Update app.py
Browse files
app.py
CHANGED
@@ -85,35 +85,35 @@ def submit_message(prompt, prompt_template, temperature, max_tokens, context_len
|
|
85 |
prompt_msg = { "role": "user", "content": prompt }
|
86 |
|
87 |
|
88 |
-
try:
|
89 |
-
|
90 |
-
with open("embeddings.pkl", 'rb') as f:
|
91 |
-
new_docsearch = pickle.load(f)
|
92 |
-
|
93 |
|
94 |
-
|
|
|
95 |
|
96 |
-
docs = new_docsearch.similarity_search(query)
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
|
106 |
-
|
107 |
|
108 |
|
109 |
|
110 |
-
except Exception as e:
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
|
118 |
total_tokens_used_msg = f"Total tokens used: {state['total_tokens']}"
|
119 |
|
|
|
85 |
prompt_msg = { "role": "user", "content": prompt }
|
86 |
|
87 |
|
88 |
+
#try:
|
|
|
|
|
|
|
|
|
89 |
|
90 |
+
with open("embeddings.pkl", 'rb') as f:
|
91 |
+
new_docsearch = pickle.load(f)
|
92 |
|
|
|
93 |
|
94 |
+
query = str(system_prompt + history + [prompt_msg])
|
95 |
+
|
96 |
+
docs = new_docsearch.similarity_search(query)
|
97 |
+
|
98 |
+
chain = load_qa_chain(ChatOpenAI(temperature=temperature, max_tokens=max_tokens, model_name="gpt-3.5-turbo"), chain_type="stuff")
|
99 |
+
completion = chain.run(input_documents=docs, question=query)
|
100 |
+
completion = { "content": completion.content }
|
101 |
|
102 |
+
|
103 |
+
get_empty_state()
|
104 |
+
state.append(completion.copy())
|
105 |
|
106 |
+
state['total_tokens'] += completion['usage']['total_tokens']
|
107 |
|
108 |
|
109 |
|
110 |
+
#except Exception as e:
|
111 |
+
# history.append(prompt_msg.copy())
|
112 |
+
# error = {
|
113 |
+
# "role": "system",
|
114 |
+
# "content": f"Error: {e}"
|
115 |
+
# }
|
116 |
+
# history.append(error.copy())
|
117 |
|
118 |
total_tokens_used_msg = f"Total tokens used: {state['total_tokens']}"
|
119 |
|