Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,8 @@ import logging
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import InferenceClient
|
5 |
import os
|
|
|
|
|
6 |
|
7 |
# 로깅 설정
|
8 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
@@ -32,6 +34,7 @@ class MyClient(discord.Client):
|
|
32 |
response = await generate_response(message.content, history, system_message, 4000, 0.7, 0.95)
|
33 |
await message.channel.send(response)
|
34 |
|
|
|
35 |
# Hugging Face 추론 API를 사용하여 응답 생성
|
36 |
async def generate_response(user_input, history, system_message, max_tokens, temperature, top_p):
|
37 |
system_prefix = """
|
@@ -49,13 +52,13 @@ async def generate_response(user_input, history, system_message, max_tokens, tem
|
|
49 |
messages.append({"role": "assistant", "content": val[1]})
|
50 |
messages.append({"role": "user", "content": user_input})
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
|
60 |
# 디스코드 봇 인스턴스 생성 및 실행
|
61 |
discord_client = MyClient(intents=intents)
|
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import InferenceClient
|
5 |
import os
|
6 |
+
import asyncio
|
7 |
+
|
8 |
|
9 |
# 로깅 설정
|
10 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s', handlers=[logging.StreamHandler()])
|
|
|
34 |
response = await generate_response(message.content, history, system_message, 4000, 0.7, 0.95)
|
35 |
await message.channel.send(response)
|
36 |
|
37 |
+
|
38 |
# Hugging Face 추론 API를 사용하여 응답 생성
|
39 |
async def generate_response(user_input, history, system_message, max_tokens, temperature, top_p):
|
40 |
system_prefix = """
|
|
|
52 |
messages.append({"role": "assistant", "content": val[1]})
|
53 |
messages.append({"role": "user", "content": user_input})
|
54 |
|
55 |
+
# 동기 함수를 비동기로 처리하기 위한 래퍼 사용
|
56 |
+
loop = asyncio.get_event_loop()
|
57 |
+
response = await loop.run_in_executor(None, lambda: hf_client.chat_completion(messages, max_tokens=max_tokens, stream=False, temperature=temperature, top_p=top_p))
|
58 |
+
return response['choices'][0]['message']['content'] # 적절한 속성 사용
|
59 |
+
|
60 |
+
# 기존 코드는 유지
|
61 |
+
|
62 |
|
63 |
# 디스코드 봇 인스턴스 생성 및 실행
|
64 |
discord_client = MyClient(intents=intents)
|