Skip to content

update all #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 155 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
c288618
240416
hyeeee14 Apr 16, 2024
7b70555
240416
hyeeee14 Apr 16, 2024
c2ae5ec
240416
hyeeee14 Apr 16, 2024
878ebbd
240416
hyeeee14 Apr 16, 2024
267d593
240416
hyeeee14 Apr 16, 2024
673d8c7
240416
hyeeee14 Apr 16, 2024
67754d9
240416
hyeeee14 Apr 16, 2024
f22247e
240416
hyeeee14 Apr 16, 2024
3f3ad93
240416
hyeeee14 Apr 17, 2024
154e401
240417
hyeeee14 Apr 17, 2024
727eb68
240418
hyeeee14 Apr 17, 2024
9b70d28
240418
hyeeee14 Apr 17, 2024
2942b69
240418
hyeeee14 Apr 17, 2024
379917a
240418
hyeeee14 Apr 17, 2024
3154606
240418
hyeeee14 Apr 17, 2024
febb9bd
240418
hyeeee14 Apr 17, 2024
946b920
240418
hyeeee14 Apr 18, 2024
0d724e5
240418
hyeeee14 Apr 18, 2024
f457b37
240418
hyeeee14 Apr 18, 2024
b363d2b
240419
hyeeee14 Apr 19, 2024
73d3169
240424
hyeeee14 Apr 24, 2024
7a15eb8
240424
hyeeee14 Apr 24, 2024
0d2d47f
240424
hyeeee14 Apr 24, 2024
3826682
240424
hyeeee14 Apr 24, 2024
3b0e610
240424
hyeeee14 Apr 24, 2024
15dba00
240424
hyeeee14 Apr 24, 2024
c783a8a
240424
hyeeee14 Apr 24, 2024
32fd9be
240425
hyeeee14 Apr 25, 2024
6916e17
240425
hyeeee14 Apr 25, 2024
efc6ba6
240425
hyeeee14 Apr 25, 2024
c39becd
240425
hyeeee14 Apr 25, 2024
a421632
240425
hyeeee14 Apr 25, 2024
b15cc5c
240425
hyeeee14 Apr 25, 2024
52b1dca
240425
hyeeee14 Apr 25, 2024
534ed7b
240425
hyeeee14 Apr 25, 2024
3948fd2
240425
hyeeee14 Apr 25, 2024
8c6c9c9
240425
hyeeee14 Apr 25, 2024
d4148cd
240425
hyeeee14 Apr 25, 2024
0819800
240425
hyeeee14 Apr 25, 2024
3ef1ea9
240425
hyeeee14 Apr 25, 2024
590e4a6
240425
hyeeee14 Apr 25, 2024
2773dc2
240425
hyeeee14 Apr 25, 2024
e752e11
240425
hyeeee14 Apr 25, 2024
bf24316
240425
hyeeee14 Apr 25, 2024
915fffa
240425
hyeeee14 Apr 25, 2024
12a412e
240425
hyeeee14 Apr 25, 2024
9227460
240425
hyeeee14 Apr 25, 2024
272ca08
240425
hyeeee14 Apr 25, 2024
5fb6c15
240426
hyeeee14 Apr 26, 2024
91479fc
240426
hyeeee14 Apr 26, 2024
56390d6
240426
hyeeee14 Apr 26, 2024
494007f
240426
hyeeee14 Apr 26, 2024
8970fe4
240426
hyeeee14 Apr 26, 2024
e138315
240426
hyeeee14 Apr 26, 2024
93bcd97
240426
hyeeee14 Apr 26, 2024
8041f41
240426
hyeeee14 Apr 26, 2024
473d39a
240426
hyeeee14 Apr 26, 2024
0844d9a
240426
hyeeee14 Apr 26, 2024
eb1f1f7
240426
hyeeee14 Apr 26, 2024
130b1d2
240426
hyeeee14 Apr 26, 2024
9b570d6
240426
hyeeee14 Apr 26, 2024
6a37735
240426
hyeeee14 Apr 26, 2024
59bb023
240426
hyeeee14 Apr 26, 2024
d7e6027
240426
hyeeee14 Apr 26, 2024
4a4781c
log
hyeeee14 Apr 26, 2024
7742d3a
240426
hyeeee14 Apr 26, 2024
5002ff7
240426
hyeeee14 Apr 26, 2024
5cf7aee
240426
hyeeee14 Apr 26, 2024
519d268
240426
hyeeee14 Apr 26, 2024
45f7be6
240426
hyeeee14 Apr 26, 2024
9a6b64e
240426
hyeeee14 Apr 26, 2024
d3d32d6
240426
hyeeee14 Apr 26, 2024
f4e6f0a
240426
hyeeee14 Apr 26, 2024
578244d
240429
hyeeee14 Apr 29, 2024
bdd29ab
240429
hyeeee14 Apr 30, 2024
80ae929
240430
hyeeee14 Apr 30, 2024
3d17283
240430
hyeeee14 Apr 30, 2024
b117b9a
240430
hyeeee14 Apr 30, 2024
4f9bebb
240430
hyeeee14 Apr 30, 2024
7b8c67e
240430
hyeeee14 Apr 30, 2024
633aaa8
240430
hyeeee14 Apr 30, 2024
3586659
240430
hyeeee14 Apr 30, 2024
499e878
240430
hyeeee14 Apr 30, 2024
09104b5
240430
hyeeee14 Apr 30, 2024
8e3486f
240430
hyeeee14 Apr 30, 2024
15e6f8e
Merge branch 'main' of https://github.com/hyeeee14/llm-examples
hyeeee14 Apr 30, 2024
95a820c
240501
hyeeee14 May 1, 2024
abc658c
240501
hyeeee14 May 1, 2024
c465758
240501
hyeeee14 May 1, 2024
f14f331
240501
hyeeee14 May 1, 2024
a363fc3
240610
hyeeee14 Jun 9, 2024
6972650
240610
hyeeee14 Jun 9, 2024
baff541
240610 ctrl+k+c
hyeeee14 Jun 9, 2024
7c947e3
240704
hyeeee14 Jul 4, 2024
21c8950
241209
hyeeee14 Dec 9, 2024
a6f0eb6
Merge branch 'main' of https://github.com/hyeeee14/llm-examples
hyeeee14 Dec 9, 2024
391e616
241209
hyeeee14 Dec 9, 2024
5d2aec7
241209
hyeeee14 Dec 9, 2024
c43e703
241209
hyeeee14 Dec 9, 2024
65a8e84
241209
hyeeee14 Dec 9, 2024
397fdae
241209
hyeeee14 Dec 9, 2024
c3b1926
241209
hyeeee14 Dec 9, 2024
9036278
241209
hyeeee14 Dec 9, 2024
24ae2a3
241209
hyeeee14 Dec 9, 2024
736604d
241209
hyeeee14 Dec 9, 2024
f08be2d
241209
hyeeee14 Dec 9, 2024
5c5d7f2
Merge branch 'main' of https://github.com/hyeeee14/llm-examples
hyeeee14 Dec 9, 2024
6117c1e
241209
hyeeee14 Dec 9, 2024
632d33c
241209
hyeeee14 Dec 9, 2024
d42000b
241209
hyeeee14 Dec 9, 2024
fdf6e9b
241213 sidebar collapsed
hyeeee14 Dec 13, 2024
3f2750d
Merge branch 'main' of https://github.com/hyeeee14/llm-examples
hyeeee14 Dec 13, 2024
15af4bb
241213 sidebar collapsed
hyeeee14 Dec 13, 2024
0a2e73d
Update README.md
hyeeee14 Dec 13, 2024
d601c5a
Update README.md
hyeeee14 Dec 13, 2024
60ddbce
Update README.md
hyeeee14 Dec 13, 2024
f7a6672
Update README.md
hyeeee14 Dec 13, 2024
3cc7214
Update README.md
hyeeee14 Dec 13, 2024
4566026
Update README.md
hyeeee14 Dec 13, 2024
95e2c8f
250127 error 제거
hyeeee14 Jan 27, 2025
71456ab
250127 오류 제거
hyeeee14 Jan 27, 2025
22748d9
S와 N 챗봇
hyeeee14 Jan 31, 2025
2c3e38a
chatbot 순서
hyeeee14 Jan 31, 2025
19a3d5c
chatbot
hyeeee14 Jan 31, 2025
21a6ea9
250131
hyeeee14 Jan 31, 2025
b38294a
sqlite3>=3.35.0
hyeeee14 Jan 31, 2025
4d9fbfd
sqlite는 pip으로 설치불가능..지워
hyeeee14 Jan 31, 2025
5c98962
chatbot 선택
hyeeee14 Jan 31, 2025
98394cf
langchain_chroma
hyeeee14 Jan 31, 2025
52b9303
chromadb
hyeeee14 Jan 31, 2025
769e8e4
chromadb==0.3.29
hyeeee14 Jan 31, 2025
ee62dbe
__init__.py
hyeeee14 Jan 31, 2025
c64344e
langchain.vectorstores
hyeeee14 Jan 31, 2025
25e19de
250131
hyeeee14 Jan 31, 2025
1658310
radio button
hyeeee14 Jan 31, 2025
2b5bd7a
Add files via upload
hyeeee14 Jan 31, 2025
9454663
Update README.md
hyeeee14 Jan 31, 2025
747f737
S,N
hyeeee14 Jan 31, 2025
19a6269
RAG senior
hyeeee14 Jan 31, 2025
adcdef2
250131
hyeeee14 Jan 31, 2025
00c7e8d
250131
hyeeee14 Jan 31, 2025
e519bb9
250131
hyeeee14 Jan 31, 2025
cf1146c
250131 index=none
hyeeee14 Jan 31, 2025
6c122e5
250131
hyeeee14 Jan 31, 2025
8f7f6e6
button
hyeeee14 Jan 31, 2025
279036b
h3, h1
hyeeee14 Jan 31, 2025
a2a2e8d
🤖
hyeeee14 Jan 31, 2025
4f0347f
set_page
hyeeee14 Jan 31, 2025
666b17d
Add files via upload
hyeeee14 Jan 31, 2025
0d5627c
Delete seniorinterviewdata_output.txt
hyeeee14 Jan 31, 2025
b8d5b04
Add files via upload
hyeeee14 Jan 31, 2025
52a9dd1
update all
hyeeee14 Feb 9, 2025
5182293
Update 1_Chatbot-S.py
hyeeee14 Feb 17, 2025
3f35919
Create config.py
hyeeee14 Feb 17, 2025
672d997
Update 1_Chatbot-S.py
hyeeee14 Feb 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions Chatbot.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
from openai import OpenAI
import streamlit as st

