fdaudens HF Staff commited on
Commit
ee5acca
·
1 Parent(s): 529342a

badrequest error fix

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -58,17 +58,23 @@ def sanitize_script(script: str) -> str:
58
 
59
  def generate_podcast_script(subject: str, steering_question: str | None = None) -> str:
60
  """Ask the LLM for a script of a podcast given by two hosts."""
 
 
 
61
  messages = [
62
  {"role": "system", "content": SYSTEM_PROMPT},
63
- {"role": "user", "content": f"""Here is the topic: it's the top trending paper on Hugging Face daily papers today. You will need to analyze it by bringing profound insights.\n{subject}"""},
64
  ]
65
  if steering_question and len(steering_question) > 0:
66
  messages.append({"role": "user", "content": f"You could focus on this question: {steering_question}"})
67
-
68
- response = client.chat_completion(
69
- messages,
70
- max_tokens=8156,
71
- )
 
 
 
72
  full_text = response.choices[0].message.content
73
  assert "[JANE]" in full_text
74
  dialogue_start_index = full_text.find("[JANE]")
 
58
 
59
  def generate_podcast_script(subject: str, steering_question: str | None = None) -> str:
60
  """Ask the LLM for a script of a podcast given by two hosts."""
61
+ # Limit subject length to avoid exceeding model context window
62
+ max_subject_length = 4000
63
+ safe_subject = subject[:max_subject_length]
64
  messages = [
65
  {"role": "system", "content": SYSTEM_PROMPT},
66
+ {"role": "user", "content": f"""Here is the topic: it's the top trending paper on Hugging Face daily papers today. You will need to analyze it by bringing profound insights.\n{safe_subject}"""},
67
  ]
68
  if steering_question and len(steering_question) > 0:
69
  messages.append({"role": "user", "content": f"You could focus on this question: {steering_question}"})
70
+ try:
71
+ response = client.chat_completion(
72
+ messages,
73
+ max_tokens=8156,
74
+ )
75
+ except Exception as e:
76
+ print(f"Error from chat_completion: {e}")
77
+ raise
78
  full_text = response.choices[0].message.content
79
  assert "[JANE]" in full_text
80
  dialogue_start_index = full_text.find("[JANE]")