Patryk Studzinski commited on
Commit
a63a522
1 Parent(s): 0dfa1e4

Revert to working prompt, remove broken fallback

Browse files
Files changed (2) hide show
  1. app/domains/cars/prompts.py +19 -14
  2. app/main.py +1 -30
app/domains/cars/prompts.py CHANGED
@@ -34,7 +34,8 @@ Na podstawie poni偶szych danych, utw贸rz kr贸tki, atrakcyjny opis marketingowy t
34
  def create_infill_prompt(text_with_gaps: str, options: InfillOptions) -> list[dict]:
35
  """
36
  Creates the chat prompt for gap-filling in car ads.
37
- Uses function-call format to force structured JSON output.
 
38
 
39
  Args:
40
  text_with_gaps: Ad text with [GAP:n] markers
@@ -46,27 +47,31 @@ def create_infill_prompt(text_with_gaps: str, options: InfillOptions) -> list[di
46
  lang_instruction = "po polsku" if options.language == "pl" else "in English"
47
 
48
  system_content = f"""Jeste艣 ekspertem od uzupe艂niania tekst贸w og艂osze艅 samochodowych.
49
- Zawsze odpowiadasz TYLKO prawid艂owym JSON-em, bez 偶adnych innych tekst贸w."""
50
-
51
- # More direct instruction with explicit filling examples
52
- user_content = f"""ZADANIE: Uzupe艂nij luki w og艂oszeniu samochodowym {lang_instruction}.
53
 
54
- TEKST:
55
- {text_with_gaps}
 
56
 
57
- INSTRUKCJE:
58
- 1. Zast膮p KA呕DY [GAP:n] rzeczywistym s艂owem/fraz膮 (nie zostawiaj [GAP:n] w tek艣cie!)
59
- 2. Pami臋taj o polskiej gramatyce (deklinacja)
60
- 3. Dla ka偶dej luki podaj {options.top_n_per_gap} alternatywne s艂owa
 
61
 
62
- ODPOWIED殴 - TYLKO JSON:
63
  {{
64
- "filled_text": "tekst z uzupe艂nionymi lukami (BEZ [GAP:n])",
65
  "gaps": [
66
- {{"index": 1, "choice": "s艂owo1", "alternatives": ["alt1", "alt2"]}}
67
  ]
68
  }}"""
69
 
 
 
 
 
 
 
70
  return [
71
  {"role": "system", "content": system_content},
72
  {"role": "user", "content": user_content}
 
34
  def create_infill_prompt(text_with_gaps: str, options: InfillOptions) -> list[dict]:
35
  """
36
  Creates the chat prompt for gap-filling in car ads.
37
+
38
+ The LLM must return strict JSON with filled text and per-gap choices.
39
 
40
  Args:
41
  text_with_gaps: Ad text with [GAP:n] markers
 
47
  lang_instruction = "po polsku" if options.language == "pl" else "in English"
48
 
49
  system_content = f"""Jeste艣 ekspertem od uzupe艂niania tekst贸w og艂osze艅 samochodowych.
 
 
 
 
50
 
51
+ ZADANIE:
52
+ Uzupe艂nij luki oznaczone jako [GAP:n] naturalnymi i gramatycznie poprawnymi s艂owami {lang_instruction}.
53
+ Ka偶da luka to jedno s艂owo lub kr贸tka fraza (1-4 s艂owa).
54
 
55
+ WA呕NE:
56
+ 1. Rzeczywi艣cie uzupe艂nij luki - nie zwracaj tekstu z [GAP:n]!
57
+ 2. Stosuj polskie przypadki gramatyczne (deklinacja)
58
+ 3. Zwracaj TYLKO JSON bez 偶adnych komentarzy
59
+ 4. Dla ka偶dej luki podaj {options.top_n_per_gap} alternatywnych s艂贸w
60
 
61
+ FORMAT JSON:
62
  {{
63
+ "filled_text": "kompletny tekst bez 偶adnych [GAP:n]",
64
  "gaps": [
65
+ {{"index": 1, "choice": "s艂owo_1", "alternatives": ["alternatywa1", "alternatywa2"]}}
66
  ]
67
  }}"""
68
 
69
+ user_content = f"""Uzupe艂nij luki w tym og艂oszeniu samochodowym:
70
+
71
+ {text_with_gaps}
72
+
73
+ Odpowied藕 - tylko JSON!"""
74
+
75
  return [
76
  {"role": "system", "content": system_content},
77
  {"role": "user", "content": user_content}
app/main.py CHANGED
@@ -422,36 +422,7 @@ async def process_infill_item(
422
  parsed = parse_infill_json(raw_output)
423
 
424
  if not parsed:
425
- # JSON parsing failed - try to extract fills from the raw output
426
- # Model might have filled the text without JSON wrapper
427
- print(f"[INFILL] JSON parsing failed, attempting fallback extraction")
428
- print(f"[INFILL] Raw output: {raw_output[:300]}")
429
-
430
- # If raw output contains the text with gaps filled (no [GAP:n]),
431
- # it might be a valid response without JSON
432
- if "[GAP:" not in raw_output:
433
- # Model filled the gaps! Extract by comparing with original
434
- filled_text = raw_output.strip()
435
-
436
- # Try to build gaps list from what we know
437
- gap_fills = []
438
- for i, gap in enumerate(gaps, 1):
439
- gap_fills.append(GapFill(
440
- index=i,
441
- marker=gap.marker,
442
- choice="(model filled)",
443
- alternatives=[]
444
- ))
445
-
446
- return InfillResult(
447
- id=item.id,
448
- status="ok",
449
- filled_text=filled_text,
450
- gaps=gap_fills,
451
- error=None
452
- )
453
-
454
- # Otherwise it's a real error
455
  return InfillResult(
456
  id=item.id,
457
  status="error",
 
422
  parsed = parse_infill_json(raw_output)
423
 
424
  if not parsed:
425
+ # JSON parsing failed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
426
  return InfillResult(
427
  id=item.id,
428
  status="error",