Spaces:
Sleeping
Sleeping
File size: 1,086 Bytes
cd9da6c | 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # Q&A Chatbot
import openai
from dotenv import load_dotenv
import streamlit as st
import os
# Load the enviroment variables from .env file
load_dotenv()
# Set the API key from environment variable
openai.api_key = os.getenv("OPENAI_API_KEY")
# Function to load OpenAI model to get response
def get_openai_response(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # You can change this to gpt-4 if you prefer
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
)
# Return the assistant's reply
return response['choices'][0]['message']['content']
# Initialize streamlit page
st.set_page_config(page_title="Q&A Chatbot")
st.header("Langchain Application")
input= st.text_input("Enter your prompt:")
submit=st.button("Submit")
# If button is clicked, get and display the response
if submit:
response = get_openai_response(input)
st.subheader("Response")
st.write(response)
|