tdfs4ds.serve.doc_assist¶
tdfs4ds.serve.doc_assist
¶
Suggest a missing description or section with the instruct model (admin app, Objects > Edit).
Pure helpers, no database and no LLM call here: the prompt builders, the response cleaning,
the language guess and the small store of corrected suggestions. panels.doc_assist_suggest
makes the call and panels.doc_assist_record (inside the confirmed edit) keeps the
corrections.
Corrections: when the person confirms a text that started as a suggestion and changed it,
the pair (suggestion, final text) is kept in ~/.tdfs4ds/assist_corrections.json, per store
(database name), 50 entries at most, newest last. The last N (tdfs4ds.DOCUMENTATION_ASSIST_EXAMPLES,
default 3, 0 = off) of the same kind go into the next prompts as examples. No database table.
_FRENCH
module-attribute
¶
_FRENCH = {'le', 'la', 'les', 'des', 'une', 'un', 'est', 'sont', 'pour', 'dans', 'avec', 'par', 'du', 'de', 'et', 'qui', 'que', 'sur', 'au', 'aux', 'ce', 'cette', 'ces', 'chaque', 'client', 'montant', 'nombre', 'ligne', 'où', 'été', 'à'}
examples_limit
¶
How many corrected examples a prompt carries (DOCUMENTATION_ASSIST_EXAMPLES, 0 = none).
kind_of
¶
'description' or 'section:
guess_language
¶
'fr' when the documentation already written is clearly French, else 'en'.
select_examples
¶
select_examples(session: Optional[List[dict]], stored: Optional[List[dict]], kind: str, limit: Optional[int] = None) -> List[dict]
The most recent corrected examples of kind: this form's own first, then the stored ones.
Returned oldest first (the newest is the last, nearest the question).
build_prompt
¶
build_prompt(field: str, *, object_name: str, object_kind: str, language: str = 'en', description: str = '', columns: Optional[Dict[str, str]] = None, sections: Optional[Dict[str, str]] = None, entity_columns: Optional[List[str]] = None, parents: Optional[Dict[str, str]] = None, examples: Optional[List[dict]] = None) -> Tuple[str, str]
(system, user) prompt for a missing description (DESCRIPTION) or SECTION:<NAME>.
clean_response
¶
The generated text without markdown fences or quotes around it; empty raises ValueError.
read_corrections
¶
The stored corrections of store (oldest first). Never raises.
add_corrections
¶
Append entries (kind, object_kind, suggestion, final), keep the last 50, write atomically.
Fail-open: returns the number kept, 0 on any failure.
corrections_to_record
¶
corrections_to_record(suggested: Dict[str, str], changes: Dict[str, str], object_kind: str) -> List[dict]
Pairs worth keeping: a suggested field the person confirmed with a text that differs.