An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:sparkles: AI Agent https://github.com/siyuan-note/siyuan/issues/17797
Danielde81d9f72e09
diff --git a/app/src/layout/dock/AgentChat.ts b/app/src/layout/dock/AgentChat.tsindex 2046aebed4..ca165b1f0a 100644--- a/app/src/layout/dock/AgentChat.ts+++ b/app/src/layout/dock/AgentChat.ts@@ -1124,11 +1124,10 @@ export class AgentChat extends Model {if (this.hasTitled) { return; }this.hasTitled = true;const userMsg = this.entries.find((e) => e.type === "user")?.content?.slice(0, 500) || "";- const aiMsg = this.entries.find((e) => e.type === "assistant")?.content?.slice(0, 500) || "";fetch("/api/ai/agent/title", {method: "POST",headers: {"Content-Type": "application/json"},- body: JSON.stringify({message: userMsg, assistantReply: aiMsg}),+ body: JSON.stringify({message: userMsg, model: this.getSelectedModel()}),}).then((resp) => resp.json()).then((data) => {if (data.code === 0 && data.data && data.data !== this.sessionTitle) {this.sessionTitle = data.data;diff --git a/kernel/agent/agent.go b/kernel/agent/agent.goindex 698d373b87..6b2c808797 100644--- a/kernel/agent/agent.go+++ b/kernel/agent/agent.go@@ -499,15 +499,14 @@ func AgentChat(ctx context.Context, client *openai.Client, model string, sessionreturn ch}-func GenerateTitle(client *openai.Client, model string, userMsg string, aiReply string, language string) string {+func GenerateTitle(client *openai.Client, model string, userMsg string, language string) string {resp, err := client.CreateChatCompletion(context.Background(), openai.ChatCompletionRequest{Model: model,Messages: []openai.ChatCompletionMessage{- {Role: openai.ChatMessageRoleSystem, Content: "Extract the core topic from the conversation below and generate a short title (under 12 words). Be specific, not generic. NEVER copy the user's message word-for-word. For example, 'Diary' is a good title for a conversation about writing a diary, while 'Help me write a diary' is bad. Reply in " + language + ". Return only the title, no quotes."},+ {Role: openai.ChatMessageRoleSystem, Content: "Extract a short title (under 12 words) for the conversation provided by the user. Be specific, not generic. Reply in " + language + "."},{Role: openai.ChatMessageRoleUser, Content: userMsg},- {Role: openai.ChatMessageRoleAssistant, Content: aiReply},},- MaxTokens: 30,+ MaxCompletionTokens: 50,})if err != nil || len(resp.Choices) == 0 {runes := []rune(userMsg)diff --git a/kernel/api/agent.go b/kernel/api/agent.goindex 22bca62e33..5d464db6da 100644--- a/kernel/api/agent.go+++ b/kernel/api/agent.go@@ -174,8 +174,8 @@ func agentChatQuestion(c *gin.Context) {}type agentTitleReq struct {- Message string `json:"message"`- AssistantReply string `json:"assistantReply"`+ Message string `json:"message"`+ Model string `json:"model"`}func agentChatTitle(c *gin.Context) {@@ -188,7 +188,7 @@ func agentChatTitle(c *gin.Context) {return}- selectedProvider := model.Conf.AI.GetProvider("")+ selectedProvider := model.Conf.AI.GetProvider(req.Model)client := util.NewOpenAIClient(selectedProvider.APIKey,selectedProvider.APIProxy,@@ -198,7 +198,7 @@ func agentChatTitle(c *gin.Context) {selectedProvider.APIProvider,)- title := agent.GenerateTitle(client, selectedProvider.APIModel, req.Message, req.AssistantReply, model.Conf.Lang)+ title := agent.GenerateTitle(client, selectedProvider.APIModel, req.Message, model.Conf.Lang)ret := gulu.Ret.NewResult()ret.Data = titlec.JSON(http.StatusOK, ret)