Skip to content

tdfs4ds.plugins

tdfs4ds.plugins

What a plugin skill needs from tdfs4ds, as a public API (0.3.6.17).

A plugin skill is a folder of TDFS4DS_SKILLS_FOLDER holding a SKILL.md and a skill.py that defines node(state). Code shared by several plugins goes in a _lib folder next to them (from _lib.helpers import x); it is not listed as a skill.

  • :func:llm_json: a language-model call returning JSON, through whatever constraint the endpoint honours;
  • :func:run_sql: a statement on the session's connection, as a frame, binary columns intact;
  • :func:chart_payload: what a chart answer returns (:mod:tdfs4ds.plotting);
  • :func:parse_period: the period a question names, with today read from the database clock.

_OFFSET_RE module-attribute

_OFFSET_RE = re.compile('\\d\\s*(?:Z|[+-]\\d{2}:?\\d{2})\\b')

_TIME_RE module-attribute

_TIME_RE = re.compile('\\b\\d{1,2}:\\d{2}\\b')

_TODAY_RE module-attribute

_TODAY_RE = re.compile("\\b(today|aujourd['’]hui)\\b", re.IGNORECASE)

_YESTERDAY_RE module-attribute

_YESTERDAY_RE = re.compile('\\b(yesterday|hier)\\b', re.IGNORECASE)

chart_payload

chart_payload(result: dict) -> Optional[dict]

{"title", "html", "height"} for the chat (the shape MCP charts use).

llm_json

llm_json(system_prompt: str, user_prompt: str, *, schema: Optional[dict] = None, expect=None, default=None, skill_name: str = 'plugin')

Ask the instruct model for JSON. Returns the parsed reply, else default (the failure is logged).

Parameters:

Name Type Description Default
schema Optional[dict]

JSON Schema of the reply, sent by the mechanism the endpoint honours (STRUCTURED_OUTPUT_METHOD); None sends no constraint.

None
expect

list or dict: a reply of another shape returns default.

None
skill_name str

the name in the logs and in the token count.

'plugin'

run_sql

run_sql(sql: str, params=None) -> pd.DataFrame

Run a statement on the session's teradataml connection (one session: a volatile table created by one call is seen by the next) and return its rows as a frame.

Values are returned as the driver gives them, so a BYTE or BLOB column stays bytes. A statement with no result set returns an empty frame. A database error raises. Not for a background thread: teradataml shares one connection per process.

_zone

_zone(timezone)

A tzinfo for timezone (a name or a tzinfo).

_bound

_bound(value: str, zone, *, upper: bool, question: str) -> _dt.datetime

A window bound as an aware datetime in zone. A date with no time covers its whole day and a YYYY-MM its whole month, so an upper bound is the start of the next one (half-open).

_db_now_in

_db_now_in(zone, now) -> _dt.datetime

parse_period

parse_period(question: str, timezone='UTC', *, now: Optional[datetime] = None) -> Optional[dict]

The period question names: {"start", "end", "how"}, else None.

start and end are aware datetimes in timezone, half-open (end is excluded); None when the question gives no such bound ("until March" has no start). how is dates (written dates), relative ("last 7 days", "les 3 derniers mois") or day (today, yesterday). A date written without an offset is read in timezone. "Now" and "today" come from the database clock (now replaces it), so they agree with the data. A numeric range ("between 10 and 20") is no period.

examples_path

examples_path(name: str = 'plugin_skills')

The folder of the example name shipped with the package (a pathlib.Path).

examples_path('plugin_skills') is a complete plugin folder (_lib and period_counter): copy it, or point TDFS4DS_SKILLS_FOLDER at it to try it.