with st.sidebar:
openai_api_key = st.text_input("OpenAI API Key", key="chatbot_api_key", type="password")
"[Get an OpenAI API key](https://platform.openai.com/account/api-keys)"
"[View the source code](https://github.com/streamlit/llm-examples/blob/main/Chatbot.py)"
"[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/streamlit/llm-examples?quickstart=1)"
# Chatbot.py

st.title("💬 Chatbot")
st.caption("🚀 A streamlit chatbot powered by OpenAI LLM")
if "messages" not in st.session_state:
st.session_state["messages"] = [{"role": "assistant", "content": "How can I help you?"}]
import streamlit as st

for msg in st.session_state.messages:
st.chat_message(msg["role"]).write(msg["content"])
st.set_page_config(
page_title="Choose a chatbot💬",
page_icon="✅",
layout="centered",
initial_sidebar_state="collapsed" # 'collapsed'로 설정하면 사이드바 접힌 상태로 시작
)

if prompt := st.chat_input():
if not openai_api_key:
st.info("Please add your OpenAI API key to continue.")
st.stop()
st.markdown("실험에 참여해주셔서 감사합니다!📝")
st.caption("챗봇🤖을 골라주세요.")

client = OpenAI(api_key=openai_api_key)
st.session_state.messages.append({"role": "user", "content": prompt})
st.chat_message("user").write(prompt)
response = client.chat.completions.create(model="gpt-3.5-turbo", messages=st.session_state.messages)
msg = response.choices[0].message.content
st.session_state.messages.append({"role": "assistant", "content": msg})
st.chat_message("assistant").write(msg)
if st.button("Chatbot-S"):
st.switch_page("pages/1_Chatbot-S.py")
if st.button("Chatbot-N"):
st.switch_page("pages/2_Chatbot-N.py")
Binary file added Chatbot.zip
Binary file not shown.
40 changes: 4 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,12 @@
# 🎈 Streamlit + LLM Examples App

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/streamlit/llm-examples?quickstart=1)

