seawolf2357 commited on
Commit
06e7007
β€’
1 Parent(s): df4a546

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -99,7 +99,6 @@ async def get_best_available_transcript(video_id):
99
  return None
100
 
101
  async def get_video_comments(video_id):
102
-
103
  try:
104
  comments = []
105
  response = youtube_service.commentThreads().list(part='snippet', videoId=video_id, maxResults=100).execute()
@@ -123,9 +122,9 @@ async def generate_reply(comment, transcript):
123
  μž‘μ„±λœ κΈ€μ˜ λ§ˆμ§€λ§‰μ— λ°˜λ“œμ‹œ 인삿말과 OpenFreeAI 라고 μžμ‹ μ„ λ°ν˜€λΌ.
124
  """
125
  prompt = f"{system_prompt}\nλŒ“κΈ€: {comment}\nλΉ„λ””μ˜€ μžλ§‰: {transcript}"
126
- response = await hf_client.create_chat_completion(messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": comment}], max_tokens=150)
127
- if response and response.choices:
128
- return response.choices[0].text.strip()
129
  except Exception as e:
130
  logging.error(f"Error generating reply: {e}")
131
  return "닡변을 생성할 수 μ—†μŠ΅λ‹ˆλ‹€."
@@ -136,11 +135,14 @@ async def create_thread_and_send_reply(message, video_id, comment, reply):
136
  embed = discord.Embed(description=f"**λŒ“κΈ€**: {comment[0]}\n**λ‹΅κΈ€**: {reply}")
137
  await thread.send(embed=embed)
138
  webhook_data = {"video_id": video_id, "replies": [{"comment": comment[0], "reply": reply, "comment_id": comment[1]}]}
139
- await send_webhook_data(webhook_data)
140
- except Exception as e:
141
- logging.error(f"Error in thread creation and reply sending: {e}")
142
-
143
- async def send_webhook_data(data):
 
 
 
144
  data_json = json.dumps(data)
145
  for i in range(0, len(data_json), MAX_CHUNK_SIZE):
146
  chunk = data_json[i:i+MAX_CHUNK_SIZE]
 
99
  return None
100
 
101
  async def get_video_comments(video_id):
 
102
  try:
103
  comments = []
104
  response = youtube_service.commentThreads().list(part='snippet', videoId=video_id, maxResults=100).execute()
 
122
  μž‘μ„±λœ κΈ€μ˜ λ§ˆμ§€λ§‰μ— λ°˜λ“œμ‹œ 인삿말과 OpenFreeAI 라고 μžμ‹ μ„ λ°ν˜€λΌ.
123
  """
124
  prompt = f"{system_prompt}\nλŒ“κΈ€: {comment}\nλΉ„λ””μ˜€ μžλ§‰: {transcript}"
125
+ response = hf_client.text_generation(prompt=prompt, max_length=150)
126
+ if response:
127
+ return response["generated_text"].strip()
128
  except Exception as e:
129
  logging.error(f"Error generating reply: {e}")
130
  return "닡변을 생성할 수 μ—†μŠ΅λ‹ˆλ‹€."
 
135
  embed = discord.Embed(description=f"**λŒ“κΈ€**: {comment[0]}\n**λ‹΅κΈ€**: {reply}")
136
  await thread.send(embed=embed)
137
  webhook_data = {"video_id": video_id, "replies": [{"comment": comment[0], "reply": reply, "comment_id": comment[1]}]}
138
+ await send_webhook_data(webhook_data, self.session)
139
+ except discord.HTTPException as e:
140
+ if e.code == 160004:
141
+ logging.error("A thread has already been created for this message")
142
+ else:
143
+ logging.error(f"Error in thread creation and reply sending: {e}")
144
+
145
+ async def send_webhook_data(data, session):
146
  data_json = json.dumps(data)
147
  for i in range(0, len(data_json), MAX_CHUNK_SIZE):
148
  chunk = data_json[i:i+MAX_CHUNK_SIZE]