-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_assistant_thread.py
More file actions
64 lines (49 loc) · 2.17 KB
/
make_assistant_thread.py
File metadata and controls
64 lines (49 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
52
53
54
55
56
57
58
59
60
61
62
63
64
from dataproc import Dart, OPENAICommunicator
import os
import time
d = Dart()
communicator = OPENAICommunicator()
# # 기업 정보 다운로드
# df = d.download_corp_list()
# 원하는 회사명, 연도, 보고서 타입 입력
corp_name = 'NAVER'
bsns_year = '2023'
reprt_type = '사업보고서'
reprt_code = '11011' # 사업보고서
uid = '1'
# # 리포트 다운로드
d.download_report(corp_name, bsns_year, reprt_type)
d.parse_xml(corp_name, bsns_year, reprt_type)
'''
assistant_id_env_name = f"{corp_name}_{bsns_year}_{reprt_code}_assistant_id".upper()
thread_id_env_name = f"{corp_name}_{bsns_year}_{reprt_code}_thread_id_{uid}".upper()
vector_store_id_env_name = f"{corp_name}_{bsns_year}_{reprt_code}_vector_store_id".upper()
# assistant_id 확인 및 생성
if not os.getenv(assistant_id_env_name):
vector_store_id = communicator.create_vector_store()
file_ids = communicator.upload_files(corp_name, bsns_year, reprt_type, vector_store_id) # 파일 업로드
assistant_id = communicator.create_assistant(corp_name, bsns_year, reprt_code, vector_store_id) # 어시스턴트 생성
# communicator.update_assistant(assistant_id, vector_store_id)
# 환경 변수에 assistant_id 저장
with open(".env", "a") as env_file:
env_file.write(f"{assistant_id_env_name}={assistant_id}\n")
env_file.write(f"{vector_store_id_env_name}={vector_store_id}\n")
else:
assistant_id = os.getenv(assistant_id_env_name)
vector_store_id = os.getenv(vector_store_id_env_name)
# print(assistant_id)
# thread_id 확인 및 생성
if not os.getenv(thread_id_env_name):
thread_id = communicator.create_thread()
# 환경 변수에 thread_id 저장
with open(".env", "a") as env_file:
env_file.write(f"{thread_id_env_name}={thread_id}\n")
else:
thread_id = os.getenv(thread_id_env_name)
# # message_id = communicator.create_message(thread_id) # 최초 메시지 생성
instructions = input("지시사항을 입력해주세요 ('종료'를 입력하면 프로그램이 종료됩니다): ")
if instructions == '종료':
print("프로그램을 종료합니다.")
else:
communicator.create_run(thread_id, assistant_id, instructions)
'''