Spaces:
Sleeping
Sleeping
|
Download docs/md/design/core/prompt_builder.md from thanhnv2323/humanize-text-python: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/docs/md/design/core/prompt_builder.md
- Command line
-
hf download hf://spaces/thanhnv2323/humanize-text-python/docs/md/design/core/prompt_builder.md
-
curl -L -o prompt_builder.md https://huggingface.co/spaces/thanhnv2323/humanize-text-python/resolve/main/docs/md/design/core/prompt_builder.md
1.8 kB
Core: PromptBuilder
Code: adsp/core/prompt_builder/__init__.py, adsp/core/prompt_builder/system_prompt.py
Purpose
PromptBuilder constructs the final prompt sent to a persona model by combining:
- persona rules/traits
- retrieved grounding context
- user question
Responsibilities
- Retrieve persona metadata from
PersonaRegistry - Convert persona profiles into a system prompt (including reasoning traits when present)
- Assemble a single string prompt for the model
Public API
build(persona_id: str, query: str, context: str) -> str
Inputs
persona_id: persona to load from the registryquery: normalized user questioncontext: retrieval grounding text (already formatted)
Output
- String prompt:
- system prompt +
Context:+Question:
- system prompt +
Internal logic (current)
persona = PersonaRegistry.get(persona_id)system_prompt = _system_prompt_for_persona(persona)- Returns:
{system_prompt}\n\nContext:\n{context}\n\nQuestion:\n{query}
Persona profile handling
_system_prompt_for_persona() supports:
PersonaProfileModel(Pydantic) →persona_to_system_prompt(profile)dict:- if it looks like a profile with reasoning traits, attempt to validate as
PersonaProfileModel - else fallback to
persona["preamble"]or"You are an AI persona."
- if it looks like a profile with reasoning traits, attempt to validate as
Key dependencies / technologies
pydantic(ValidationError)adsp/data_pipeline/schema.py(PersonaProfileModel)PersonaRegistry(adsp/core/persona_registry/__init__.py)
Notes / production hardening
- Return structured prompt objects (
{system, user, context}) rather than concatenated strings to better support chat-based LLM APIs. - Add citation formatting to ensure explainability requirements are met (page refs + doc ids).