Spaces:
Running
Running
Zeamays3427
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -109,25 +109,25 @@ def generate_suggestions(title, text, keywords):
|
|
109 |
Title: {title}
|
110 |
Text: {text}
|
111 |
"""
|
112 |
-
|
113 |
try:
|
114 |
-
#
|
115 |
response = client.chat.completions.create(
|
116 |
-
model="gpt-4", #
|
117 |
messages=[
|
118 |
-
{"role": "system", "content": "You are a helpful assistant specialized in fact-checking."},
|
119 |
-
{"role": "user", "content": prompt} #
|
120 |
],
|
121 |
-
max_tokens=
|
122 |
-
temperature=0.7
|
123 |
)
|
124 |
|
125 |
-
#
|
126 |
-
suggestions = response.choices[0].message
|
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
|