Files
api_health/agent/tools/calendar/year_terms.js
2026-05-30 16:41:26 +08:00

60 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { tool } from "langchain"
/**
* 年份节气列表工具
* 查询给定年份节气所在日期列表
*/
export const getYearTermsTool = tool(
async ({ year }) => {
try {
// 简化实现返回24节气信息
const terms = [
{ date: `${year}-02-04`, name: '立春' },
{ date: `${year}-02-19`, name: '雨水' },
{ date: `${year}-03-05`, name: '惊蛰' },
{ date: `${year}-03-20`, name: '春分' },
{ date: `${year}-04-04`, name: '清明' },
{ date: `${year}-04-19`, name: '谷雨' },
{ date: `${year}-05-05`, name: '立夏' },
{ date: `${year}-05-20`, name: '小满' },
{ date: `${year}-06-05`, name: '芒种' },
{ date: `${year}-06-21`, name: '夏至' },
{ date: `${year}-07-07`, name: '小暑' },
{ date: `${year}-07-22`, name: '大暑' },
{ date: `${year}-08-07`, name: '立秋' },
{ date: `${year}-08-23`, name: '处暑' },
{ date: `${year}-09-07`, name: '白露' },
{ date: `${year}-09-23`, name: '秋分' },
{ date: `${year}-10-08`, name: '寒露' },
{ date: `${year}-10-23`, name: '霜降' },
{ date: `${year}-11-07`, name: '立冬' },
{ date: `${year}-11-22`, name: '小雪' },
{ date: `${year}-12-07`, name: '大雪' },
{ date: `${year}-12-21`, name: '冬至' },
{ date: `${year + 1}-01-05`, name: '小寒' },
{ date: `${year + 1}-01-20`, name: '大寒' }
]
return JSON.stringify({ year, terms }, null, 2)
} catch (error) {
console.error('Error in year terms tool:', error)
return JSON.stringify({ error: error.message }, null, 2)
}
},
{
name: "get_year_terms",
description: "查询给定年份节气所在日期列表",
schema: {
type: "object",
properties: {
year: {
type: "number",
description: "年份",
minimum: 1900,
maximum: 2100
}
},
required: ["year"]
}
}
)