SimpleChatTC:System Date and Time
This commit is contained in:
parent
d6fd4ea533
commit
83a4b1a3fa
|
|
@ -125,6 +125,9 @@ export function trim_hist_garbage_at_end(sIn, maxType, maxUniq, maxMatchLenThres
|
|||
let iNum = 0;
|
||||
let iOth = 0;
|
||||
// Learn
|
||||
/**
|
||||
* @type {Object<string, number>}
|
||||
*/
|
||||
let hist = {};
|
||||
let iUniq = 0;
|
||||
for(let i=0; i<maxMatchLenThreshold; i++) {
|
||||
|
|
|
|||
|
|
@ -107,8 +107,8 @@ remember to
|
|||
* review and update this to match your needs.
|
||||
* the shared bearer token between server and client ui
|
||||
|
||||
* other builtin tool / function calls like calculator, javascript runner, DataStore dont require the
|
||||
simpleproxy.py helper.
|
||||
* other builtin tool / function calls like datetime, calculator, javascript runner, DataStore
|
||||
dont require the simpleproxy.py helper.
|
||||
|
||||
|
||||
|
||||
|
|
@ -435,6 +435,8 @@ The following tools/functions are currently provided by default
|
|||
|
||||
##### directly in browser
|
||||
|
||||
* sys_date_time - provides the current date and time
|
||||
|
||||
* simple_calculator - which can solve simple arithmatic expressions
|
||||
|
||||
* run_javascript_function_code - which can be used to run ai generated or otherwise javascript code
|
||||
|
|
@ -628,6 +630,8 @@ sliding window based drop off or even before they kick in, this can help in many
|
|||
|
||||
* renamed pdf_to_text to fetch_pdf_as_text so that ai model can understand the semantic better.
|
||||
|
||||
* sys_date_time tool call has been added.
|
||||
|
||||
|
||||
#### ToDo
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,76 @@
|
|||
let gToolsWorker = /** @type{Worker} */(/** @type {unknown} */(null));
|
||||
|
||||
|
||||
let sysdatetime_meta = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "sys_date_time",
|
||||
"description": "Returns the current system date and time. One can optionally pass template to control what and all parts of date and time are returned",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"template": {
|
||||
"type": "string",
|
||||
"description": `Optional template can be any combination of Y,M,D,h,m,s.
|
||||
Y - FullYear 4 digits, M - Month 2 digits, D - Day 2 digits,
|
||||
h - hour 2 digits, m - minutes 2 digits, s - seconds 2 digits,
|
||||
any other char will be returned as is
|
||||
|
||||
If no template is given, it defaults to YMDThm
|
||||
`
|
||||
}
|
||||
},
|
||||
"required": ["template"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the system date and time.
|
||||
* @param {string} chatid
|
||||
* @param {string} toolcallid
|
||||
* @param {string} toolname
|
||||
* @param {any} obj
|
||||
*/
|
||||
function sysdatetime_run(chatid, toolcallid, toolname, obj) {
|
||||
let dt = new Date()
|
||||
let tmpl = obj['template'];
|
||||
if ((tmpl == undefined) || (tmpl == "")) {
|
||||
tmpl = 'YMDThm';
|
||||
}
|
||||
let sDT = ""
|
||||
for (const c of tmpl) {
|
||||
switch (c) {
|
||||
case 'Y':
|
||||
sDT += dt.getFullYear().toString().padStart(4, '0')
|
||||
break;
|
||||
case 'M':
|
||||
sDT += (dt.getMonth()+1).toString().padStart(2, '0')
|
||||
break;
|
||||
case 'D':
|
||||
sDT += dt.getDate().toString().padStart(2, '0')
|
||||
break;
|
||||
case 'h':
|
||||
sDT += dt.getHours().toString().padStart(2, '0')
|
||||
break;
|
||||
case 'm':
|
||||
sDT += dt.getMinutes().toString().padStart(2, '0')
|
||||
break;
|
||||
case 's':
|
||||
sDT += dt.getSeconds().toString().padStart(2, '0')
|
||||
break;
|
||||
default:
|
||||
sDT += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gToolsWorker.onmessage != null) {
|
||||
gToolsWorker.onmessage(new MessageEvent('message', {data: {cid: chatid, tcid: toolcallid, name: toolname, data: sDT}}))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let js_meta = {
|
||||
"type": "function",
|
||||
"function": {
|
||||
|
|
@ -79,6 +149,11 @@ function calc_run(chatid, toolcallid, toolname, obj) {
|
|||
* @type {Object<string, Object<string, any>>}
|
||||
*/
|
||||
export let tc_switch = {
|
||||
"sys_date_time": {
|
||||
"handler": sysdatetime_run,
|
||||
"meta": sysdatetime_meta,
|
||||
"result": ""
|
||||
},
|
||||
"run_javascript_function_code": {
|
||||
"handler": js_run,
|
||||
"meta": js_meta,
|
||||
|
|
|
|||
Loading…
Reference in New Issue