Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: AI Agent https://github.com/siyuan-note/siyuan/issues/17797

Danielf44610570d4b
diff --git a/app/src/layout/dock/AgentChat.ts b/app/src/layout/dock/AgentChat.ts
index 24942c0707..45ebe5217f 100644
--- a/app/src/layout/dock/AgentChat.ts
+++ b/app/src/layout/dock/AgentChat.ts
@@ -1303,7 +1303,7 @@ export class AgentChat extends Model {
fetch("/api/ai/agent/title", {
method: "POST",
headers: {"Content-Type": "application/json"},
- body: JSON.stringify({message: userMsg, model: this.getSelectedModel()}),
+ body: JSON.stringify({message: userMsg, model: this.getSelectedModel(), language: window.siyuan.config.appearance.lang}),
}).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.go
index 79e51b826a..01c35ff2d9 100644
--- a/kernel/agent/agent.go
+++ b/kernel/agent/agent.go
@@ -552,11 +552,11 @@ func AgentChat(ctx context.Context, client *openai.Client, model string, session
return ch
}
-func GenerateTitle(client *openai.Client, model string, userMsg 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: "You are a title generator. Below is the first message of a conversation. Write a concise title (under 12 words) that summarizes the topic. Output ONLY the title, no other text. Reply in the same language as the user's message."},
+ {Role: openai.ChatMessageRoleSystem, Content: "You are a title generator. Below is the first message of a conversation. Write a concise title (under 12 words) that summarizes the topic. Output ONLY the title, no other text. Reply in the same language as the user's message. If you cannot determine the language, reply in " + util.I18nTerm(language, "_label") + "."},
{Role: openai.ChatMessageRoleUser, Content: "Conversation starts with: " + userMsg},
},
MaxCompletionTokens: 50,
diff --git a/kernel/api/agent.go b/kernel/api/agent.go
index 1ad0c8225d..51caf9e52c 100644
--- a/kernel/api/agent.go
+++ b/kernel/api/agent.go
@@ -175,8 +175,9 @@ func agentChatQuestion(c *gin.Context) {
}
type agentTitleReq struct {
- Message string `json:"message"`
- Model string `json:"model"`
+ Message string `json:"message"`
+ Model string `json:"model"`
+ Language string `json:"language"`
}
func agentChatTitle(c *gin.Context) {
@@ -199,7 +200,7 @@ func agentChatTitle(c *gin.Context) {
}
client := util.NewOpenAIClient(string(selectedProvider.APIKey), selectedProvider.BaseURL)
- title := agent.GenerateTitle(client, selectedModel.Name, req.Message)
+ title := agent.GenerateTitle(client, selectedModel.Name, req.Message, req.Language)
ret := gulu.Ret.NewResult()
ret.Data = title
c.JSON(http.StatusOK, ret)