File size: 688 Bytes
2376116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from langchain.chains.qa_with_sources.loading import load_qa_with_sources_chain
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.llms import OpenAI

from utils import generate_answer
from utils import get_search_index

open_ai_pkl = "open_ai.pkl"
open_ai_index = "open_ai.index"

gpt_3_5 = OpenAI(model_name='gpt-3.5-turbo',temperature=0)

open_ai_embeddings = OpenAIEmbeddings()

def run(question):

    gpt_3_5_index = get_search_index(open_ai_pkl, open_ai_index, open_ai_embeddings)

    gpt_3_5_chain = load_qa_with_sources_chain(gpt_3_5, chain_type="stuff", verbose=True)

    answer = generate_answer(gpt_3_5_chain, gpt_3_5_index, question)
    return answer