Spaces:
Runtime error
Runtime error
app.py
CHANGED
@@ -10,35 +10,30 @@ from utils import (
|
|
10 |
)
|
11 |
|
12 |
system_template = {"role": "system", "content": os.environ["content"]}
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
)
|
17 |
-
document_store = FAISSDocumentStore.load(
|
18 |
index_path="./documents/climate_gpt.faiss",
|
19 |
config_path="./documents/climate_gpt.json",
|
|
|
|
|
|
|
20 |
)
|
21 |
-
|
22 |
-
document_store=
|
|
|
|
|
|
|
23 |
embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
|
24 |
model_format="sentence_transformers",
|
25 |
)
|
26 |
|
27 |
|
28 |
-
def gen_conv(query: str, history=[system_template], report_type="All available", threshold=0.56):
|
29 |
-
""
|
30 |
-
|
31 |
-
Args:
|
32 |
-
query (str): the user message
|
33 |
-
history (list, optional): history of the chat messages. Defaults to [system_template].
|
34 |
-
ipcc (bool, optional): _description_. Defaults to True.
|
35 |
-
|
36 |
-
Returns:
|
37 |
-
_type_: _description_
|
38 |
-
"""
|
39 |
|
40 |
messages = history + [{"role": "user", "content": query}]
|
41 |
-
docs = retriever.retrieve(query=query, top_k=10)
|
42 |
sources = "\n\n".join(
|
43 |
f"doc {i}: {d.meta['file_name']} page {d.meta['page_number']}\n{d.content}"
|
44 |
for i, d in enumerate(docs, 1)
|
|
|
10 |
)
|
11 |
|
12 |
system_template = {"role": "system", "content": os.environ["content"]}
|
13 |
+
|
14 |
+
retrieve_all = EmbeddingRetriever(
|
15 |
+
document_store=FAISSDocumentStore.load(
|
|
|
|
|
16 |
index_path="./documents/climate_gpt.faiss",
|
17 |
config_path="./documents/climate_gpt.json",
|
18 |
+
),
|
19 |
+
embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
|
20 |
+
model_format="sentence_transformers",
|
21 |
)
|
22 |
+
retrieve_giec = EmbeddingRetriever(
|
23 |
+
document_store=FAISSDocumentStore.load(
|
24 |
+
index_path="./documents/climate_gpt_only_giec.faiss",
|
25 |
+
config_path="./documents/climate_gpt_only_giec.json",
|
26 |
+
),
|
27 |
embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
|
28 |
model_format="sentence_transformers",
|
29 |
)
|
30 |
|
31 |
|
32 |
+
def gen_conv(query: str, history: list = [system_template], report_type="All available", threshold=0.56):
|
33 |
+
retriever = retrieve_all if report_type=="All available" else retrieve_giec
|
34 |
+
docs = retriever.retrieve(query=query, top_k=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
messages = history + [{"role": "user", "content": query}]
|
|
|
37 |
sources = "\n\n".join(
|
38 |
f"doc {i}: {d.meta['file_name']} page {d.meta['page_number']}\n{d.content}"
|
39 |
for i, d in enumerate(docs, 1)
|