Yosef Skolnick commited on
Commit
4e23fa8
·
1 Parent(s): 797a936

Fix citations

Browse files
Files changed (1) hide show
  1. services/openai_service.py +6 -7
services/openai_service.py CHANGED
@@ -9,7 +9,10 @@ try:
9
  import config
10
  from utils import format_context_for_openai
11
  except ImportError:
 
12
  print("Error: Failed to import config or utils in openai_service.py")
 
 
13
  raise SystemExit("Failed imports in openai_service.py")
14
 
15
  # --- Globals ---
@@ -183,15 +186,13 @@ async def extract_citations_with_openai(text: str) -> Set[str]:
183
  """
184
  Extract citation numbers from a response text using OpenAI.
185
  Returns a set of citation IDs as strings.
186
- Falls back to regex if OpenAI fails.
187
  """
188
  global openai_async_client
189
  ready, msg = get_openai_status()
190
  if not ready or openai_async_client is None or not text:
191
  print(f"OpenAI citation extraction failed: Client not ready - {msg}")
192
- # Fall back to regex
193
- import re
194
- return set(re.findall(r'מקור[\s\u00A0\u2000-\u200F\u2028-\u202F\u205F\u3000]*([0-9]+)', text))
195
 
196
  try:
197
  response = await openai_async_client.chat.completions.create(
@@ -212,6 +213,4 @@ async def extract_citations_with_openai(text: str) -> Set[str]:
212
  except Exception as e:
213
  print(f"Error during OpenAI citation extraction: {e}")
214
  traceback.print_exc()
215
- # Fall back to regex
216
- import re
217
- raise Exception(f"Failed to extract citations: {e}")
 
9
  import config
10
  from utils import format_context_for_openai
11
  except ImportError:
12
+ # More detailed error handling for better debugging
13
  print("Error: Failed to import config or utils in openai_service.py")
14
+ traceback.print_exc()
15
+ print("Current directory:", __file__)
16
  raise SystemExit("Failed imports in openai_service.py")
17
 
18
  # --- Globals ---
 
186
  """
187
  Extract citation numbers from a response text using OpenAI.
188
  Returns a set of citation IDs as strings.
189
+ Returns empty set if extraction fails.
190
  """
191
  global openai_async_client
192
  ready, msg = get_openai_status()
193
  if not ready or openai_async_client is None or not text:
194
  print(f"OpenAI citation extraction failed: Client not ready - {msg}")
195
+ return set()
 
 
196
 
197
  try:
198
  response = await openai_async_client.chat.completions.create(
 
213
  except Exception as e:
214
  print(f"Error during OpenAI citation extraction: {e}")
215
  traceback.print_exc()
216
+ return set()