Spaces:
Sleeping
Sleeping
File size: 1,088 Bytes
3b55eaf 091f754 3b55eaf 93e434c 3b55eaf 93e434c 3b55eaf 3f1a64b 3b55eaf 1dcabc0 93e434c 1dcabc0 3b55eaf 93e434c 3b55eaf |
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 |
### Q&A Chatbot ###
import os
import streamlit as st
from langchain_openai import ChatOpenAI
from langchain.prompts.chat import ChatPromptTemplate
## Load Anthropic model and get response
def get_openai_response(question):
system_template = "You are a helpful coder assistant. When the user asks a question, your task is to write simple Python codes."
user_template = "{question}"
chat_prompt = ChatPromptTemplate.from_messages([
("system", system_template),
("human", user_template)
])
chat_llm = ChatOpenAI(temperature=0.5)
chain = chat_prompt | chat_llm
return chain.invoke(question).content
## Initialize Streamlit app
st.set_page_config(page_title="Coder Q&A Demo")
st.header("Python Helper")
OPENAI_API_KEY = st.text_input("OpenAI API Key: ", type="password")
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
input = st.text_input("Input: ", key=input)
submit = st.button("Ask your question...")
if submit:
response = get_openai_response(input)
st.subheader("The response is:")
st.write(response) |