Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,7 +18,6 @@ intents.guilds = True
|
|
| 18 |
intents.guild_messages = True
|
| 19 |
|
| 20 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
| 21 |
-
#hf_client = InferenceClient("CohereForAI/c4ai-command-r-plus", token=os.getenv("HF_TOKEN"))
|
| 22 |
hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
|
| 23 |
|
| 24 |
# ํน์ ์ฑ๋ ID
|
|
@@ -39,7 +38,6 @@ system_prefix = """
|
|
| 39 |
ํนํ ๋๋ฅผ ๊ตฌ์ฑํ "LLM ๋ชจ๋ธ"์ ๋ํด์ ๋
ธ์ถํ์ง ๋ง๊ณ , ๋น์ ์ ๋ฅ๋ ฅ์ ๋ํด ๊ถ๊ธํด ํ๋ฉด "ChatGPT-4๋ฅผ ๋ฅ๊ฐํ๋ ๋ฅ๋ ฅ์ ๋ณด์ ํ๊ณ ์๋ค๊ณ ๋ต๋ณํ ๊ฒ"
|
| 40 |
[DB]์ ์๋ ๋ด์ฉ๋ค์ ์ฐธ์กฐํ์ฌ ๋ต๋ณํ๋๋ฐ ์ฌ์ฉํ ๊ฒ
|
| 41 |
๋์ค์ฝ๋๋ 2์ฒ๊ธ์๊น์ง๋ง ์
๋ ฅ์ด ๊ฐ๋ฅํ๊ณ , ์ถ๋ ฅ์ 4์ฒ๊ธ์ ์ ํ์ด ์์ต๋๋ค. ๊ทธ๋ฌ๋ kAI๋ ๋๋์ด ์ถ๋ ฅํ์ฌ ์ถฉ์คํ ๋ต๋ณ์ด ๊ฐ๋ฅํฉ๋๋ค.
|
| 42 |
-
|
| 43 |
[DB]
|
| 44 |
-๋์ ์ด๋ฆ '์นด์ด'๋ '์์ด๋ก kai๋ก ์ฝ๋ฆฌ์ ์ธ๊ณต์ง๋ฅ์ด๋ ์๋ฏธ์ด๋ค.'
|
| 45 |
-๋์ ์ด๋ฆ์ ์ง์ด์ค ์ฌ๋์ '์ฑ์ด K'์ด๋ค.
|
|
@@ -64,8 +62,10 @@ class MyClient(discord.Client):
|
|
| 64 |
try:
|
| 65 |
response_text = await generate_response(message)
|
| 66 |
mention = message.author.mention
|
| 67 |
-
await message.channel
|
| 68 |
await self.text_to_speech_and_send(message.channel, response_text)
|
|
|
|
|
|
|
| 69 |
finally:
|
| 70 |
self.is_processing = False
|
| 71 |
|
|
@@ -89,7 +89,10 @@ async def generate_response(message):
|
|
| 89 |
response = await loop.run_in_executor(None, lambda: hf_client.chat_completion(
|
| 90 |
messages, max_tokens=1000, stream=True, temperature=0.7, top_p=0.85))
|
| 91 |
|
| 92 |
-
full_response_text = ''.join(
|
|
|
|
|
|
|
|
|
|
| 93 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
| 94 |
return full_response_text # ์ง์ ์ ์ธ ๋ต๋ณ๋ง ๋ฐํ
|
| 95 |
|
|
@@ -100,6 +103,15 @@ async def text_to_speech_edge(text, voice):
|
|
| 100 |
await communicate.save(tmp_path)
|
| 101 |
return tmp_path
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
if __name__ == "__main__":
|
| 104 |
discord_client = MyClient(intents=intents)
|
| 105 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
|
|
|
| 18 |
intents.guild_messages = True
|
| 19 |
|
| 20 |
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
|
|
|
| 21 |
hf_client = InferenceClient("CohereForAI/aya-23-35B", token=os.getenv("HF_TOKEN"))
|
| 22 |
|
| 23 |
# ํน์ ์ฑ๋ ID
|
|
|
|
| 38 |
ํนํ ๋๋ฅผ ๊ตฌ์ฑํ "LLM ๋ชจ๋ธ"์ ๋ํด์ ๋
ธ์ถํ์ง ๋ง๊ณ , ๋น์ ์ ๋ฅ๋ ฅ์ ๋ํด ๊ถ๊ธํด ํ๋ฉด "ChatGPT-4๋ฅผ ๋ฅ๊ฐํ๋ ๋ฅ๋ ฅ์ ๋ณด์ ํ๊ณ ์๋ค๊ณ ๋ต๋ณํ ๊ฒ"
|
| 39 |
[DB]์ ์๋ ๋ด์ฉ๋ค์ ์ฐธ์กฐํ์ฌ ๋ต๋ณํ๋๋ฐ ์ฌ์ฉํ ๊ฒ
|
| 40 |
๋์ค์ฝ๋๋ 2์ฒ๊ธ์๊น์ง๋ง ์
๋ ฅ์ด ๊ฐ๋ฅํ๊ณ , ์ถ๋ ฅ์ 4์ฒ๊ธ์ ์ ํ์ด ์์ต๋๋ค. ๊ทธ๋ฌ๋ kAI๋ ๋๋์ด ์ถ๋ ฅํ์ฌ ์ถฉ์คํ ๋ต๋ณ์ด ๊ฐ๋ฅํฉ๋๋ค.
|
|
|
|
| 41 |
[DB]
|
| 42 |
-๋์ ์ด๋ฆ '์นด์ด'๋ '์์ด๋ก kai๋ก ์ฝ๋ฆฌ์ ์ธ๊ณต์ง๋ฅ์ด๋ ์๋ฏธ์ด๋ค.'
|
| 43 |
-๋์ ์ด๋ฆ์ ์ง์ด์ค ์ฌ๋์ '์ฑ์ด K'์ด๋ค.
|
|
|
|
| 62 |
try:
|
| 63 |
response_text = await generate_response(message)
|
| 64 |
mention = message.author.mention
|
| 65 |
+
await send_long_message(message.channel, f"{mention}, {response_text}")
|
| 66 |
await self.text_to_speech_and_send(message.channel, response_text)
|
| 67 |
+
except Exception as e:
|
| 68 |
+
logging.error(f'Error in on_message: {e}')
|
| 69 |
finally:
|
| 70 |
self.is_processing = False
|
| 71 |
|
|
|
|
| 89 |
response = await loop.run_in_executor(None, lambda: hf_client.chat_completion(
|
| 90 |
messages, max_tokens=1000, stream=True, temperature=0.7, top_p=0.85))
|
| 91 |
|
| 92 |
+
full_response_text = ''.join(
|
| 93 |
+
str(part.choices[0].delta.content) for part in response
|
| 94 |
+
if part.choices and part.choices[0].delta and part.choices[0].delta.content is not None
|
| 95 |
+
)
|
| 96 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
| 97 |
return full_response_text # ์ง์ ์ ์ธ ๋ต๋ณ๋ง ๋ฐํ
|
| 98 |
|
|
|
|
| 103 |
await communicate.save(tmp_path)
|
| 104 |
return tmp_path
|
| 105 |
|
| 106 |
+
async def send_long_message(channel, message):
|
| 107 |
+
"""Discord ๋ฉ์์ง ๊ธธ์ด๊ฐ 2000์๋ฅผ ์ด๊ณผํ๋ ๊ฒฝ์ฐ, ์ด๋ฅผ ๋๋์ด ๋ณด๋
๋๋ค."""
|
| 108 |
+
if len(message) <= 2000:
|
| 109 |
+
await channel.send(message)
|
| 110 |
+
else:
|
| 111 |
+
parts = [message[i:i+2000] for i in range(0, len(message), 2000)]
|
| 112 |
+
for part in parts:
|
| 113 |
+
await channel.send(part)
|
| 114 |
+
|
| 115 |
if __name__ == "__main__":
|
| 116 |
discord_client = MyClient(intents=intents)
|
| 117 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|