Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -39,9 +39,11 @@ def get_reformulation_prompt(query: str) -> str:
|
|
39 |
---
|
40 |
query: La technologie nous sauvera-t-elle ?
|
41 |
standalone question: Can technology help humanity mitigate the effects of climate change?
|
|
|
42 |
---
|
43 |
query: what are our reserves in fossil fuel?
|
44 |
standalone question: What are the current reserves of fossil fuels and how long will they last?
|
|
|
45 |
---
|
46 |
query: {query}
|
47 |
standalone question:"""
|
@@ -122,6 +124,8 @@ def chat(
|
|
122 |
stop=["\n---\n", "<|im_end|>"],
|
123 |
)
|
124 |
reformulated_query = reformulated_query["choices"][0]["text"]
|
|
|
|
|
125 |
docs = [d for d in retriever.retrieve(query=reformulated_query, top_k=10) if d.score > threshold]
|
126 |
messages = history + [{"role": "user", "content": query}]
|
127 |
|
@@ -129,11 +133,11 @@ def chat(
|
|
129 |
sources = "\n\n".join(
|
130 |
[f"query used for retrieval:\n{reformulated_query}"]
|
131 |
+ [
|
132 |
-
f"📃 doc {i}: {d.meta['file_name']} page {d.meta['page_number']}\n{d.content}"
|
133 |
for i, d in enumerate(docs, 1)
|
134 |
]
|
135 |
)
|
136 |
-
messages.append({"role": "system", "content": f"{sources_prompt}\n\n{sources}"})
|
137 |
|
138 |
response = openai.Completion.create(
|
139 |
engine="climateGPT",
|
|
|
39 |
---
|
40 |
query: La technologie nous sauvera-t-elle ?
|
41 |
standalone question: Can technology help humanity mitigate the effects of climate change?
|
42 |
+
language: French
|
43 |
---
|
44 |
query: what are our reserves in fossil fuel?
|
45 |
standalone question: What are the current reserves of fossil fuels and how long will they last?
|
46 |
+
language: English
|
47 |
---
|
48 |
query: {query}
|
49 |
standalone question:"""
|
|
|
124 |
stop=["\n---\n", "<|im_end|>"],
|
125 |
)
|
126 |
reformulated_query = reformulated_query["choices"][0]["text"]
|
127 |
+
reformulated_query,language = reformulated_query.split("\n")
|
128 |
+
language = language.split(":")[1].strip()
|
129 |
docs = [d for d in retriever.retrieve(query=reformulated_query, top_k=10) if d.score > threshold]
|
130 |
messages = history + [{"role": "user", "content": query}]
|
131 |
|
|
|
133 |
sources = "\n\n".join(
|
134 |
[f"query used for retrieval:\n{reformulated_query}"]
|
135 |
+ [
|
136 |
+
f"📃 doc {i}: {d.meta['file_name']} page {d.meta['page_number']}\n{d.content.replace("\r\n","")}"
|
137 |
for i, d in enumerate(docs, 1)
|
138 |
]
|
139 |
)
|
140 |
+
messages.append({"role": "system", "content": f"{sources_prompt}\n\n{sources}\n\nAnswer in {language}:"})
|
141 |
|
142 |
response = openai.Completion.create(
|
143 |
engine="climateGPT",
|