File size: 665 Bytes
407c075
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from dotenv import load_dotenv

load_dotenv()

import os

from . import make_docs
from .chainrunner import *
from .docstore import *


def get_runner(regenerate=False):
  from pathlib import Path
  filename = Path(FaissDocumentStore.filename).resolve()

  if regenerate or not os.path.exists(filename):
      texts, metadatas = make_docs.produce_documents()
      docsearch = FaissDocumentStore.from_texts(texts, metadatas)
      docsearch.to_pickle()
  else:
      docsearch = FaissDocumentStore.from_pickle()

  chain = StuffChain({"model_name": "text-davinci-003", "temperature": 0.0})

  query_runner = StuffChainRunner(chain, docsearch)

  return query_runner