Update app.py
Browse files
app.py
CHANGED
|
@@ -1,70 +1,71 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import argparse
|
| 3 |
-
from pathlib import Path
|
| 4 |
-
from crawl import *
|
| 5 |
-
from chatbot import *
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
def main(args):
|
| 9 |
-
# ํ๊น
ํ์ด์ค secret key๋ก๋ถํฐ api key ์ฝ์ด์ค๊ธฐ
|
| 10 |
-
api_key = args.api_key
|
| 11 |
-
if not api_key:
|
| 12 |
-
api_key = os.environ.get("GROQ_API_KEY", "")
|
| 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 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
parser.add_argument("--
|
| 52 |
-
parser.add_argument("--
|
| 53 |
-
parser.add_argument("--
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
parser.add_argument("--
|
| 58 |
-
parser.add_argument("--
|
| 59 |
-
parser.add_argument("--
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
parser.add_argument("--
|
| 64 |
-
parser.add_argument("--
|
| 65 |
-
parser.add_argument("--
|
| 66 |
-
parser.add_argument("--
|
| 67 |
-
parser.add_argument("--
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
main(args)
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import argparse
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
from crawl import *
|
| 5 |
+
from chatbot import *
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def main(args):
|
| 9 |
+
# ํ๊น
ํ์ด์ค secret key๋ก๋ถํฐ api key ์ฝ์ด์ค๊ธฐ
|
| 10 |
+
api_key = args.api_key
|
| 11 |
+
if not api_key:
|
| 12 |
+
api_key = str(os.environ.get("GROQ_API_KEY", ""))
|
| 13 |
+
print(f"Groq API Key๋ฅผ ์ฑ๊ณต์ ์ผ๋ก ๋ถ๋ฌ์์ต๋๋ค. ๋ท์๋ฆฌ 4๊ธ์ : ...{api_key[-4:]}")
|
| 14 |
+
|
| 15 |
+
if not api_key:
|
| 16 |
+
print("API Key๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. Hugging Face Secrets์์ 'GROQ_API_KEY'๋ฅผ ์ค์ ํ๊ฑฐ๋ --api_key ์ธ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# ํฌ๋กค๋ฌ ํํธ
|
| 20 |
+
abs_download_path = os.path.join(args.base_dir, args.download_dir)
|
| 21 |
+
abs_db_path = os.path.join(args.base_dir, args.db_dir)
|
| 22 |
+
|
| 23 |
+
collection = make_db(abs_download_path, abs_db_path, args.collection_name)
|
| 24 |
+
# ๊ธฐ๋ณธ ์๋ฒ ๋ฉ ํจ์ ์ธ์ ํจ์๋ฅผ ์ด์ฉํ ๊ฒฝ์ฐ
|
| 25 |
+
#collection = make_db(abs_download_path, abs_db_path, args.collection_name, embedf_name = args.embedf_name)
|
| 26 |
+
|
| 27 |
+
crawl_seoultech_notice(abs_download_path, args.base_url, args.num_page, collection)
|
| 28 |
+
|
| 29 |
+
# ์ฑ๋ด ํํธ
|
| 30 |
+
collection = get_chroma_collection(abs_db_path, args.collection_name)
|
| 31 |
+
# embedding function๋ก ๋ค๋ฅธ ๋ชจ๋ธ์ ์ฌ์ฉํ ๊ฒฝ์ฐ
|
| 32 |
+
# collection = get_chroma_collection(abs_db_path, args.collection_name, embedf_name = args.embedf_name)
|
| 33 |
+
|
| 34 |
+
if collection is None:
|
| 35 |
+
print("Chromadb Collection์ ๋ถ๋ฌ์ค์ง ๋ชปํ์ต๋๋ค. ํ๋ก๊ทธ๋จ์ ์ข
๋ฃํฉ๋๋ค. ")
|
| 36 |
+
return
|
| 37 |
+
|
| 38 |
+
# ์์คํ
ํ๋กฌํํธ ๋ถ๋ฌ์ค๊ธฐ
|
| 39 |
+
system_prompt = get_system_prompt(args.prompt_type)
|
| 40 |
+
|
| 41 |
+
# ์ฑ๋ด ์คํ
|
| 42 |
+
chat_with_rag(api_key = args.api_key,
|
| 43 |
+
collection = collection,
|
| 44 |
+
system_prompt = system_prompt,
|
| 45 |
+
args = args)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
parser = argparse.ArgumentParser()
|
| 50 |
+
# ๊ณตํต ์ธ์
|
| 51 |
+
parser.add_argument("--base_dir", type = str, default = str(Path(__file__).resolve().parent)) # ํ์ฌ ์ด ํ์ผ์ด ์๋ ๋๋ ํ ๋ฆฌ
|
| 52 |
+
parser.add_argument("--db_dir", type = str, default = "seoultech_data_db")
|
| 53 |
+
parser.add_argument("--collection_name", type = str, default = "seoultech_notices")
|
| 54 |
+
parser.add_argument("--embedf_name", type = str, default = "BAAI/bge-m3")
|
| 55 |
+
|
| 56 |
+
# ํฌ๋กค๋ฌ
|
| 57 |
+
parser.add_argument("--base_url", type = str, default = "https://www.seoultech.ac.kr/service/info/notice")
|
| 58 |
+
parser.add_argument("--download_dir", type = str, default = "seoultech_data_download")
|
| 59 |
+
parser.add_argument("--header", type = dict, default = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"})
|
| 60 |
+
parser.add_argument("--num_page", type = int, default = 1)
|
| 61 |
+
|
| 62 |
+
# ์ฑ๋ด
|
| 63 |
+
parser.add_argument("--api_key", type = str, default = "")
|
| 64 |
+
parser.add_argument("--log_dir", type = str, default = "chat_log")
|
| 65 |
+
parser.add_argument("--model_name", type = str, default = "llama-3.3-70b-versatile") # llama-3.1-8b-instant llama-3.3-70b-versatile openai/gpt-oss-120b
|
| 66 |
+
parser.add_argument("--temperature", type = float, default = 0.5)
|
| 67 |
+
parser.add_argument("--n_results", type = int, default = 3)
|
| 68 |
+
parser.add_argument("--prompt_type", type = str, default = "v")
|
| 69 |
+
|
| 70 |
+
args = parser.parse_args()
|
| 71 |
main(args)
|