seawolf2357
commited on
Commit
โข
7e3f770
1
Parent(s):
1263e43
Update app.py
Browse files
app.py
CHANGED
@@ -58,6 +58,7 @@ class MyClient(discord.Client):
|
|
58 |
)
|
59 |
|
60 |
async def handle_message(message):
|
|
|
61 |
user_input = message.content.strip()
|
62 |
user_mention = message.author.mention
|
63 |
|
@@ -72,11 +73,14 @@ async def handle_message(message):
|
|
72 |
return f"{user_mention}, '{user_input}'์ ๋ํ ํฐ์ปค ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. ์ ํํ ์ข
๋ชฉ๋ช
์ด๋ ํฐ์ปค๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์."
|
73 |
|
74 |
async def handle_ticker(ticker, user_mention):
|
|
|
75 |
company_info = get_company_info(ticker)
|
76 |
|
|
|
77 |
if len(conversation_history) > 20:
|
78 |
conversation_history = conversation_history[-20:]
|
79 |
|
|
|
80 |
filtered_conversation = []
|
81 |
last_role = None
|
82 |
for message in conversation_history:
|
@@ -84,6 +88,7 @@ async def handle_ticker(ticker, user_mention):
|
|
84 |
filtered_conversation.append(message)
|
85 |
last_role = message['role']
|
86 |
|
|
|
87 |
system_message = f"์ฌ์ฉ์๊ฐ ํฐ์ปค '{ticker}'์ ๋ํด ์๊ณ ์ถ์ดํฉ๋๋ค."
|
88 |
system_prefix = """
|
89 |
๋๋ '๊ธ๋ก๋ฒ ์ฃผ์ ์ ๋ณด ์ ๋ฌธ๊ฐ'์
๋๋ค. ํฐ์ปค์ ๋ํด Yahoo Finance๋ฅผ ํตํด ํ์ฌ ์ ๋ณด, ์์ธ ์ ๋ณด, 1์ผ/1์ฃผ/1๊ฐ์/1๋
/10๋
๊ฐ์ ์ฐจํธ ํ๋ฆ ์์ฝ, ์ต์ ๊ด๋ จ ๋ด์ค ์์ฝ์ ์ ๊ณตํ๊ณ , ์ต์ข
์ ์ผ๋ก ํฅํ 1์ฃผ์ผ๊ฐ ์์ธ ์์ธก์ ์ ๊ณตํฉ๋๋ค. ๋ฆฌ์คํฌ์ ํ์คํฌ๋ฅผ ๊ตฌ๋ถํ์ฌ ์ค๋ช
ํ๋ฉฐ, ๋ชจ๋ ํฌ์ ์ฑ
์์ ๊ณ ๊ฐ์๊ฒ ์์์ ๋ฐ๋์ ๊ณ ์งํ์ญ์์ค.
|
@@ -94,14 +99,17 @@ async def handle_ticker(ticker, user_mention):
|
|
94 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}] + filtered_conversation
|
95 |
logging.debug(f'๋ชจ๋ธ์ ๋ณด๋ผ ๋ฉ์์ง: {messages}')
|
96 |
|
|
|
97 |
response = await asyncio.get_event_loop().run_in_executor(None, lambda: hf_client.chat_completion(
|
98 |
messages=messages, max_tokens=1000, temperature=0.7, top_p=0.85))
|
99 |
|
100 |
full_response_text = ''.join(response)
|
101 |
logging.debug(f'๋ชจ๋ธ ์ ์ฒด ์๋ต: {full_response_text}')
|
102 |
|
|
|
103 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
104 |
|
|
|
105 |
final_response = f"{user_mention}, {full_response_text}\n\n**ํ์ฌ ์ ๋ณด:**\n{company_info}"
|
106 |
|
107 |
return final_response
|
@@ -109,11 +117,12 @@ async def handle_ticker(ticker, user_mention):
|
|
109 |
def get_ticker_from_name(name):
|
110 |
try:
|
111 |
ticker_search = Ticker(name)
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
|
|
117 |
return None
|
118 |
except Exception as e:
|
119 |
logging.error(f'Error retrieving ticker for {name}: {e}')
|
|
|
58 |
)
|
59 |
|
60 |
async def handle_message(message):
|
61 |
+
global conversation_history # ์ ์ญ ๋ณ์ ์ฌ์ฉ์ ๋ช
์
|
62 |
user_input = message.content.strip()
|
63 |
user_mention = message.author.mention
|
64 |
|
|
|
73 |
return f"{user_mention}, '{user_input}'์ ๋ํ ํฐ์ปค ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค. ์ ํํ ์ข
๋ชฉ๋ช
์ด๋ ํฐ์ปค๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์."
|
74 |
|
75 |
async def handle_ticker(ticker, user_mention):
|
76 |
+
global conversation_history # ์ ์ญ ๋ณ์ ์ฌ์ฉ์ ๋ช
์
|
77 |
company_info = get_company_info(ticker)
|
78 |
|
79 |
+
# ๋ํ ๋ด์ญ์ด ๋๋ฌด ๊ธธ ๊ฒฝ์ฐ, ์ต๋ ๊ธธ์ด๋ฅผ ์ ์งํ๊ธฐ ์ํด ์๋ถ๋ถ์ ์๋ผ๋
|
80 |
if len(conversation_history) > 20:
|
81 |
conversation_history = conversation_history[-20:]
|
82 |
|
83 |
+
# ๋ํ ๋ด์ญ์์ ์ญํ ์ด ์ ๋๋ก ๊ต์ฐจํ๋๋ก ํ์ธ
|
84 |
filtered_conversation = []
|
85 |
last_role = None
|
86 |
for message in conversation_history:
|
|
|
88 |
filtered_conversation.append(message)
|
89 |
last_role = message['role']
|
90 |
|
91 |
+
# ์์คํ
๋ฉ์์ง์ ํํฐ๋ง๋ ๋ํ ํ์คํ ๋ฆฌ๋ฅผ ๊ฒฐํฉํ์ฌ ๋ชจ๋ธ์ ๋ณด๋ผ ๋ฉ์์ง ๊ตฌ์ฑ
|
92 |
system_message = f"์ฌ์ฉ์๊ฐ ํฐ์ปค '{ticker}'์ ๋ํด ์๊ณ ์ถ์ดํฉ๋๋ค."
|
93 |
system_prefix = """
|
94 |
๋๋ '๊ธ๋ก๋ฒ ์ฃผ์ ์ ๋ณด ์ ๋ฌธ๊ฐ'์
๋๋ค. ํฐ์ปค์ ๋ํด Yahoo Finance๋ฅผ ํตํด ํ์ฌ ์ ๋ณด, ์์ธ ์ ๋ณด, 1์ผ/1์ฃผ/1๊ฐ์/1๋
/10๋
๊ฐ์ ์ฐจํธ ํ๋ฆ ์์ฝ, ์ต์ ๊ด๋ จ ๋ด์ค ์์ฝ์ ์ ๊ณตํ๊ณ , ์ต์ข
์ ์ผ๋ก ํฅํ 1์ฃผ์ผ๊ฐ ์์ธ ์์ธก์ ์ ๊ณตํฉ๋๋ค. ๋ฆฌ์คํฌ์ ํ์คํฌ๋ฅผ ๊ตฌ๋ถํ์ฌ ์ค๋ช
ํ๋ฉฐ, ๋ชจ๋ ํฌ์ ์ฑ
์์ ๊ณ ๊ฐ์๊ฒ ์์์ ๋ฐ๋์ ๊ณ ์งํ์ญ์์ค.
|
|
|
99 |
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}] + filtered_conversation
|
100 |
logging.debug(f'๋ชจ๋ธ์ ๋ณด๋ผ ๋ฉ์์ง: {messages}')
|
101 |
|
102 |
+
# ๋ชจ๋ธ ํธ์ถ
|
103 |
response = await asyncio.get_event_loop().run_in_executor(None, lambda: hf_client.chat_completion(
|
104 |
messages=messages, max_tokens=1000, temperature=0.7, top_p=0.85))
|
105 |
|
106 |
full_response_text = ''.join(response)
|
107 |
logging.debug(f'๋ชจ๋ธ ์ ์ฒด ์๋ต: {full_response_text}')
|
108 |
|
109 |
+
# ์ด์์คํดํธ ์๋ต์ ๋ํ ํ์คํ ๋ฆฌ์ ์ถ๊ฐ
|
110 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
111 |
|
112 |
+
# ์ต์ข
์๋ต: ํ์ฌ ์ ๋ณด์ ๋ชจ๋ธ์ ์๋ต ๊ฒฐํฉ
|
113 |
final_response = f"{user_mention}, {full_response_text}\n\n**ํ์ฌ ์ ๋ณด:**\n{company_info}"
|
114 |
|
115 |
return final_response
|
|
|
117 |
def get_ticker_from_name(name):
|
118 |
try:
|
119 |
ticker_search = Ticker(name)
|
120 |
+
summary = ticker_search.summary_profile
|
121 |
+
# ํฐ์ปค๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ํ์ฑ๋์๋์ง ํ์ธ
|
122 |
+
if summary and isinstance(summary, dict):
|
123 |
+
# ๊ฐ์ฅ ๋งค์นญ๋ ํค๋ฅผ ํฐ์ปค๋ก ์ฌ์ฉ
|
124 |
+
ticker = next(iter(summary.keys()))
|
125 |
+
return ticker
|
126 |
return None
|
127 |
except Exception as e:
|
128 |
logging.error(f'Error retrieving ticker for {name}: {e}')
|