speech-to-text / database_search.py
MSchell0129
separated files based on function
a76862a
raw
history blame
1.37 kB
from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
from langchain.llms import OpenAI
from api_key import open_ai_key
from speech_to_text import transcribe
llm = OpenAI(temperature=0, openai_api_key='open_ai_key')
#Not sure how the data will be stored, but my idea is that when a question or prompt is asked the audio file will be stored as text which then be fed into the llm
#to then query the database and return the answer.
#estbalish the question to be asked
question = transcribe
# #I feel like I need another step here so that the model takes the question, goes to the db and knows that it needs to look for the answer to the question
# # I am wondering if I need to setup an extraction algorithm here, but then how do I link the extraction algorithm to the database?
# #Creating link to db
# # I am also wondering if there should be an api for the model to call in order to access the database? Thinking that might be more better?
def database(transcribe):
sqlite_db_path = 'sqlite:///database.db'
db = SQLDatabase.from_uri(f'sqlite:///{sqlite_db_path}')
db_chain = SQLDatabaseChain(llm-llm, database=db)
db_results = db_chain.run(transcribe)
return db_results
#After retrieving the data from the database, have llm summarize the data and return the answer to the question
if __name__ == '__main__':
database(transcribe)