seawolf2357 commited on
Commit
bf8bf66
ยท
verified ยท
1 Parent(s): 23ecff0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
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
- prompt = system_message + user_input # ์ž…๋ ฅ๊ณผ ์‹œ์Šคํ…œ ๋ฉ”์‹œ์ง€๋ฅผ ๊ฒฐํ•ฉ
73
-
74
- response = openai.ChatCompletion.create(
75
- model="gpt-4o",
76
- messages=conversation_history,
77
- temperature=0.7,
78
- max_tokens=1000,
79
- top_p=1,
80
- frequency_penalty=0,
81
- presence_penalty=0
82
- )
83
-
84
- full_response_text = response.choices[0].message['content']
85
- logging.debug(f'Full model response: {full_response_text}')
 
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)