SimpleChatTC: More generic tooljs, SimpCalc, some main skeleton
Make tooljs structure and flow more generic Add a simple_calculator tool/function call logic Add initial skeleton wrt the main tools.mjs file.
This commit is contained in:
parent
f1aa0ee778
commit
46f0304105
|
|
@ -1,40 +1,83 @@
|
|||
//@ts-check
|
||||
// Helpers to handle tools/functions calling
|
||||
// DANGER DANGER DANGER - Simple and Stupid - Use from a discardable VM only
|
||||
// Helpers to handle tools/functions calling wrt
|
||||
// * javascript interpreter
|
||||
// * simple arithmatic calculator
|
||||
// by Humans for All
|
||||
//
|
||||
|
||||
|
||||
let metas = [
|
||||
{
|
||||
"type":"function",
|
||||
"function":{
|
||||
let js_meta = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "javascript",
|
||||
"description":"Runs code in an javascript interpreter and returns the result of the execution after 60 seconds.",
|
||||
"parameters":{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"code":{
|
||||
"type":"string",
|
||||
"description":"The code to run in the javascript interpreter."
|
||||
"description": "Runs code in an javascript interpreter and returns the result of the execution after few seconds",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"description": "The code to run in the javascript interpreter."
|
||||
}
|
||||
},
|
||||
"required":["code"]
|
||||
"required": ["code"]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the javascript interpretor logic. Minimal skeleton for now.
|
||||
* ALERT: Has access to the javascript environment and can mess with it and beyond
|
||||
* @param {any} obj
|
||||
*/
|
||||
function tool_run(obj) {
|
||||
function js_run(obj) {
|
||||
let func = new Function(obj["code"])
|
||||
func()
|
||||
}
|
||||
|
||||
let tswitch = {
|
||||
"javascript": tool_run,
|
||||
|
||||
let calc_meta = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "simple_calculator",
|
||||
"description": "Calculates the provided arithmatic expression using javascript interpreter and returns the result of the execution after few seconds",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"arithexpr":{
|
||||
"type":"string",
|
||||
"description":"The arithmatic expression that will be calculated using javascript interpreter."
|
||||
}
|
||||
},
|
||||
"required": ["arithexpr"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the simple calculator logic. Minimal skeleton for now.
|
||||
* ALERT: Has access to the javascript environment and can mess with it and beyond
|
||||
* @param {any} obj
|
||||
*/
|
||||
function calc_run(obj) {
|
||||
let func = new Function(obj["arithexpr"])
|
||||
func()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string, Object>}
|
||||
*/
|
||||
export let tc_switch = {
|
||||
"javascript": {
|
||||
"handler": js_run,
|
||||
"meta": js_meta
|
||||
},
|
||||
"simple_calculator": {
|
||||
"handler": calc_run,
|
||||
"meta": calc_meta
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,29 @@
|
|||
//@ts-check
|
||||
// Helpers to handle tools/functions calling
|
||||
// DANGER DANGER DANGER - Simple and Stupid - Use from a discardable VM only
|
||||
// Helpers to handle tools/functions calling in a direct and dangerous way
|
||||
// by Humans for All
|
||||
//
|
||||
|
||||
|
||||
import * as tjs from './tooljs.mjs'
|
||||
import * as tjs from './tooljs.mjs'
|
||||
|
||||
|
||||
/**
|
||||
* @type {Object<string,Object>}
|
||||
*/
|
||||
let tc_switch = {}
|
||||
|
||||
export function setup() {
|
||||
for (const key in tjs.tc_switch) {
|
||||
tc_switch[key] = tjs.tc_switch[key]
|
||||
}
|
||||
}
|
||||
|
||||
export function meta() {
|
||||
let tools = []
|
||||
for (const key in tc_switch) {
|
||||
tools.push(tc_switch[key]["meta"])
|
||||
}
|
||||
return tools
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue