Spaces:
Sleeping
Sleeping
Patryk Studzinski commited on
Commit 路
1569809
1
Parent(s): 48663e4
fix: Add optional attributes parameter to create_infill_prompt and update InfillItem schema
Browse files- app/domains/cars/prompts.py +9 -2
- app/main.py +1 -1
- app/schemas/schemas.py +1 -0
app/domains/cars/prompts.py
CHANGED
|
@@ -31,7 +31,7 @@ Na podstawie poni偶szych danych, utw贸rz kr贸tki, atrakcyjny opis marketingowy t
|
|
| 31 |
]
|
| 32 |
|
| 33 |
|
| 34 |
-
def create_infill_prompt(text_with_gaps: str, options: InfillOptions) -> list[dict]:
|
| 35 |
"""
|
| 36 |
Creates a simplified prompt for gap-filling.
|
| 37 |
Uses a direct list format to minimize token usage and instructions.
|
|
@@ -44,7 +44,14 @@ def create_infill_prompt(text_with_gaps: str, options: InfillOptions) -> list[di
|
|
| 44 |
"Wypisz wynik jako prost膮 list臋 numerowan膮."
|
| 45 |
)
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
{text_with_gaps}
|
| 49 |
|
| 50 |
Wypisz list臋 s艂贸w pasuj膮cych do luk (1., 2., ...):"""
|
|
|
|
| 31 |
]
|
| 32 |
|
| 33 |
|
| 34 |
+
def create_infill_prompt(text_with_gaps: str, options: InfillOptions, attributes: dict = None) -> list[dict]:
|
| 35 |
"""
|
| 36 |
Creates a simplified prompt for gap-filling.
|
| 37 |
Uses a direct list format to minimize token usage and instructions.
|
|
|
|
| 44 |
"Wypisz wynik jako prost膮 list臋 numerowan膮."
|
| 45 |
)
|
| 46 |
|
| 47 |
+
# Build context string from attributes if they exist
|
| 48 |
+
context_str = ""
|
| 49 |
+
if attributes:
|
| 50 |
+
attr_list = [f"{k.capitalize()}: {v}" for k, v in attributes.items() if v]
|
| 51 |
+
if attr_list:
|
| 52 |
+
context_str = "Dane pojazdu:\n" + ", ".join(attr_list) + "\n\n"
|
| 53 |
+
|
| 54 |
+
user_content = f"""{context_str}Tekst do uzupe艂nienia:
|
| 55 |
{text_with_gaps}
|
| 56 |
|
| 57 |
Wypisz list臋 s艂贸w pasuj膮cych do luk (1., 2., ...):"""
|
app/main.py
CHANGED
|
@@ -407,7 +407,7 @@ async def process_infill_item(
|
|
| 407 |
)
|
| 408 |
|
| 409 |
# Build prompt
|
| 410 |
-
chat_messages = create_infill_prompt(normalized_text, options)
|
| 411 |
|
| 412 |
# Generate
|
| 413 |
llm = await registry.get_model(model_name)
|
|
|
|
| 407 |
)
|
| 408 |
|
| 409 |
# Build prompt
|
| 410 |
+
chat_messages = create_infill_prompt(normalized_text, options, attributes=item.attributes)
|
| 411 |
|
| 412 |
# Generate
|
| 413 |
llm = await registry.get_model(model_name)
|
app/schemas/schemas.py
CHANGED
|
@@ -15,6 +15,7 @@ class InfillItem(BaseModel):
|
|
| 15 |
"""A single item (ad) with gaps to be filled."""
|
| 16 |
id: str = Field(..., description="Unique identifier for this item")
|
| 17 |
text_with_gaps: str = Field(..., description="Text containing [GAP:n] markers or ___ to fill")
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
class InfillOptions(BaseModel):
|
|
|
|
| 15 |
"""A single item (ad) with gaps to be filled."""
|
| 16 |
id: str = Field(..., description="Unique identifier for this item")
|
| 17 |
text_with_gaps: str = Field(..., description="Text containing [GAP:n] markers or ___ to fill")
|
| 18 |
+
attributes: Dict[str, Any] = Field(default_factory=dict, description="Optional context attributes (e.g. make, model)")
|
| 19 |
|
| 20 |
|
| 21 |
class InfillOptions(BaseModel):
|