From b446b57afdff2992074c5bf228af145d82b5b663 Mon Sep 17 00:00:00 2001 From: AkashiNeko Date: Fri, 11 Apr 2025 10:07:10 +0800 Subject: [PATCH] feat: optimize LLM prompts and message handling --- cmds/group.go | 3 +-- llm/llm.go | 34 +++++++++++++--------------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/cmds/group.go b/cmds/group.go index 27c478f..493376b 100644 --- a/cmds/group.go +++ b/cmds/group.go @@ -7,8 +7,7 @@ import ( ) func cmd_group(c *qbot.Client, raw *qbot.Message, args *ArgsList) { - if raw.GroupID == 0 { - c.SendMsg(raw, "只能在群组中使用") + if raw.GroupID != 948697448 { return } const help = "Usage: group [rename ]" diff --git a/llm/llm.go b/llm/llm.go index 3d56a9e..108a587 100644 --- a/llm/llm.go +++ b/llm/llm.go @@ -28,6 +28,9 @@ func LLMMsgHandle(c *qbot.Client, msg *qbot.Message) bool { 2. 群聊不支持 Markdown 语法,所以请不要使用它。 3. 使用灵活生动的语言,不要让你发的消息读起来像是AI生成的。 4. 每个用户有一个id、昵称和个人信息。你可以在回复时使用昵称来称呼用户,尽量避免在回复中使用id。 +5. 目前你只能阅读文字和发送文字,无法识别图片、语音、视频、文件等信息,也无法发送这些信息。 +6. 请尽量以对方的昵称来称呼用户,而不是对方的id。 +7. 对于专业的问题,请使用专业的语言回答,但也不要过于正式。 在回复时,你必须使用 xml 格式输出你的回复。你可以使用以下 xml 标签持久化保存记忆,更新的记忆将用于下一次回复: @@ -47,6 +50,8 @@ func LLMMsgHandle(c *qbot.Client, msg *qbot.Message) bool { 消息内容 如果你需要@其他人,请在标签中使用 [CQ:at,qq=] 的形式。例如:发送 [CQ:at,qq=1006554341]可以@用户1006554341。 +5. 换行不使用
,而是直接在块中换行。如果你的消息可能包含多段内容,请使用多个标签。 + 下面是一个示例,这段示例将更新记忆中的用户昵称、用户信息和群聊信息,并发送三条消息: 氟氟 关于氟氟的介绍… @@ -139,37 +144,24 @@ func LLMMsgHandle(c *qbot.Client, msg *qbot.Message) bool { var usersInfo string for id, info := range userMap { - usersInfo += fmt.Sprintf("nick_name=%q,id=%d,summary=%q\n", info.NickName, id, info.Summary) + usersInfo += fmt.Sprintf("nick_name:%q,id:%d,user_info:%q\n", info.NickName, id, info.Summary) } req.Messages = append(req.Messages, Grok2Message{ - Role: "user", - Content: "以下是聊天参与者的昵称和相关信息,这些信息是之前由你生成的,你可以使用 标签来更改这些信息:\n" + usersInfo, + Role: "user", + Content: "以下是聊天参与者的昵称和相关信息,这些信息是之前由你生成的,你可以使用 标签来更改这些信息:\n" + + usersInfo, }) var chatHistory string for i := len(histories) - 1; i >= 0; i-- { - localTime := histories[i].Time.In(time.FixedZone("UTC+8", 8*60*60)) - if histories[i].UserID == config.BotID { - if chatHistory != "" { - req.Messages = append(req.Messages, Grok2Message{ - Role: "user", - Content: chatHistory, - }) - chatHistory = "" - } - req.Messages = append(req.Messages, Grok2Message{ - Role: "assistant", - Content: localTime.Format("2006-01-02 15:04:05 ") + histories[i].Content, - }) - } else { - chatHistory += formatMsg(histories[i].Time, userMap[histories[i].UserID].NickName, histories[i].UserID, histories[i].Content) - } + chatHistory += formatMsg(histories[i].Time, userMap[histories[i].UserID].NickName, histories[i].UserID, histories[i].Content) } if chatHistory != "" { req.Messages = append(req.Messages, Grok2Message{ - Role: "user", - Content: chatHistory, + Role: "user", + Content: "以下是聊天记录,其中可能包含你自己发送的信息。你的id是" + + strconv.FormatUint(config.BotID, 10) + "\n" + chatHistory, }) }