Skip to content

Commit 9a996c6

Browse files
committed
temporary made streamlit chatbot
0 parents  commit 9a996c6

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

.streamlit/secrets.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OPENAI_API_KEY = "YOUR_API_KEY"

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# git-bash-streamlit
2+
I'LL MY BEST
3+
<p>Used Tools Visual Studio Code, Sourcetree, Git Bash</p>
4+
<p>Used languages Python</p>
5+
<p>Used libraries openai, streamlit</p>

app.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from openai import OpenAI
2+
import streamlit as st
3+
4+
# Lastest Edited | 2025 may 06th tue pm 04:10 utc+09:00
5+
# X(Twitter) @shininggrail | Discord nerdmecha#1806 | GameJolt @nerdmecha
6+
7+
with st.sidebar:
8+
openai_api_key = st.secrets.get("OPENAI_API_KEY") or st.text_input("OpenAI API Key", key="chatbot_api_key", type="password")
9+
"[Get an OpenAI API key](https://platform.openai.com/account/api-keys)"
10+
"[View the source code](https://github.com/streamlit/llm-examples/blob/main/Chatbot.py)"
11+
"[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/streamlit/llm-examples?quickstart=1)"
12+
13+
st.title("💬 Chatbot")
14+
st.caption("🚀 Powered by OpenAI")
15+
if "messages" not in st.session_state:
16+
st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
17+
18+
for msg in st.session_state.messages:
19+
st.chat_message(msg["role"]).write(msg["content"])
20+
21+
if prompt := st.chat_input():
22+
if not openai_api_key:
23+
st.info("Please add your OpenAI API key to continue.")
24+
st.stop()
25+
26+
client = OpenAI(api_key=openai_api_key)
27+
st.session_state.messages.append({"role": "user", "content": prompt})
28+
st.chat_message("user").write(prompt)
29+
response = client.chat.completions.create(model="gpt-3.5-turbo", messages=st.session_state.messages)
30+
msg = response.choices[0].message.content
31+
st.session_state.messages.append({"role": "assistant", "content": msg})
32+
st.chat_message("assistant").write(msg)

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pip install openai
2+
pip install streamlit

0 commit comments

Comments
 (0)