Starter examples for building LLM apps with Streamlit.
# 🎈 Streamlit + LLM App <Career Counseling Chatbot>

## Overview of the App

This app showcases a growing collection of LLM minimum working examples.

Current examples include:

- Chatbot
- File Q&A
- Chat with Internet search
- LangChain Quickstart
- LangChain PromptTemplate
- Chat with user feedback

## Demo App

[![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_white.svg)](https://llm-examples.streamlit.app/)

### Get an OpenAI API key
- Chatbot: AI Career Counselor Conversational Assistant

You can get your own OpenAI API key by following the following instructions:
## Go to experience the app!

1. Go to https://platform.openai.com/account/api-keys.
2. Click on the `+ Create new secret key` button.
3. Next, enter an identifier name (optional) and click on the `Create secret key` button.

### Enter the OpenAI API key in Streamlit Community Cloud

To set the OpenAI API key as an environment variable in Streamlit apps, do the following:

1. At the lower right corner, click on `< Manage app` then click on the vertical "..." followed by clicking on `Settings`.
2. This brings the **App settings**, next click on the `Secrets` tab and paste the API key into the text box as follows:

```sh
OPENAI_API_KEY='xxxxxxxxxx'
```
[Career Counseling Chatbot App](https://llm-based-career-counseling-chatbot.streamlit.app/)

## Run it locally

Expand Down
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import streamlit as st
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file added career_saramin/chroma.sqlite3
Binary file not shown.
Empty file added chat_log.csv
Empty file.
221 changes: 221 additions & 0 deletions pages/1_Chatbot-S.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
import streamlit as st
import os, json, chardet, openai
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_community.utilities.tavily_search import TavilySearchAPIWrapper
from langchain_core.tools import tool
from langchain.memory import ConversationSummaryBufferMemory
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from langchain_community.vectorstores import Chroma

# ----------------------------------------------------------------------------------------------------
# streamlit
# ----------------------------------------------------------------------------------------------------

st.set_page_config(
page_title="Career Counseling Chatbot-S💬",
page_icon="💬",
layout="wide",
initial_sidebar_state="collapsed" # 'collapsed'로 설정하면 사이드바 접힌 상태로 시작
)

st.title("Career Counseling Chatbot-S💬")
st.markdown('진로 결정 어려움을 해결하여 진로 결정을 잘할 수 있도록 도와주는 AI 진로 상담사')
st.caption("🚀 AI Career Counselor Conversational Assistant produced by Hyerim")


OPENAI_API_KEY = st.secrets['OPENAI_API_KEY']
OPENAI_ORGANIZATION = st.secrets['OPENAI_ORGANIZATION']

# 임베딩 함수 설정
embedding = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)

#----------------------------------------------------------------------------------------------------
# function calling
# ----------------------------------------------------------------------------------------------------
# 현재 작업 디렉토리 가져오기
current_directory = os.getcwd()

# 안전한 경로 설정 (배포 환경에서도 유지됨)
persist_dir = os.path.join(current_directory, "career_saramin")

@tool
def SearchCareerInfo(query):
"""Get the current carrer_info in a given url"""
career_info = None
tavily_search = TavilySearchAPIWrapper(tavily_api_key=st.secrets['TAVILY_API'])
# 쿼리 작성
url = "https://www.work.go.kr/consltJobCarpa/srch/getExpTheme.do?jobClcd=D&pageIndex=1&pageUnit=10"

# TavilySearchAPIWrapper를 이용하여 검색 결과 가져오기
search_results = TavilySearchResults(max_results=5, tavily_api_key=st.secrets['TAVILY_API']).invoke(query)
career_info = {
"name": career_info,
"query": query,
"career_info": search_results,
}
return json.dumps(career_info)

@tool
def SearchSeniorInfo(query):
"""Get the current Senior_info in RAG"""
senior_info = None
embedding = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)
# load from disk (save 이후)

