完善了agent
This commit is contained in:
42
agent/tools/calendar/calendar_info.js
Normal file
42
agent/tools/calendar/calendar_info.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { tool } from "langchain"
|
||||
import lunar from "lunar-javascript"
|
||||
const { Solar, Lunar, HolidayUtil, TermUtil } = lunar
|
||||
import { getAccurateTime } from "./utils.js"
|
||||
|
||||
/**
|
||||
* 日历工具
|
||||
* 提供准确时间、农历信息、节气、节日和老黄历等信息
|
||||
*/
|
||||
export const getCalendarInfoTool = tool(
|
||||
async () => {
|
||||
try {
|
||||
// 获取准确时间
|
||||
const timeInfo = await getAccurateTime()
|
||||
|
||||
// 获取农历信息
|
||||
const date = new Date(timeInfo.timestamp)
|
||||
const solar = Solar.fromDate(date)
|
||||
const lunar = solar.getLunar()
|
||||
|
||||
// 组合返回结果
|
||||
const result = {
|
||||
time: timeInfo,
|
||||
weekday: solar.getWeek(),
|
||||
lunar: {
|
||||
lunar: lunar.toString(),
|
||||
solar: solar.toString(),
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(result, null, 2)
|
||||
} catch (error) {
|
||||
console.error('Error in calendar tool:', error)
|
||||
return JSON.stringify({ error: error.message }, null, 2)
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "get_calendar_info",
|
||||
description: "获取当前准确日期时间,以及对应的农历日期"
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user