Spaces:
Runtime error
Runtime error
reformulation
Browse files
app.py
CHANGED
@@ -15,7 +15,6 @@ from azure.storage.fileshare import ShareServiceClient
|
|
15 |
|
16 |
# from dotenv import load_dotenv
|
17 |
|
18 |
-
|
19 |
# load_dotenv()
|
20 |
|
21 |
theme = gr.themes.Soft(
|
@@ -94,20 +93,18 @@ def chat(
|
|
94 |
stop=["\n---\n", "<|im_end|>"],
|
95 |
)
|
96 |
reformulated_query = reformulated_query["choices"][0]["text"]
|
97 |
-
|
98 |
-
docs = retriever.retrieve(query=reformulated_query, top_k=10)
|
99 |
-
|
100 |
messages = history + [{"role": "user", "content": query}]
|
101 |
-
sources = "\n\n".join(
|
102 |
-
[f"query used for retrieval:\n{reformulated_query}"]
|
103 |
-
+ [
|
104 |
-
f"doc {i}: {d.meta['file_name']} page {d.meta['page_number']}\n{d.content}"
|
105 |
-
for i, d in enumerate(docs, 1)
|
106 |
-
if d.score > threshold
|
107 |
-
]
|
108 |
-
)
|
109 |
|
110 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
messages.append({"role": "system", "content": f"{os.environ['sources']}\n\n{sources}"})
|
112 |
|
113 |
response = openai.Completion.create(
|
|
|
15 |
|
16 |
# from dotenv import load_dotenv
|
17 |
|
|
|
18 |
# load_dotenv()
|
19 |
|
20 |
theme = gr.themes.Soft(
|
|
|
93 |
stop=["\n---\n", "<|im_end|>"],
|
94 |
)
|
95 |
reformulated_query = reformulated_query["choices"][0]["text"]
|
96 |
+
docs = [d for d in retriever.retrieve(query=reformulated_query, top_k=10) if d.score > threshold]
|
|
|
|
|
97 |
messages = history + [{"role": "user", "content": query}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
if docs:
|
100 |
+
sources = "\n\n".join(
|
101 |
+
[f"query used for retrieval:\n{reformulated_query}"]
|
102 |
+
+ [
|
103 |
+
f"doc {i}: {d.meta['file_name']} page {d.meta['page_number']}\n{d.content}"
|
104 |
+
for i, d in enumerate(docs, 1)
|
105 |
+
]
|
106 |
+
)
|
107 |
+
|
108 |
messages.append({"role": "system", "content": f"{os.environ['sources']}\n\n{sources}"})
|
109 |
|
110 |
response = openai.Completion.create(
|