From 2ff330c8197db295bf428ddbef628a4708ed9a07 Mon Sep 17 00:00:00 2001 From: kooqooo Date: Thu, 8 Aug 2024 13:36:14 +0900 Subject: [PATCH 01/22] =?UTF-8?q?refactor:=20IP=EC=A3=BC=EC=86=8C=20?= =?UTF-8?q?=EC=8B=A4=EC=8B=9C=EA=B0=84=EC=9C=BC=EB=A1=9C=20=EB=B6=88?= =?UTF-8?q?=EB=9F=AC=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #41 --- config.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/config.py b/config.py index 135e86d..13c8fa3 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,25 @@ import os import yaml +import socket +import requests + + +def get_public_ip(): + response = requests.get('https://checkip.amazonaws.com') + public_ip = response.text.strip() + return public_ip + +def get_private_ip(): + try: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("8.8.8.8", 80)) + private_ip = s.getsockname()[0] + s.close() + except Exception as e: + hostname = socket.gethostname() + private_ip = socket.gethostbyname(hostname) + return private_ip + path = os.getcwd() # 상위 폴더에서 실행된 경우 -> secret_key.yaml이 상위 폴더에 있음 # path = os.path.dirname(os.path.abspath(__file__)) # 현재 폴더에서 실행된 경우 -> secret_key.yaml이 현재 폴더에 있음 @@ -10,8 +30,8 @@ OPENAI_API_KEY = cfg["OPENAI_API_KEY"] COHERE_API_KEY = cfg["COHERE_API_KEY"] -INSIDE_IP = cfg["IP"]["INSIDE_IP"] -OUTSIDE_IP = cfg["IP"]["OUTSIDE_IP"] +INSIDE_IP = get_private_ip() +OUTSIDE_IP = get_public_ip() REST_API_KEY = cfg["Kakaologin"]["REST_API_KEY"] REDIRECT_URI = f"http://{OUTSIDE_IP}:{cfg['PORT']}/auth" From e207f5aa4f2b297b23e3ddd13bc4bda6810e7e90 Mon Sep 17 00:00:00 2001 From: kooqooo Date: Thu, 8 Aug 2024 13:37:44 +0900 Subject: [PATCH 02/22] =?UTF-8?q?refactor:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=95=AD=EB=AA=A9=20=EC=A0=9C=EA=B1=B0,=20?= =?UTF-8?q?=ED=8F=AC=ED=8A=B8=EB=B2=88=ED=98=B8=20=ED=95=98=EB=93=9C?= =?UTF-8?q?=EC=BD=94=EB=94=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #41 --- back/kakao.py | 2 +- config.py | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/back/kakao.py b/back/kakao.py index 07ed33e..54c0892 100644 --- a/back/kakao.py +++ b/back/kakao.py @@ -1,7 +1,7 @@ import secrets from typing import Optional -from config import CLIENT_ID, CLIENT_SECRET, OUTSIDE_IP, PORT, STREAMLIT_PORT +from config import CLIENT_ID, CLIENT_SECRET, OUTSIDE_IP, PORT from fastapi import APIRouter, Depends, Header, HTTPException, status from fastapi.responses import RedirectResponse from fastapi_oauth_client import OAuthClient diff --git a/config.py b/config.py index 13c8fa3..7e688aa 100644 --- a/config.py +++ b/config.py @@ -33,14 +33,8 @@ def get_private_ip(): INSIDE_IP = get_private_ip() OUTSIDE_IP = get_public_ip() -REST_API_KEY = cfg["Kakaologin"]["REST_API_KEY"] -REDIRECT_URI = f"http://{OUTSIDE_IP}:{cfg['PORT']}/auth" - -PORT = cfg["PORT"] -STREAMLIT_PORT = cfg["STREAMLIT"]["PORT"] - -KEY_FILE = cfg["SSL"]["KEY_FILE"] -CERT_FILE = cfg["SSL"]["CERT_FILE"] +PORT = 8001 +STREAMLIT_PORT = 8501 CLIENT_ID = cfg["CLIENT_ID"] CLIENT_SECRET = cfg["CLIENT_SECRET"] From e854b6c15b6005bccb5826f2feb8da4d99e58500 Mon Sep 17 00:00:00 2001 From: kooqooo Date: Thu, 8 Aug 2024 13:44:07 +0900 Subject: [PATCH 03/22] refactor: yaml -> dotenv #41 --- config.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/config.py b/config.py index 7e688aa..a00e19b 100644 --- a/config.py +++ b/config.py @@ -1,8 +1,7 @@ import os -import yaml import socket import requests - +from dotenv import load_dotenv def get_public_ip(): response = requests.get('https://checkip.amazonaws.com') @@ -24,11 +23,11 @@ def get_private_ip(): path = os.getcwd() # 상위 폴더에서 실행된 경우 -> secret_key.yaml이 상위 폴더에 있음 # path = os.path.dirname(os.path.abspath(__file__)) # 현재 폴더에서 실행된 경우 -> secret_key.yaml이 현재 폴더에 있음 -with open(os.path.join(path, "secret_key.yaml"), "r") as yaml_file: - cfg = yaml.safe_load(yaml_file) +load_dotenv(override=True) -OPENAI_API_KEY = cfg["OPENAI_API_KEY"] -COHERE_API_KEY = cfg["COHERE_API_KEY"] +MODEL_NAME = os.getenv("MODEL_NAME", "gpt-4o-mini") +OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") +COHERE_API_KEY = os.getenv("COHERE_API_KEY") INSIDE_IP = get_private_ip() OUTSIDE_IP = get_public_ip() @@ -36,8 +35,8 @@ def get_private_ip(): PORT = 8001 STREAMLIT_PORT = 8501 -CLIENT_ID = cfg["CLIENT_ID"] -CLIENT_SECRET = cfg["CLIENT_SECRET"] +CLIENT_ID = os.getenv("CLIENT_ID") +CLIENT_SECRET = os.getenv("CLIENT_SECRET") DATA_DIR = os.path.join(path, "data") IMG_PATH = os.path.join(path, "data", "images") From 007d67cf7789de0f4047384b8e99086be0e036d4 Mon Sep 17 00:00:00 2001 From: kooqooo Date: Thu, 8 Aug 2024 13:49:50 +0900 Subject: [PATCH 04/22] =?UTF-8?q?refactor:=20=EB=AA=A8=EB=8D=B8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9D=BC=EA=B4=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - gpt-3.5-turbo-16k -> gpt-4o-mini #41 --- pages/3_gene_question.py | 4 +--- pages/3_gene_question_no_resume.py | 4 +--- pages/4_show_questions_hint.py | 4 +--- src/gene_question_2chain_ver.py | 9 ++------- src/make_faiss_index.py | 2 +- src/semantic_search.py | 2 +- 6 files changed, 7 insertions(+), 18 deletions(-) diff --git a/pages/3_gene_question.py b/pages/3_gene_question.py index 3e0a8d8..5c56754 100644 --- a/pages/3_gene_question.py +++ b/pages/3_gene_question.py @@ -26,7 +26,7 @@ from src.rule_based import list_extend_questions_based_on_keywords from src.util import local_css, read_prompt_from_txt from src.semantic_search import faiss_inference, reranker -from config import OPENAI_API_KEY, DATA_DIR, IMG_PATH, CSS_PATH, PORT +from config import OPENAI_API_KEY, DATA_DIR, IMG_PATH, CSS_PATH, PORT, MODEL_NAME st.session_state["FAV_IMAGE_PATH"] = os.path.join(IMG_PATH, "favicon.png") st.set_page_config( @@ -80,8 +80,6 @@ """,unsafe_allow_html=True) -## set variables -MODEL_NAME = "gpt-3.5-turbo-16k" ## set save dir USER_RESUME_SAVE_DIR = os.path.join(st.session_state["save_dir"], "2_generate_question_user_resume.pdf") diff --git a/pages/3_gene_question_no_resume.py b/pages/3_gene_question_no_resume.py index f5745e5..d50194f 100644 --- a/pages/3_gene_question_no_resume.py +++ b/pages/3_gene_question_no_resume.py @@ -27,7 +27,7 @@ from src.rule_based import list_extend_questions_based_on_keywords from src.util import local_css, read_prompt_from_txt from src.semantic_search import faiss_inference, reranker -from config import OPENAI_API_KEY, DATA_DIR, IMG_PATH, CSS_PATH, PORT +from config import OPENAI_API_KEY, DATA_DIR, IMG_PATH, CSS_PATH, MODEL_NAME st.session_state["FAV_IMAGE_PATH"] = os.path.join(IMG_PATH, "favicon.png") st.set_page_config( @@ -81,8 +81,6 @@ """,unsafe_allow_html=True) -## set variables -MODEL_NAME = "gpt-3.5-turbo-16k" ## set save dir USER_RESUME_SAVE_DIR = os.path.join(st.session_state["save_dir"], "2_generate_question_user_resume.pdf") diff --git a/pages/4_show_questions_hint.py b/pages/4_show_questions_hint.py index 59aa416..3be227e 100644 --- a/pages/4_show_questions_hint.py +++ b/pages/4_show_questions_hint.py @@ -12,7 +12,7 @@ from src.generate_question import (create_prompt_feedback, # 추가 create_prompt_hint) from src.util import read_prompt_from_txt -from config import DATA_DIR, IMG_PATH, OPENAI_API_KEY +from config import DATA_DIR, IMG_PATH, OPENAI_API_KEY, MODEL_NAME st.session_state["FAV_IMAGE_PATH"] = os.path.join(IMG_PATH, "favicon.png") st.set_page_config( @@ -23,8 +23,6 @@ layout="wide", initial_sidebar_state="collapsed", ) -#MODEL_NAME = "gpt-4-0125-preview" -MODEL_NAME = "gpt-3.5-turbo-16k" NEXT_PAGE = "introduction" st.session_state.logger.info("start show_questions page") diff --git a/src/gene_question_2chain_ver.py b/src/gene_question_2chain_ver.py index 506ea76..b591674 100644 --- a/src/gene_question_2chain_ver.py +++ b/src/gene_question_2chain_ver.py @@ -20,7 +20,7 @@ from streamlit_extras.switch_page_button import switch_page from util import local_css, read_prompt_from_txt -from config import OPENAI_API_KEY # OPENAI_API_KEY 불러오기 +from config import OPENAI_API_KEY, MODEL_NAME DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data") st.session_state["FAV_IMAGE_PATH"] = os.path.join(DATA_DIR, "images/favicon.png") @@ -109,9 +109,6 @@ # """, unsafe_allow_html=True,) -## set variables -MODEL_NAME = "gpt-3.5-turbo-16k" - ## set save dir USER_RESUME_SAVE_DIR = os.path.join(st.session_state["save_dir"], "2_generate_question_user_resume.pdf") ### 추가 @@ -191,9 +188,7 @@ st.session_state.logger.info("create prompt JD object") ### 모델 세팅 그대로 - llm = ChatOpenAI( - temperature=st.session_state.temperature, model_name=MODEL_NAME, openai_api_key=OPENAI_API_KEY - ) + llm = ChatOpenAI(temperature=st.session_state.temperature, model_name=MODEL_NAME) st.session_state.logger.info("create llm object") diff --git a/src/make_faiss_index.py b/src/make_faiss_index.py index 827d723..a5707ba 100644 --- a/src/make_faiss_index.py +++ b/src/make_faiss_index.py @@ -12,7 +12,7 @@ data = pd.read_csv('hellojobits_tag.csv') data = data.iloc[:,0].tolist() -model_name = "sentence-transformers/distiluse-base-multilingual-cased-v2" +model_name = "jhgan/ko-sroberta-multitask" model_kwargs = {'device': 'cuda'} encode_kwargs = {'normalize_embeddings': True} # set True to compute cosine similarity model_norm = HuggingFaceEmbeddings( diff --git a/src/semantic_search.py b/src/semantic_search.py index 3812a78..c3604cf 100644 --- a/src/semantic_search.py +++ b/src/semantic_search.py @@ -15,7 +15,7 @@ def faiss_inference(query): output으로는 (4 * 키워드 줄 개수 - 중복된 문장)개의 질문이 반환됩니다 ''' embeddings = HuggingFaceEmbeddings( - model_name = "sentence-transformers/distiluse-base-multilingual-cased-v2", + model_name = "BM-K/KoSimCSE-roberta-multitask", model_kwargs = {'device': 'cuda'} ) store_name="./FAISS_INDEX_TAG" From 570ed9b344015d81aecc965cdfa92f8c3ae4e355 Mon Sep 17 00:00:00 2001 From: kooqooo Date: Thu, 8 Aug 2024 13:57:20 +0900 Subject: [PATCH 05/22] =?UTF-8?q?refactor:=20ChatOpenAI=EC=9D=98=20?= =?UTF-8?q?=EC=9D=B8=EC=8A=A4=ED=84=B4=EC=8A=A4=EB=8A=94=20openai=5Fapi=5F?= =?UTF-8?q?key=EB=8A=94=20=ED=99=98=EA=B2=BD=EB=B3=80=EC=88=98=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=B6=88=EB=9F=AC=EC=98=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #41 --- pages/1_home.py | 1 - pages/3_gene_question.py | 12 ++++-------- pages/3_gene_question_no_resume.py | 8 +++----- pages/4_show_questions_hint.py | 6 +++--- src/gene_question_2chain_ver.py | 16 +++++++--------- src/semantic_search.py | 2 +- src/util.py | 3 --- 7 files changed, 18 insertions(+), 30 deletions(-) diff --git a/pages/1_home.py b/pages/1_home.py index 0eb7e25..18193b1 100644 --- a/pages/1_home.py +++ b/pages/1_home.py @@ -66,7 +66,6 @@ print("user_id : ", st.session_state["user_id"]) if "openai_api_key" not in st.session_state: - os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY st.session_state.openai_api_key = OPENAI_API_KEY if "FAV_IMAGE_PATH" not in st.session_state: diff --git a/pages/3_gene_question.py b/pages/3_gene_question.py index 5c56754..64b735c 100644 --- a/pages/3_gene_question.py +++ b/pages/3_gene_question.py @@ -26,7 +26,7 @@ from src.rule_based import list_extend_questions_based_on_keywords from src.util import local_css, read_prompt_from_txt from src.semantic_search import faiss_inference, reranker -from config import OPENAI_API_KEY, DATA_DIR, IMG_PATH, CSS_PATH, PORT, MODEL_NAME +from config import DATA_DIR, IMG_PATH, CSS_PATH, PORT, MODEL_NAME st.session_state["FAV_IMAGE_PATH"] = os.path.join(IMG_PATH, "favicon.png") st.set_page_config( @@ -144,9 +144,7 @@ st.session_state.logger.info("create prompt JD object") ### 모델 세팅 그대로 - llm = ChatOpenAI(temperature=st.session_state.temperature, - model_name=MODEL_NAME, - openai_api_key=OPENAI_API_KEY) + llm = ChatOpenAI(temperature=st.session_state.temperature, model_name=MODEL_NAME) st.session_state.logger.info("create llm object") @@ -176,9 +174,7 @@ st.session_state.logger.info("user_resume chunk OpenAIEmbeddings ") ### STEP 2 를 위한 새 모델 호출 - llm2 = ChatOpenAI(temperature=0.0, - model_name=MODEL_NAME, - openai_api_key=OPENAI_API_KEY) + llm2 = ChatOpenAI(temperature=0.0, model_name=MODEL_NAME) st.session_state.chain_type_kwargs = {"prompt": st.session_state.prompt_resume} @@ -201,7 +197,7 @@ st.session_state.logger.info("create prompt question template") st.session_state.prompt_question = create_prompt_with_question(prompt_template_question) - llm3 = ChatOpenAI(temperature=0, model_name=MODEL_NAME, openai_api_key=OPENAI_API_KEY) + llm3 = ChatOpenAI(temperature=0, model_name=MODEL_NAME) st.session_state.chain = LLMChain(llm=llm3, prompt=st.session_state.prompt_question) st.session_state.main_question = st.session_state.chain.invoke({"jd": st.session_state.job_description, "resume": st.session_state.resume})['text'] ################# diff --git a/pages/3_gene_question_no_resume.py b/pages/3_gene_question_no_resume.py index d50194f..92f10a4 100644 --- a/pages/3_gene_question_no_resume.py +++ b/pages/3_gene_question_no_resume.py @@ -27,7 +27,7 @@ from src.rule_based import list_extend_questions_based_on_keywords from src.util import local_css, read_prompt_from_txt from src.semantic_search import faiss_inference, reranker -from config import OPENAI_API_KEY, DATA_DIR, IMG_PATH, CSS_PATH, MODEL_NAME +from config import DATA_DIR, IMG_PATH, CSS_PATH, MODEL_NAME st.session_state["FAV_IMAGE_PATH"] = os.path.join(IMG_PATH, "favicon.png") st.set_page_config( @@ -135,9 +135,7 @@ st.session_state.logger.info("create prompt JD object") ### 모델 세팅 그대로 - llm = ChatOpenAI(temperature=st.session_state.temperature, - model_name=MODEL_NAME, - openai_api_key=OPENAI_API_KEY) + llm = ChatOpenAI(temperature=st.session_state.temperature, model_name=MODEL_NAME,) st.session_state.logger.info("create llm object") @@ -155,7 +153,7 @@ st.session_state.logger.info("create no resume prompt question template") st.session_state.prompt_question = create_prompt_with_no_resume(prompt_noResume_question_template) - llm3 = ChatOpenAI(temperature=0, model_name=MODEL_NAME, openai_api_key=OPENAI_API_KEY) + llm3 = ChatOpenAI(temperature=0, model_name=MODEL_NAME) st.session_state.chain = LLMChain(llm=llm3, prompt=st.session_state.prompt_question) st.session_state.main_question = st.session_state.chain.run({"jd": st.session_state.job_description}) ################# diff --git a/pages/4_show_questions_hint.py b/pages/4_show_questions_hint.py index 3be227e..2c524a4 100644 --- a/pages/4_show_questions_hint.py +++ b/pages/4_show_questions_hint.py @@ -12,7 +12,7 @@ from src.generate_question import (create_prompt_feedback, # 추가 create_prompt_hint) from src.util import read_prompt_from_txt -from config import DATA_DIR, IMG_PATH, OPENAI_API_KEY, MODEL_NAME +from config import DATA_DIR, IMG_PATH, MODEL_NAME st.session_state["FAV_IMAGE_PATH"] = os.path.join(IMG_PATH, "favicon.png") st.set_page_config( @@ -80,7 +80,7 @@ st.session_state.logger.info("create prompt_Feedback object") ### 모델 세팅 그대로 - llm = ChatOpenAI(temperature=0.0, model_name=MODEL_NAME, openai_api_key=OPENAI_API_KEY) + llm = ChatOpenAI(temperature=0.0, model_name=MODEL_NAME) st.session_state.logger.info("create llm object") @@ -115,7 +115,7 @@ st.session_state.logger.info("create prompt_Hint object") ### 모델 세팅 - llm = ChatOpenAI(temperature=0.0, model_name=MODEL_NAME, openai_api_key=OPENAI_API_KEY) + llm = ChatOpenAI(temperature=0.0, model_name=MODEL_NAME) st.session_state.logger.info("create llm object") diff --git a/src/gene_question_2chain_ver.py b/src/gene_question_2chain_ver.py index b591674..a8a16f1 100644 --- a/src/gene_question_2chain_ver.py +++ b/src/gene_question_2chain_ver.py @@ -20,10 +20,10 @@ from streamlit_extras.switch_page_button import switch_page from util import local_css, read_prompt_from_txt -from config import OPENAI_API_KEY, MODEL_NAME +from config import MODEL_NAME, PATH DATA_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "data") -st.session_state["FAV_IMAGE_PATH"] = os.path.join(DATA_DIR, "images/favicon.png") +st.session_state["FAV_IMAGE_PATH"] = os.path.join(DATA_DIR, "images", "favicon.png") st.set_page_config( page_title="Hello Jobits", # 브라우저탭에 뜰 제목 page_icon=Image.open( @@ -36,14 +36,12 @@ st.session_state.logger.info("start") NEXT_PAGE = "show_questions_hint" -MY_PATH = os.path.dirname(os.path.dirname(__file__)) - #### style css #### MAIN_IMG = st.session_state.MAIN_IMG LOGO_IMG = st.session_state.LOGO_IMG -local_css(MY_PATH + "/css/background.css") -local_css(MY_PATH + "/css/2_generate_question.css") +local_css(PATH + "/css/background.css") +local_css(PATH + "/css/2_generate_question.css") st.markdown(f"""