nsmcp::ChatCompletionsRun method invoke (protected)
<instance of nsmcp::ChatCompletionsRun> 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 {${:pins} eq {}} { error "Question tools are not pinned" } 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 toolStarted [clock clicks -milliseconds] 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]] if {[catch { set json [::nsmcp::QuestionJobPoller wait $name $json ${:deadline} ${:emit} [list [self] pollJob] [list [self] eval {:check}]] } message options]} { set failed [ns_json value -- [list {} object [list isError boolean true content array [list 0 object [list type string text text string [string range $message 0 1023]]]]]] catch { :emit [dict create type tool name $name status failed arguments $arguments result $failed truncated false durationMs [expr {[clock clicks -milliseconds]-$toolStarted}] durationSource api-observed] } return -options $options $message } 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 durationMs [expr {[clock clicks -milliseconds]-$toolStarted}] durationSource api-observed] return [list role string tool tool_call_id string [dict get $call id] content string $json]XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)