beetlebug▾
/

ztcl::code digest

Gives the answer of a cheap model to a question about a text.

ztcl::code digest ?-q QUESTION? ?-words N? TEXT

Description

Sends TEXT and QUESTION to a model and gives its answer in N words (60) or fewer. With no -q, the question asks what ran, what failed, and where. The system text tells the model to use only the facts of the text, to copy paths, line numbers, and messages exactly, and to answer "not in the text" when the text has no answer.

The backend is claude (claude -p with the model claude-sonnet-5-5) when the environment has CLAUDECODE or claude is on the PATH, then codex (codex exec), and then http, a chat endpoint of the OpenAI API such as llama-server. ZTCL_CODE_AGENT names the backend, ZTCL_CODE_MODEL sets its model, and ZTCL_CODE_LLM sets the URL of http and picks it. A text of more than 240,000 characters goes as its start and its end.

Returns

The answer.

Examples

Each example of this page runs after package require ztcl::code # A folder with three files, outside a git tree. set dir /tmp/ztcl-ref-code-[pid] file delete -force $dir file mkdir $dir cd $dir proc put {path text} { set ch [open $path w] puts -nonewline $ch $text close $ch } put a.zig "const std = @import(\"std\");\n\npub const Point = struct {\n x: i32,\n\n pub fn len(p: Point) i32 {\n return p.x;\n }\n};\n" put b.txt "one\ntwo\ntwo\n" put c.md "# Title\n\n## Part\n\ntext\n" # The tests use no model. set ::ztcl::code::backend {http ""} set ::ztcl::code::llm_url http://127.0.0.1:9/v1/chat/completions .

% catch {ztcl::code digest x}
1

Errors

% ztcl::code digest x
no model server at 127.0.0.1:9 (couldn't open socket: connection refused). Start llama-server, or set ZTCL_CODE_LLM.
-errorcode ZTCL CODE LLM

% ztcl::code digest
digest ?-q QUESTION? ?-words N? TEXT
-errorcode ZTCL CODE USAGE

Facts

Capability
file. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.2