Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -53,6 +53,7 @@ class MyClient(discord.Client):
|
|
53 |
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
54 |
)
|
55 |
|
|
|
56 |
async def generate_response(message):
|
57 |
global conversation_history
|
58 |
user_input = message.content
|
@@ -65,28 +66,32 @@ async def generate_response(message):
|
|
65 |
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ์ญ์์ค.
|
66 |
{user_mention}, DISCORD์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค.
|
67 |
"""
|
68 |
-
|
69 |
conversation_history.append({"role": "user", "content": user_input})
|
70 |
logging.debug(f'Conversation history updated: {conversation_history}')
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
86 |
|
87 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
88 |
return f"{user_mention}, {full_response_text}"
|
89 |
|
|
|
90 |
if __name__ == "__main__":
|
91 |
discord_client = MyClient(intents=intents)
|
92 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
|
|
|
|
|
53 |
isinstance(message.channel, discord.Thread) and message.channel.parent_id == SPECIFIC_CHANNEL_ID
|
54 |
)
|
55 |
|
56 |
+
|
57 |
async def generate_response(message):
|
58 |
global conversation_history
|
59 |
user_input = message.content
|
|
|
66 |
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ์ญ์์ค.
|
67 |
{user_mention}, DISCORD์์ ์ฌ์ฉ์๋ค์ ์ง๋ฌธ์ ๋ตํ๋ ์ด์์คํดํธ์
๋๋ค.
|
68 |
"""
|
69 |
+
# ๋ํ ์ด๋ ฅ ์
๋ฐ์ดํธ
|
70 |
conversation_history.append({"role": "user", "content": user_input})
|
71 |
logging.debug(f'Conversation history updated: {conversation_history}')
|
72 |
|
73 |
+
try:
|
74 |
+
response = openai.Completion.create(
|
75 |
+
engine="gpt-4o",
|
76 |
+
prompt=user_input,
|
77 |
+
max_tokens=1000,
|
78 |
+
temperature=0.7,
|
79 |
+
top_p=1,
|
80 |
+
frequency_penalty=0,
|
81 |
+
presence_penalty=0
|
82 |
+
)
|
83 |
+
full_response_text = response.choices[0].text.strip()
|
84 |
+
logging.debug(f'Full model response: {full_response_text}')
|
85 |
+
except Exception as e:
|
86 |
+
logging.error(f'Error during API call: {str(e)}')
|
87 |
+
full_response_text = "Sorry, there was an error processing your request."
|
88 |
|
89 |
conversation_history.append({"role": "assistant", "content": full_response_text})
|
90 |
return f"{user_mention}, {full_response_text}"
|
91 |
|
92 |
+
|
93 |
if __name__ == "__main__":
|
94 |
discord_client = MyClient(intents=intents)
|
95 |
discord_client.run(os.getenv('DISCORD_TOKEN'))
|
96 |
+
|
97 |
+
demo.launch(server_name="0.0.0.0", server_port=7890, inbrowser=True)
|