mojakob commited on
Commit
90347ee
·
verified ·
1 Parent(s): e388473

Update Chatbot_new.py

Browse files
Files changed (1) hide show
  1. Chatbot_new.py +16 -15
Chatbot_new.py CHANGED
@@ -383,36 +383,37 @@ def generate_internal_external_options(chat_history, vignette, user_state):
383
  Use simple, but neutral and professional language suitable for a psychological assessment.
384
  """
385
 
386
- response = openai.chat.completions.create(
387
- model="gpt-4o-mini",
388
- temperature=0.3,
389
- messages=[
390
- {"role": "system", "content": "You are assisting in generating attribution options based on a given scenario for a psychological assessment. Directly address the user. Present a single brief sentence for each option."},
391
- {"role": "user", "content": prompt},
392
- ],
393
- )
 
394
  content = response.choices[0].message.content.strip()
395
  print(f"Raw internal_external_options response: {content}") # Logging
396
-
397
  # Split the response into lines
398
  lines = content.split('\n')
399
-
400
  # Filter lines that start with "A:" or "B:"
401
  options = [line.strip() for line in lines if line.strip().startswith(("A:", "B:"))]
402
-
403
  # If more than 2 options are present, trim the list to the first two
404
  if len(options) > 2:
405
  options = options[:2]
406
-
407
  # If fewer than 2 options are present, handle accordingly (e.g., add placeholders)
408
  while len(options) < 2:
409
  options.append("Option missing due to system error.")
410
-
411
  # Join the options into a single string separated by newlines
412
  options_text = "\n".join(options)
413
-
414
  return options_text
415
-
416
  except Exception as e:
417
  print(f"Error generating internal_external options: {e}")
418
  return "Option missing due to system error.\nOption missing due to system error."
 
383
  Use simple, but neutral and professional language suitable for a psychological assessment.
384
  """
385
 
386
+ try:
387
+ response = openai.chat.completions.create(
388
+ model="gpt-4o-mini",
389
+ temperature=0.3,
390
+ messages=[
391
+ {"role": "system", "content": "You are assisting in generating attribution options based on a given scenario for a psychological assessment. Directly address the user. Present a single brief sentence for each option."},
392
+ {"role": "user", "content": prompt},
393
+ ],
394
+ )
395
  content = response.choices[0].message.content.strip()
396
  print(f"Raw internal_external_options response: {content}") # Logging
397
+
398
  # Split the response into lines
399
  lines = content.split('\n')
400
+
401
  # Filter lines that start with "A:" or "B:"
402
  options = [line.strip() for line in lines if line.strip().startswith(("A:", "B:"))]
403
+
404
  # If more than 2 options are present, trim the list to the first two
405
  if len(options) > 2:
406
  options = options[:2]
407
+
408
  # If fewer than 2 options are present, handle accordingly (e.g., add placeholders)
409
  while len(options) < 2:
410
  options.append("Option missing due to system error.")
411
+
412
  # Join the options into a single string separated by newlines
413
  options_text = "\n".join(options)
414
+
415
  return options_text
416
+
417
  except Exception as e:
418
  print(f"Error generating internal_external options: {e}")
419
  return "Option missing due to system error.\nOption missing due to system error."