Forked from hxyy/current-time
src / toolsProvider.ts
import { text, tool, ToolsProviderController } from "@lmstudio/sdk";
import { z } from "zod";
export async function toolsProvider(ctl: ToolsProviderController) {
const locale = typeof navigator !== 'undefined' ? (navigator.language || 'en-US') : 'en-US';
const isChinese = locale.startsWith('zh');
const currentDateOnly = new Intl.DateTimeFormat(isChinese ? 'zh-CN' : 'en-US', {
year: 'numeric', month: '2-digit', day: '2-digit'
}).format(new Date());
const exampleTool = tool({
// The name of the tool
name: "current_time",
description: text`${isChinese ? '当前日期: ' : 'Current date: '}${currentDateOnly}${isChinese ? ',需要精确时间时可调用。' : ', call this tool when you need a precise time.'}`,
parameters: {},
// 工具实现逻辑
implementation: () => {
return new Intl.DateTimeFormat(locale, {
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
year: 'numeric', month: 'long', day: 'numeric',
hour: '2-digit', minute: '2-digit', second: '2-digit'
}).format(new Date());
}
});
return [exampleTool];
}