nsmcp::ChatCompletionsRun method invoke (protected)

 <instance of nsmcp::ChatCompletionsRun[i]> invoke call allowed

Defined in /usr/local/ns/tcl/nsmcp/question-chat-completions.tcl

Parameters:
call (required)
allowed (required)

Testcases:
No testcase defined.
Source code:
:check
if {[incr :toolCount] > [${:backend} cget -maxToolCalls]} {error "Question tool-call limit reached"}
set name [dict get $call name]
set arguments [dict get $call arguments]
if {$name ni $allowed || [dict get $call type] ne "function" || [dict get $call id] eq ""} {error "API requested an unadvertised or invalid tool"}
# Reauthenticate each call so token revocation and runtime tool switches
# take effect immediately, including within an ongoing question.
set context [:context]
try {
    if {[catch {
        set parsed [ns_json parse -top container -maxdepth 64 -maxstring 1048576 -maxcontainer 100000 -output triples -- $arguments]
        if {[lindex $parsed 1] ne "object"} {error "Tool arguments must be a JSON object"}
        [${:backend} cget -registry] call $context [${:backend} cget -authorizer] $name $parsed
    } result]} {
        set result [list {} object [list isError boolean true content array  [list 0 object [list type string text text string [string range $result 0 1023]]]]]
    }
} finally {$context destroy}
set json [${:backend} canonicalResult [ns_json value -- $result]]
set json [::nsmcp::QuestionJobPoller wait $name $json ${:deadline} ${:emit} [list [self] pollJob] [list [self] eval {:check}]]
set json [${:backend} canonicalResult $json]
set shown $json
set truncated false
if {[string bytelength $shown] > [${:backend} cget -maxResultBytes]} {
    set shown {Result omitted from this page because it exceeds the configured display limit.}
    set truncated true
}
set status completed
set value [ns_json parse $json]
if {[dict exists $value isError] && [dict get $value isError]} {set status failed}
:emit [dict create type tool name $name status $status arguments $arguments result $shown truncated $truncated]
return [list role string tool tool_call_id string [dict get $call id] content string $json]
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: