Avo-k commited on
Commit
99e2b1f
1 Parent(s): 669d503
Files changed (1) hide show
  1. app.py +14 -19
app.py CHANGED
@@ -10,35 +10,30 @@ from utils import (
10
  )
11
 
12
  system_template = {"role": "system", "content": os.environ["content"]}
13
- only_ipcc_document_store = FAISSDocumentStore.load(
14
- index_path="./documents/climate_gpt_only_giec.faiss",
15
- config_path="./documents/climate_gpt_only_giec.json",
16
- )
17
- document_store = FAISSDocumentStore.load(
18
  index_path="./documents/climate_gpt.faiss",
19
  config_path="./documents/climate_gpt.json",
 
 
 
20
  )
21
- retriever = EmbeddingRetriever(
22
- document_store=document_store if report_type == "All available" else only_ipcc_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
- """return (answer:str, history:list[dict], sources:str)
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)