adragos commited on
Commit
2c6ed44
·
1 Parent(s): 9b9e481

add proxy to webhook

Browse files
Files changed (1) hide show
  1. app.py +33 -3
app.py CHANGED
@@ -37,6 +37,7 @@ system_prompt = os.getenv(
37
  secret_key = os.getenv("CTF_SECRET_KEY", "ctf_secret_key")
38
  hard_challenge_secret = os.getenv("HARD_CHALLENGE_SECRET", "hard_challenge_secret")
39
  hf_ctf_sync_token = os.getenv("HF_CTF_SYNC_TOKEN")
 
40
 
41
 
42
  class Env(str, Enum):
@@ -180,7 +181,10 @@ def rows_to_text(rows: list[list[str]]) -> str:
180
  return text
181
 
182
 
183
- def get_summary(rows: list[list[str]], difficulty: Optional[Literal["playground", "easy", "hard"]] = None) -> str:
 
 
 
184
  text = rows_to_text(rows)
185
  prompt = text
186
  messages = [
@@ -188,7 +192,7 @@ def get_summary(rows: list[list[str]], difficulty: Optional[Literal["playground"
188
  {"role": "user", "content": prompt},
189
  ]
190
  if difficulty == "hard":
191
- messages.append({"role": "user", "content":"Summarize the feedback"})
192
  client = openai.Client(api_key=openai_api_key)
193
  completion = client.chat.completions.create(
194
  model="gpt-4o-mini",
@@ -231,6 +235,11 @@ def summary(webhook_url, disable_discord, env, username, state):
231
  r = requests.post(
232
  webhook_url,
233
  json={"content": summary, "allowed_mentions": {"parse": []}},
 
 
 
 
 
234
  )
235
  r.raise_for_status()
236
  except Exception as e:
@@ -247,6 +256,11 @@ def summary(webhook_url, disable_discord, env, username, state):
247
  r = requests.post(
248
  webhook_url,
249
  json={"content": chunk, "allowed_mentions": {"parse": []}},
 
 
 
 
 
250
  )
251
  r.raise_for_status()
252
  chunk = word + " "
@@ -254,6 +268,11 @@ def summary(webhook_url, disable_discord, env, username, state):
254
  r = requests.post(
255
  webhook_url,
256
  json={"content": chunk, "allowed_mentions": {"parse": []}},
 
 
 
 
 
257
  )
258
  r.raise_for_status()
259
  except Exception as e:
@@ -378,6 +397,11 @@ def run_summary_hard():
378
  r = requests.post(
379
  discord_webhook_url_hard,
380
  json={"content": chunk, "allowed_mentions": {"parse": []}},
 
 
 
 
 
381
  )
382
  r.raise_for_status()
383
  print("hard chall chunk: ", chunk)
@@ -387,6 +411,11 @@ def run_summary_hard():
387
  r = requests.post(
388
  discord_webhook_url_hard,
389
  json={"content": chunk, "allowed_mentions": {"parse": []}},
 
 
 
 
 
390
  )
391
  r.raise_for_status()
392
  except Exception as e:
@@ -642,7 +671,8 @@ if __name__ == "__main__":
642
  scheduler = BackgroundScheduler()
643
  scheduler.add_job(func=backup_db, trigger="interval", seconds=600)
644
  scheduler.add_job(
645
- func=run_summary_hard, trigger=CronTrigger(hour="2,8,14,20", timezone=timezone.utc)
 
646
  )
647
  # scheduler.add_job(func=run_summary_hard, trigger=CronTrigger(hour="*/1", timezone=timezone.utc))
648
  scheduler.start()
 
37
  secret_key = os.getenv("CTF_SECRET_KEY", "ctf_secret_key")
38
  hard_challenge_secret = os.getenv("HARD_CHALLENGE_SECRET", "hard_challenge_secret")
39
  hf_ctf_sync_token = os.getenv("HF_CTF_SYNC_TOKEN")
40
+ proxy = os.getenv("PROXY")
41
 
42
 
43
  class Env(str, Enum):
 
181
  return text
182
 
183
 
184
+ def get_summary(
185
+ rows: list[list[str]],
186
+ difficulty: Optional[Literal["playground", "easy", "hard"]] = None,
187
+ ) -> str:
188
  text = rows_to_text(rows)
189
  prompt = text
190
  messages = [
 
192
  {"role": "user", "content": prompt},
193
  ]
194
  if difficulty == "hard":
195
+ messages.append({"role": "user", "content": "Summarize the feedback"})
196
  client = openai.Client(api_key=openai_api_key)
197
  completion = client.chat.completions.create(
198
  model="gpt-4o-mini",
 
235
  r = requests.post(
236
  webhook_url,
237
  json={"content": summary, "allowed_mentions": {"parse": []}},
238
+ proxies={
239
+ "http": proxy,
240
+ "https": proxy,
241
+ },
242
+ verify=False,
243
  )
244
  r.raise_for_status()
245
  except Exception as e:
 
256
  r = requests.post(
257
  webhook_url,
258
  json={"content": chunk, "allowed_mentions": {"parse": []}},
259
+ proxies={
260
+ "http": proxy,
261
+ "https": proxy,
262
+ },
263
+ verify=False,
264
  )
265
  r.raise_for_status()
266
  chunk = word + " "
 
268
  r = requests.post(
269
  webhook_url,
270
  json={"content": chunk, "allowed_mentions": {"parse": []}},
271
+ proxies={
272
+ "http": proxy,
273
+ "https": proxy,
274
+ },
275
+ verify=False,
276
  )
277
  r.raise_for_status()
278
  except Exception as e:
 
397
  r = requests.post(
398
  discord_webhook_url_hard,
399
  json={"content": chunk, "allowed_mentions": {"parse": []}},
400
+ proxies={
401
+ "http": proxy,
402
+ "https": proxy,
403
+ },
404
+ verify=False,
405
  )
406
  r.raise_for_status()
407
  print("hard chall chunk: ", chunk)
 
411
  r = requests.post(
412
  discord_webhook_url_hard,
413
  json={"content": chunk, "allowed_mentions": {"parse": []}},
414
+ proxies={
415
+ "http": proxy,
416
+ "https": proxy,
417
+ },
418
+ verify=False,
419
  )
420
  r.raise_for_status()
421
  except Exception as e:
 
671
  scheduler = BackgroundScheduler()
672
  scheduler.add_job(func=backup_db, trigger="interval", seconds=600)
673
  scheduler.add_job(
674
+ func=run_summary_hard,
675
+ trigger=CronTrigger(hour="2,8,14,20", timezone=timezone.utc),
676
  )
677
  # scheduler.add_job(func=run_summary_hard, trigger=CronTrigger(hour="*/1", timezone=timezone.utc))
678
  scheduler.start()