try:
vector = Chroma(persist_directory=persist_dir, embedding_function=embedding, collection_name="career_saramin")
print("ChromaDB 문서 개수:", vector._collection.count())
except Exception as e:
print("Error Loading ChromaDB:", e)
# ✅ RAG 기반 검색 수행
search_results = vector.similarity_search(query, k=3) # 🔥 상위 1개 문서 검색
# page_content만 리스트로 추출
page_contents = [doc.page_content for doc in search_results]

senior_info = {
"name": "senior_info",
"query": query,
"careersenior_info": page_contents,
}
return senior_info

tools = [
{
"name": "SearchCareerInfo",
"description": "A tool that search the information needed to generate job information according to the prompt based on the given URL.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search query to look for specific Career information."
},
# "career_info": {
# "type": "string",
# "description": "Career information Retrieved by query."
# }
},
# "required": ["query", "career_info"]
"required": ["query"]
},
},
{
"name": "SearchSeniorInfo",
"description": "A retrieval-augmented tool that searches senior career insights based on past interviews and expert testimonials. This tool utilizes ChromaDB and OpenAI Embeddings to find the most relevant career growth strategies, job challenges, and expert advice.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search query to look for specific Senior based Career information."
},
},
"required": ["query"]
},
}
]
#----------------------------------------------------------------------------------------------------
# Prompt Template
# ----------------------------------------------------------------------------------------------------


