Created
February 12, 2024 16:40
-
-
Save AtriSaxena/af87c33781c5d66df8a2d7b76fd2654f to your computer and use it in GitHub Desktop.
Langchain Finance OpenAI Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Author - Atri Saxena | |
#Email - atrisaxena2@gmail.com | |
#Q&A Finance Chatbot | |
from langchain_community.llms import OpenAI | |
from dotenv import load_dotenv | |
import streamlit as st | |
from langchain import PromptTemplate | |
from langchain.llms import OpenAI | |
from langchain.chains import LLMChain | |
load_dotenv() #Load .env file | |
import os | |
##load OpenAI model | |
llm = OpenAI(openai_api_key = os.getenv('OPENAI_API_KEY'), temperature = 0.5) | |
#Demo template. Instruct to act as financial advisor | |
demo_template = '''I want to you to act as an financial advisor to the peoples. | |
Explain {financial_concept}''' | |
#Prompt Template to take input variable | |
prompt = PromptTemplate( | |
input_variables = ['financial_concept'], | |
template = demo_template | |
) | |
prompt.format(financial_concept = 'income tax') #Format of data example | |
#Chaining to run llm using prompt template | |
chain = LLMChain(llm=llm, prompt=prompt) | |
def get_openai_response(question): | |
response = chain.run('Income tax') | |
return response | |
# Initialize our steamlit app | |
st.set_page_config(page_title="Q&A Demo") | |
st.header("OpenAI Financial Advisor Bot") | |
#Getting input | |
input = st.text_input("Input: ", key= "input") | |
response = get_openai_response(input) | |
submit = st.button("Ask the Question") | |
# If submit is clicked | |
if submit: | |
st.subheader("The Response is:") | |
st.write(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment