Zeamays3427 commited on
Commit
c9a08b3
·
verified ·
1 Parent(s): 8bac67e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -109,25 +109,25 @@ def generate_suggestions(title, text, keywords):
109
  Title: {title}
110
  Text: {text}
111
  """
112
-
113
  try:
114
- # Call OpenAI's chat completion method using GPT-4 model
115
  response = client.chat.completions.create(
116
- model="gpt-4", # Using the GPT-4 model
117
  messages=[
118
- {"role": "system", "content": "You are a helpful assistant specialized in fact-checking."}, # System role definition
119
- {"role": "user", "content": prompt} # User input (the constructed prompt)
120
  ],
121
- max_tokens=4000, # Set the maximum token limit to 4000
122
- temperature=0.7, # Controls the randomness in the generated text
123
  )
124
 
125
- # Extract and clean the suggestions from the API response
126
- suggestions = response.choices[0].message["content"].strip()
127
-
128
  except Exception as e:
129
  # If there's an error, set a default error message and print the exception details for debugging
130
- suggestions = "Unable to generate suggestions at this time."
131
  print(f"Error generating suggestions: {e}") # Debug: print the error details to the console
132
 
133
  return suggestions
 
109
  Title: {title}
110
  Text: {text}
111
  """
112
+
113
  try:
114
+ # Use OpenAI GPT-4 API to generate suggestions using chat completion
115
  response = client.chat.completions.create(
116
+ model="gpt-4", # Use the GPT-4 model
117
  messages=[
118
+ {"role": "system", "content": "You are a helpful assistant specialized in fact-checking."},
119
+ {"role": "user", "content": prompt} # Pass the constructed prompt as user input
120
  ],
121
+ max_tokens=1000, # Set the maximum number of tokens
122
+ temperature=0.7 # Control the diversity of the generated text
123
  )
124
 
125
+ # Correctly access the generated suggestions from the API response
126
+ suggestions = response.choices[0].message.content.strip()
127
+
128
  except Exception as e:
129
  # If there's an error, set a default error message and print the exception details for debugging
130
+ suggestions = f"Unable to generate suggestions at this time. Error: {str(e)}"
131
  print(f"Error generating suggestions: {e}") # Debug: print the error details to the console
132
 
133
  return suggestions