Created
December 1, 2023 15:46
-
-
Save youtube-jocoding/9c924fd2c0e6e7673a04d4fd113cc66f to your computer and use it in GitHub Desktop.
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
from dotenv import load_dotenv | |
import os | |
from openai import OpenAI | |
import streamlit as st | |
load_dotenv() | |
API_KEY = os.environ['OPENAI_API_KEY'] | |
client = OpenAI(api_key=API_KEY) | |
#thread id를 하나로 관리하기 위함 | |
# if 'thread_id' not in st.session_state: | |
# thread = client.beta.threads.create() | |
# st.session_state.thread_id = thread.id | |
# thread_id = st.session_state.thread_id | |
thread_id = "thread_102Ni97l2qcsd09RZYPZkqH3" | |
assistant_id = "asst_WYPrmrww2xZ0jqsRyMyBD6Xu" | |
thread_messages = client.beta.threads.messages.list(thread_id) | |
st.header("현진건 작가님과의 대화") | |
for msg in reversed(thread_messages.data): | |
with st.chat_message(msg.role): | |
st.write(msg.content[0].text.value) | |
prompt = st.chat_input("물어보고 싶은 것을 입력하세요!") | |
if prompt: | |
st.write(f"User has sent the following prompt: {prompt}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment