cyberandy commited on
Commit
3f3931e
·
verified ·
1 Parent(s): 73367c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -20
app.py CHANGED
@@ -102,7 +102,7 @@ else:
102
  """
103
  try:
104
  # Create the system message for ChatGPT
105
- prefix_messages = [{
106
  "role": "system",
107
  "content": '''You are an SEO expert specializing in structured data analysis. Your task is to create JSON-formatted reports about websites' structured data.
108
 
@@ -120,8 +120,7 @@ else:
120
  # Initialize OpenAI client with basic configuration
121
  client = OpenAI(
122
  api_key=openai_api_key,
123
- base_url="https://api.openai.com/v1",
124
- timeout=60.0 # 60 seconds timeout
125
  )
126
 
127
  # Construct messages for the chat API
@@ -132,7 +131,7 @@ else:
132
  if not _issues and len(_items) > 0:
133
  # Case 1: When there are NO issues but there ARE items
134
  template = """
135
- Based on the following data, create a JSON object with three parts:
136
  1. {advice} and schema classes: {items}
137
  2. Entities found: {topics}
138
  3. Technologies: {technologies}
@@ -142,8 +141,7 @@ else:
142
  "first": "Analysis of schema classes with classes marked in <i>italic</i>",
143
  "second": "Description of entities marked in <b>bold</b>",
144
  "third": "Description of technologies in <i>italic</i>"
145
- }}
146
- """
147
  prompt = PromptTemplate(
148
  template=template,
149
  input_variables=["advice", "items", "topics", "technologies"]
@@ -167,8 +165,7 @@ else:
167
  "first": "Notice about missing schema classes",
168
  "second": "Description of entities marked in <b>bold</b>",
169
  "third": "Description of technologies in <i>italic</i>"
170
- }}
171
- """
172
  prompt = PromptTemplate(
173
  template=template,
174
  input_variables=["topics", "technologies"]
@@ -193,8 +190,7 @@ else:
193
  "second": "Description of issues marked in <u>underline</u>",
194
  "third": "Description of entities marked in <b>bold</b>",
195
  "fourth": "Description of technologies in <i>italic</i>"
196
- }}
197
- """
198
  prompt = PromptTemplate(
199
  template=template,
200
  input_variables=["advice", "items", "topics", "issues", "technologies"]
@@ -214,9 +210,10 @@ else:
214
  # Make the API call with better error handling
215
  try:
216
  response = client.chat.completions.create(
217
- model="gpt-4o",
218
  messages=messages,
219
- temperature=0.2,
 
220
  )
221
  if hasattr(response.choices[0].message, 'content'):
222
  out = response.choices[0].message.content
@@ -224,9 +221,8 @@ else:
224
  out = "Error: No content in response"
225
  except Exception as e:
226
  error_msg = str(e)
227
- print(f"OpenAI API Error: {error_msg}") # Log the error for debugging
228
  if "proxies" in error_msg:
229
- # Handle proxy-related errors
230
  out = "Error: Proxy configuration issue. Please check your environment settings."
231
  else:
232
  out = f"Sorry, there was an error with the OpenAI API: {error_msg}"
@@ -235,12 +231,7 @@ else:
235
 
236
  except Exception as e:
237
  error_message = f"An unexpected error occurred: {str(e)}"
238
- print(error_message) # Log the error for debugging
239
- return error_message
240
-
241
- except Exception as e:
242
- error_message = f"An unexpected error occurred: {str(e)}"
243
- print(error_message) # Log the error for debugging
244
  return error_message
245
 
246
  # Call WooRank API to get the data (cached)
 
102
  """
103
  try:
104
  # Create the system message for ChatGPT
105
+ prefix_messages = [{
106
  "role": "system",
107
  "content": '''You are an SEO expert specializing in structured data analysis. Your task is to create JSON-formatted reports about websites' structured data.
108
 
 
120
  # Initialize OpenAI client with basic configuration
121
  client = OpenAI(
122
  api_key=openai_api_key,
123
+ base_url="https://api.openai.com/v1"
 
124
  )
125
 
126
  # Construct messages for the chat API
 
131
  if not _issues and len(_items) > 0:
132
  # Case 1: When there are NO issues but there ARE items
133
  template = """
134
+ Create a JSON object based on the following data:
135
  1. {advice} and schema classes: {items}
136
  2. Entities found: {topics}
137
  3. Technologies: {technologies}
 
141
  "first": "Analysis of schema classes with classes marked in <i>italic</i>",
142
  "second": "Description of entities marked in <b>bold</b>",
143
  "third": "Description of technologies in <i>italic</i>"
144
+ }}"""
 
145
  prompt = PromptTemplate(
146
  template=template,
147
  input_variables=["advice", "items", "topics", "technologies"]
 
165
  "first": "Notice about missing schema classes",
166
  "second": "Description of entities marked in <b>bold</b>",
167
  "third": "Description of technologies in <i>italic</i>"
168
+ }}"""
 
169
  prompt = PromptTemplate(
170
  template=template,
171
  input_variables=["topics", "technologies"]
 
190
  "second": "Description of issues marked in <u>underline</u>",
191
  "third": "Description of entities marked in <b>bold</b>",
192
  "fourth": "Description of technologies in <i>italic</i>"
193
+ }}"""
 
194
  prompt = PromptTemplate(
195
  template=template,
196
  input_variables=["advice", "items", "topics", "issues", "technologies"]
 
210
  # Make the API call with better error handling
211
  try:
212
  response = client.chat.completions.create(
213
+ model="gpt-4",
214
  messages=messages,
215
+ temperature=0.7,
216
+ max_tokens=1500
217
  )
218
  if hasattr(response.choices[0].message, 'content'):
219
  out = response.choices[0].message.content
 
221
  out = "Error: No content in response"
222
  except Exception as e:
223
  error_msg = str(e)
224
+ print(f"OpenAI API Error: {error_msg}")
225
  if "proxies" in error_msg:
 
226
  out = "Error: Proxy configuration issue. Please check your environment settings."
227
  else:
228
  out = f"Sorry, there was an error with the OpenAI API: {error_msg}"
 
231
 
232
  except Exception as e:
233
  error_message = f"An unexpected error occurred: {str(e)}"
234
+ print(error_message)
 
 
 
 
 
235
  return error_message
236
 
237
  # Call WooRank API to get the data (cached)