Skip to content

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.

MAX_STORED module-attribute

MAX_STORED = 50

EXAMPLE_CHARS module-attribute

EXAMPLE_CHARS = 600

COLUMN_CHARS module-attribute

COLUMN_CHARS = 300

MAX_COLUMNS module-attribute

MAX_COLUMNS = 80

DEFAULT_EXAMPLES module-attribute

DEFAULT_EXAMPLES = 3

_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é', 'à'}

_FENCE module-attribute

_FENCE = re.compile('^\\s*```[a-zA-Z0-9_-]*\\s*\\n?|\\n?```\\s*$')

default_path

default_path() -> str

examples_limit

examples_limit() -> int

How many corrected examples a prompt carries (DOCUMENTATION_ASSIST_EXAMPLES, 0 = none).

kind_of

kind_of(field: str) -> str

'description' or 'section:' from a form field id or a request field.

guess_language

guess_language(*texts: str) -> str

'fr' when the documentation already written is clearly French, else 'en'.

_cut

_cut(text, n: int) -> str

_example_block

_example_block(examples: List[dict]) -> str

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

clean_response(text) -> str

The generated text without markdown fences or quotes around it; empty raises ValueError.

_load

_load(path: str) -> dict

_store_key

_store_key(store: str) -> str

read_corrections

read_corrections(store: str, path: Optional[str] = None) -> List[dict]

The stored corrections of store (oldest first). Never raises.

add_corrections

add_corrections(store: str, entries: List[dict], path: Optional[str] = None) -> int

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.