# ----------------------------------------------------------------------------------------------------
# RAG
#-----------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------
# Session State
#----------------------------------------------------------------------------------------------------


llm = ChatOpenAI(model_name="gpt-4o",
temperature=0.5,
openai_api_key=OPENAI_API_KEY,
organization=OPENAI_ORGANIZATION)

#llm.bind_tools(tools=[SearchCareerInfo, SearchSeniorInfo])
# tool_choice=[SearchCareerInfo]

# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = [
{"role": "system", "content": st.secrets["system_prompt_S"]},
{"role": "assistant", "content": "안녕하세요! 저는 오늘 당신과 함께 진로 고민에 대해 이야기 나눠볼 AI 진로 상담사입니다.😊 제가 어떻게 불러주면 좋을까요?"}
]
if "memory" not in st.session_state:
st.session_state.memory = ConversationSummaryBufferMemory(
llm=llm,
max_token_limit=1000, # 요약의 기준이 되는 토큰 길이를 설정합니다.
return_messages=True,
)

# Display chat messages from history on app rerun
for message in st.session_state.messages:
if message["role"]=='system':
continue
st.chat_message(message["role"]).write(message["content"])
print(message)

if user_input := st.chat_input():
#Add user message to chat history
st.session_state.messages.append({"role": "user", "content": user_input})
st.chat_message("user").write(user_input)

with st.spinner('Please wait...'):
response = openai.chat.completions.create(
model="gpt-4o",
messages=st.session_state.messages,
functions=tools,
function_call="auto"
)
response_message = response.choices[0].message
if response_message.function_call:
function_name = response_message.function_call.name
function_args = json.loads(response_message.function_call.arguments)
if function_name == "SearchCareerInfo":
# 함수 실행
function_response = SearchCareerInfo(function_name)
parsed_data = json.loads(function_response)
for info in parsed_data['career_info']:
detected = chardet.detect(info['content'].encode())
decoded_content = info['content'].encode(detected['encoding']).decode('utf-8', errors='ignore') #한국어로 디코딩
# 함수 응답을 메시지 이력에 추가
st.session_state.messages.append({
"role": "function",
"name": function_name,
"content": decoded_content
})
assistant_reply= openai.chat.completions.create(
model="gpt-4o",
messages=st.session_state.messages
)
assistant_replys = assistant_reply.choices[0].message.content
elif function_name == "SearchSeniorInfo":
# 함수 실행
#function_response = SearchSeniorInfo(function_name)
function_response = SearchSeniorInfo(function_args["query"])
# 함수 응답을 메시지 이력에 추가
st.session_state.messages.append({
"role": "function",
"name": function_name,
"content": function_response["careersenior_info"]
})
assistant_reply= openai.chat.completions.create(
model="gpt-4o",
messages=st.session_state.messages
)
assistant_replys = assistant_reply.choices[0].message.content
else:
assistant_replys = response.choices[0].message.content
# Add assistant response to chat history
st.chat_message("assistant").write(assistant_replys)
st.session_state.messages.append({"role": "assistant", "content": assistant_replys})
st.session_state.memory.save_context(inputs={"user": user_input}, outputs={"assistant": assistant_replys})


# 대화 로그 저장
def save_conversation_to_file(conversation):
with open("career_chat_log.csv", mode='a', newline='', encoding='utf-8') as file:
for message in conversation:
if message["role"]=='system':
continue
file.write(f"{message['role']}: {message['content']}\n")
33 changes: 0 additions & 33 deletions pages/1_File_Q&A.py

This file was deleted.

Loading