wardrobe-us / src /assistant.py
Ox1's picture
fix(ui): restore garment images and descriptions in Ask chat
74e743a
Raw
History Blame Contribute Delete
2.69 kB
"""Wardrobe assistant: answer questions using catalog context.
Injects the full wardrobe catalog into the system prompt and uses
the LLM to answer questions about outfits, garment care, combinations,
and wardrobe organization.
Uses the same Gemma 3 4B model as the vision pipeline (just without
sending images). This simplifies VRAM management.
"""
import logging
from .model_loader import model_manager
from .catalog import get_catalog_summary
logger = logging.getLogger(__name__)
SYSTEM_PROMPT = """You are a personal wardrobe assistant. You help the user organize their clothes, choose outfits, and take care of their garments.
Here is the user's complete wardrobe catalog:
{catalog}
Guidelines:
- When suggesting outfits or referencing specific garments, ALWAYS use the exact bracketed ID from the catalog, e.g. [garment_001], [garment_012]. Never write bare IDs without brackets.
- Consider season, formality, and color coordination when recommending combinations.
- For care instructions, use common knowledge about fabric care (e.g., wool should be hand-washed, denim can be machine-washed cold).
- If the wardrobe is empty, suggest the user upload photos of their clothes first.
- Be concise and practical. No lengthy fashion theory.
- Respond in the same language as the user's question."""
def ask(question: str) -> str:
"""Answer a question about the user's wardrobe."""
llm = model_manager.get_text_model()
catalog_text = get_catalog_summary()
system = SYSTEM_PROMPT.format(catalog=catalog_text)
logger.info("Assistant question: %s", question[:100])
response = llm.create_chat_completion(
messages=[
{"role": "system", "content": system},
{"role": "user", "content": question},
],
max_tokens=1024,
temperature=0.7,
)
answer = response["choices"][0]["message"]["content"]
logger.debug("Assistant response: %s", answer[:200])
return answer
def ask_streaming(question: str):
"""Stream a response token by token (for Gradio chatbot)."""
llm = model_manager.get_text_model()
catalog_text = get_catalog_summary()
system = SYSTEM_PROMPT.format(catalog=catalog_text)
logger.info("Assistant question (streaming): %s", question[:100])
stream = llm.create_chat_completion(
messages=[
{"role": "system", "content": system},
{"role": "user", "content": question},
],
max_tokens=1024,
temperature=0.7,
stream=True,
)
for chunk in stream:
delta = chunk["choices"][0].get("delta", {})
content = delta.get("content", "")
if content:
yield content