File size: 911 Bytes
a76862a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 langchain.chains.summarize import load_summarize_chain
from langchain.text_splitter import RecursiveCharacterTextSplitter
from api_key import open_ai_key
import openai
from database_search import database
llm = openai(temperature=0, openai_api_key='open_ai_key')

def model_response(database):
    with open(database) as file:
        text = file.read()


    text_splitter = RecursiveCharacterTextSplitter(separators = ['\n\n', '\n'], chunk_size = 100, chunk_overlap = 0)
    docs = text_splitter.create_documents([text])

    chain = load_summarize_chain(llm=llm, chain_type = 'map_reduce')

    output = chain.run(docs)

    #Setup for the model to recevie a question and return the answer
    context = output


    answer = llm(context)
    #Next part is to take the saved docx file and convert it to an audio file to be played back to the user

if __name__ == '__main__':
    model_response(database)