mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-04-24 20:45:22 +08:00
feat: 精简部分工具的搜索参数以节省token
This commit is contained in:
@@ -4,12 +4,12 @@ import type { ToolContext } from '../types'
|
||||
import * as workerManager from '../../../worker/workerManager'
|
||||
import { parseExtendedTimeParams } from '../utils/time-params'
|
||||
import { formatTimeRange, isChineseLocale } from '../utils/format'
|
||||
import { timeParamPropertiesNoHour } from '../utils/schemas'
|
||||
import { timeParamProperties } from '../utils/schemas'
|
||||
|
||||
const schema = Type.Object({
|
||||
keywords: Type.Optional(Type.Array(Type.String(), { description: 'ai.tools.get_session_summaries.params.keywords' })),
|
||||
limit: Type.Optional(Type.Number({ description: 'ai.tools.get_session_summaries.params.limit' })),
|
||||
...timeParamPropertiesNoHour,
|
||||
...timeParamProperties,
|
||||
})
|
||||
|
||||
/** 获取会话摘要列表,快速了解群聊历史讨论的主题。适用场景:1. 了解群里最近在聊什么话题 2. 按关键词搜索讨论过的话题 3. 概览性问题如"群里有没有讨论过旅游"。返回的摘要是对每个会话的简短总结,可以帮助快速定位感兴趣的会话,然后用 get_session_messages 获取详情。 */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Type } from '@mariozechner/pi-ai'
|
||||
import type { AgentTool } from '@mariozechner/pi-agent-core'
|
||||
import type { ToolContext } from '../types'
|
||||
import { timeParamPropertiesNoHour } from '../utils/schemas'
|
||||
import { timeParamProperties } from '../utils/schemas'
|
||||
import * as workerManager from '../../../worker/workerManager'
|
||||
import { parseExtendedTimeParams } from '../utils/time-params'
|
||||
import { formatTimeRange, formatMessageCompact, isChineseLocale } from '../utils/format'
|
||||
@@ -9,7 +9,7 @@ import { formatTimeRange, formatMessageCompact, isChineseLocale } from '../utils
|
||||
const schema = Type.Object({
|
||||
keywords: Type.Optional(Type.Array(Type.String(), { description: 'ai.tools.search_sessions.params.keywords' })),
|
||||
limit: Type.Optional(Type.Number({ description: 'ai.tools.search_sessions.params.limit' })),
|
||||
...timeParamPropertiesNoHour,
|
||||
...timeParamProperties,
|
||||
})
|
||||
|
||||
/** 搜索聊天会话(对话段落)。会话是根据消息时间间隔自动切分的对话单元。适用于查找特定话题的讨论、了解某个时间段内发生了几次对话等场景。返回匹配的会话列表及每个会话的前5条消息预览。 */
|
||||
|
||||
@@ -6,18 +6,6 @@
|
||||
import { Type } from '@mariozechner/pi-ai'
|
||||
|
||||
export const timeParamProperties = {
|
||||
year: Type.Optional(Type.Number({ description: 'ai.tools._shared.params.year' })),
|
||||
month: Type.Optional(Type.Number({ description: 'ai.tools._shared.params.month' })),
|
||||
day: Type.Optional(Type.Number({ description: 'ai.tools._shared.params.day' })),
|
||||
hour: Type.Optional(Type.Number({ description: 'ai.tools._shared.params.hour' })),
|
||||
start_time: Type.Optional(Type.String({ description: 'ai.tools._shared.params.start_time' })),
|
||||
end_time: Type.Optional(Type.String({ description: 'ai.tools._shared.params.end_time' })),
|
||||
}
|
||||
|
||||
export const timeParamPropertiesNoHour = {
|
||||
year: Type.Optional(Type.Number({ description: 'ai.tools._shared.params.year' })),
|
||||
month: Type.Optional(Type.Number({ description: 'ai.tools._shared.params.month' })),
|
||||
day: Type.Optional(Type.Number({ description: 'ai.tools._shared.params.day' })),
|
||||
start_time: Type.Optional(Type.String({ description: 'ai.tools._shared.params.start_time' })),
|
||||
end_time: Type.Optional(Type.String({ description: 'ai.tools._shared.params.end_time' })),
|
||||
}
|
||||
|
||||
@@ -3,17 +3,13 @@
|
||||
*/
|
||||
|
||||
export interface ExtendedTimeParams {
|
||||
year?: number
|
||||
month?: number
|
||||
day?: number
|
||||
hour?: number
|
||||
start_time?: string // 格式: "YYYY-MM-DD HH:mm"
|
||||
end_time?: string // 格式: "YYYY-MM-DD HH:mm"
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析扩展的时间参数,返回时间过滤器
|
||||
* 优先级: start_time/end_time > year/month/day/hour 组合 > context.timeFilter
|
||||
* 解析时间参数,返回时间过滤器
|
||||
* 优先级: start_time/end_time > context.timeFilter
|
||||
*/
|
||||
export function parseExtendedTimeParams(
|
||||
params: ExtendedTimeParams,
|
||||
@@ -45,34 +41,5 @@ export function parseExtendedTimeParams(
|
||||
}
|
||||
}
|
||||
|
||||
if (params.year) {
|
||||
const year = params.year
|
||||
const month = params.month
|
||||
const day = params.day
|
||||
const hour = params.hour
|
||||
|
||||
let startDate: Date
|
||||
let endDate: Date
|
||||
|
||||
if (month && day && hour !== undefined) {
|
||||
startDate = new Date(year, month - 1, day, hour, 0, 0)
|
||||
endDate = new Date(year, month - 1, day, hour, 59, 59)
|
||||
} else if (month && day) {
|
||||
startDate = new Date(year, month - 1, day, 0, 0, 0)
|
||||
endDate = new Date(year, month - 1, day, 23, 59, 59)
|
||||
} else if (month) {
|
||||
startDate = new Date(year, month - 1, 1)
|
||||
endDate = new Date(year, month, 0, 23, 59, 59)
|
||||
} else {
|
||||
startDate = new Date(year, 0, 1)
|
||||
endDate = new Date(year, 11, 31, 23, 59, 59)
|
||||
}
|
||||
|
||||
return {
|
||||
startTs: Math.floor(startDate.getTime() / 1000),
|
||||
endTs: Math.floor(endDate.getTime() / 1000),
|
||||
}
|
||||
}
|
||||
|
||||
return contextTimeFilter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user