This commit is contained in:
2026-06-10 19:50:14 +08:00
parent dc39d28894
commit 2182d0312b
6 changed files with 122 additions and 4 deletions
+17 -1
View File
@@ -319,7 +319,7 @@ func handleChat(ctx *gin.Context) {
toolNames = append(toolNames, tool.Function.Name)
}
emitTrace("function_tools", "prepare", "success", "已启用 Function Calling 工具", map[string]interface{}{"tools": toolNames})
openaiMsgs = append([]openaiMessage{{Role: "system", Content: "可用工具使用规则:当用户询问本月、今天、本周、下周等相对日期的日程时,先调用 time 获取明确 start_date/end_date,再调用 ops_ai_assistant_schedule_query 查询日程。不要臆造工具结果中不存在的日程。"}}, openaiMsgs...)
openaiMsgs = append([]openaiMessage{{Role: "system", Content: "可用工具使用规则:当用户询问“我是谁”“当前登录用户是谁”“我的用户信息”等当前身份问题时,调用 ops_ai_assistant_current_user;工具返回 loggedIn=true 时按工具结果回答当前用户信息,返回 loggedIn=false 时说明不知道并提示需要登录才能获取信息。当用户询问本月、今天、本周、下周等相对日期的日程时,先调用 time 获取明确 start_date/end_date,再调用 ops_ai_assistant_schedule_query 查询日程。不要臆造工具结果中不存在的信息。"}}, openaiMsgs...)
var toolExecuted bool
openaiMsgs, toolExecuted, err = runOpenAIToolLoop(ctx.Request.Context(), profile, openaiMsgs, functionTools, currentUser, tracker, emitTrace)
if err != nil {
@@ -983,6 +983,22 @@ func executeAIFunctionTool(ctx context.Context, name string, rawArgs []byte, cur
runtime := agents.FunctionToolRuntime{}
if currentUser != nil {
runtime.UserID = currentUser.ID
runtime.UserName = currentUser.Name
runtime.UserEmail = currentUser.Email
runtime.UserType = currentUser.Type
if userInfo := GetUserInfoFromUserID(currentUser.ID); userInfo != nil {
runtime.UserInfo = &agents.CurrentUserInfo{
ID: userInfo.ID,
UserID: userInfo.UserID,
FirstName: userInfo.FirstName,
Username: userInfo.Username,
Birthdate: userInfo.Birthdate.Format("2006-01-02"),
Gender: userInfo.Gender,
AvatarPath: userInfo.AvatarPath,
Region: userInfo.Region,
Language: userInfo.Language,
}
}
}
return agents.ExecuteFunctionTool(ctx, runtime, name, rawArgs)
}