speech-to-text / model_response.py
MSchell0129
separated files based on function
a76862a
raw
history blame
911 Bytes
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)