LLM

Configure an LLM for Pro, Pro Plus, or Admin accounts.

Syntax

LLM(system_prompt, *, timeout_ms=10000, max_retries=1)

Constructor parameters

NameDescription
system_promptString
Instructions sent with each call. A non-blank string of at most 4,000 UTF-16 units.
Required · Positional or named
No default
timeout_msInt
Request budget in milliseconds, from 1,000 to 30,000. Includes image preparation, retries and model fallback.
Optional · Keyword only
Default: 10000
max_retriesInt
Additional attempts for temporary provider failures, from 0 to 2.
Optional · Keyword only
Default: 1

Returns

Example

Not documented

Methods

4 methods

LLM.chat

Send text to the model provider and wait for a reply. Calls are independent and share your account quota across all macros. If the free model hits its rate limit, CogniTab can switch to a low-cost model within the same call.

Syntax

llm.chat(input, *, temperature=None, top_p=None, top_k=None, min_p=None, frequency_penalty=None, presence_penalty=None, repetition_penalty=None, seed=None, max_tokens=8192, stop=None, parallel=False)

Parameters

NameDescription
inputString
Text for this call. A non-blank string of at most 4,000 UTF-16 units.
Required · Positional or named
No default
temperatureFloat?
Sampling randomness from 0 to 2. Higher values generally produce more varied replies.
Optional · Keyword only
Default: None
top_pFloat?
Cumulative probability cutoff from 0 to 1.
Optional · Keyword only
Default: None
top_kInt?
Maximum number of token candidates at each step. Use 0 for no cutoff.
Optional · Keyword only
Default: None
min_pFloat?
Relative token probability cutoff from 0 to 1.
Optional · Keyword only
Default: None
frequency_penaltyFloat?
Frequency penalty from -2 to 2.
Optional · Keyword only
Default: None
presence_penaltyFloat?
Presence penalty from -2 to 2.
Optional · Keyword only
Default: None
repetition_penaltyFloat?
Repetition penalty from 0 to 2.
Optional · Keyword only
Default: None
seedInt?
Optional signed 32-bit seed. Omit to let sampling vary.
Optional · Keyword only
Default: None
max_tokensInt
Maximum generated tokens, including reasoning and the final reply, from 1 to 8192.
Optional · Keyword only
Default: 8192
stoplist[String]?
One to four stop sequences, each 1 to 128 UTF-16 units.
Optional · Keyword only
Default: None
parallelBoolean
True starts one background request per script. Returns whether it was accepted. Read the result with poll().
Optional · Keyword only
Default: False

Returns

dict | Boolean — The result dict contains ok, text, and error. On failure text is empty and error contains a code. With parallel=True the call returns True or False.

Example

# Generate a short reply
llm = LLM("Reply in one short English sentence.", timeout_ms=30000, max_retries=0)
reply = llm.chat("good catch", temperature=0.9, max_tokens=8192)
if reply["ok"]:
    print(reply["text"])
else:
    print(reply["error"])

LLM.decision

Ask a yes/no question. Sends the prompt, text and optional image template to the model provider.

Syntax

llm.decision(input, *, image=None, parallel=False)

Parameters

NameDescription
inputString
Text for this call. A non-blank string of at most 4,000 UTF-16 units.
Required · Positional or named
No default
imageTemplate?
Optional image template. Capture a region first with Region.capture().
Optional · Keyword only
Default: None
parallelBoolean
True starts one background request per script. Returns whether it was accepted. Read the result with poll().
Optional · Keyword only
Default: False

Returns

dict | Boolean — The result dict contains ok, probability, and error. Probability is the chance of yes from 0 to 1 or None on failure. With parallel=True the call returns True or False.

Example

# Capture the region to classify
image = Region(120, 220, 320, 100).capture()
if image is not None:
    llm = LLM("Does the image show a fish?")
    answer = llm.decision("Check this image.", image=image)
    if answer["ok"]:
        print(answer["probability"])
    else:
        print(answer["error"])

LLM.poll

Read and consume this LLM instance's completed background result. Returns None if there is no completed result.

Syntax

llm.poll()

Returns

Example

Not documented

LLM.cancel

Cancel the background request and discard its result. Returns True when a request was removed.

Syntax

llm.cancel()

Returns

Boolean

Example

Not documented