Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,85 +1,43 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
|
|
|
| 3 |
import os
|
| 4 |
-
|
| 5 |
-
import
|
| 6 |
-
import subprocess
|
| 7 |
-
|
| 8 |
-
# ๋ก๊น
์ค์
|
| 9 |
-
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
| 10 |
-
|
| 11 |
-
# ์ธํ
ํธ ์ค์
|
| 12 |
-
intents = discord.Intents.default()
|
| 13 |
-
intents.message_content = True
|
| 14 |
-
intents.messages = True
|
| 15 |
-
intents.guilds = True
|
| 16 |
-
intents.guild_messages = True
|
| 17 |
-
|
| 18 |
-
# ์ถ๋ก API ํด๋ผ์ด์ธํธ ์ค์
|
| 19 |
-
hf_client = InferenceClient("meta-llama/Meta-Llama-3-70B-Instruct", token=os.getenv("HF_TOKEN"))
|
| 20 |
-
|
| 21 |
-
# ํน์ ์ฑ๋ ID
|
| 22 |
-
SPECIFIC_CHANNEL_ID = int(os.getenv("DISCORD_CHANNEL_ID"))
|
| 23 |
-
|
| 24 |
-
# ๋ํ ํ์คํ ๋ฆฌ๋ฅผ ์ ์ฅํ ์ ์ญ ๋ณ์
|
| 25 |
-
conversation_history = []
|
| 26 |
-
|
| 27 |
-
class MyClient(discord.Client):
|
| 28 |
-
def __init__(self, *args, **kwargs):
|
| 29 |
-
super().__init__(*args, **kwargs)
|
| 30 |
-
self.is_processing = False
|
| 31 |
-
|
| 32 |
-
async def on_message(self, message):
|
| 33 |
-
if message.author == self.user:
|
| 34 |
-
return
|
| 35 |
-
if not self.is_message_in_specific_channel(message):
|
| 36 |
-
return
|
| 37 |
-
if self.is_processing:
|
| 38 |
-
return
|
| 39 |
-
self.is_processing = True
|
| 40 |
-
try:
|
| 41 |
-
response = await generate_response(message)
|
| 42 |
-
await message.channel.send(response)
|
| 43 |
-
finally:
|
| 44 |
-
self.is_processing = False
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
| 50 |
-
)
|
| 51 |
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
user_mention = message.author.mention
|
| 57 |
-
system_message = f"{user_mention}, DISCORD์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
|
| 58 |
-
system_prefix = """
|
| 59 |
-
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ์ญ์์ค.
|
| 60 |
-
"""
|
| 61 |
-
conversation_history.append({"role": "user", "content": user_input})
|
| 62 |
-
logging.debug(f'Conversation history updated: {conversation_history}')
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
if part.choices and part.choices[0].delta and part.choices[0].delta.content:
|
| 75 |
-
full_response.append(part.choices[0].delta.content)
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import pandas as pd
|
| 4 |
import os
|
| 5 |
+
import pyarrow.parquet as pq
|
| 6 |
+
import discord
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Discord ๋ด ํ ํฐ ๋ฐ ์ฑ๋ I ์ค์
|
| 9 |
+
discordtoken = "MI2Mk0zQ3czc0Mz4Mw.Glf6.2bSeer-q5jHVnClSe1wsP0IHpVyIdxGaYac"
|
| 10 |
+
discordchannelid = 1261896610506604564
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Discord ํด๋ผ์ด์ธํธ ์์ฑ
|
| 13 |
+
client = discord.Client()
|
| 14 |
|
| 15 |
+
def respondtodiscord(message):
|
| 16 |
+
# ๋ฉ์์ง ์ ์ก์ ์ํ Discord API ์๋ํฌ์ธํธ
|
| 17 |
+
url = f"https://discord.com/api/v9/channels/{discordchannelid}/messages"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# ๋ฉ์์ง ์ ์ก ๋ฐ์ดํฐ
|
| 20 |
+
data = {
|
| 21 |
+
"content": message
|
| 22 |
+
}
|
| 23 |
|
| 24 |
+
# Discord API ์ธ์ฆ ํค๋
|
| 25 |
+
headers = {
|
| 26 |
+
"Authorization": discordtoken
|
| 27 |
+
}
|
| 28 |
|
| 29 |
+
try:
|
| 30 |
+
# ๋ฉ์์ง ์ ์ก
|
| 31 |
+
response = requests.post(url, headers=headers, json=data)
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
if response.statuscode == 200:
|
| 34 |
+
print("๋ฉ์์ง ์ ์ก ์ฑ๊ณต")
|
| 35 |
+
else:
|
| 36 |
+
print(f"๋ฉ์์ง ์ ์ก ์คํจ: {response.statuscode}")
|
| 37 |
|
| 38 |
+
except Exception as e:
|
| 39 |
+
print(f"์๊ธฐ์น ๋ชปํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}")
|
| 40 |
|
| 41 |
+
def getanswer(question):
|
| 42 |
+
matchinganswer = df[df['question'] == question]['answer'].values
|
| 43 |
+
return matching
|