diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d527c1e..3a25396b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to DreamCoder will be documented in this file. ### Fixed +- Session title generation tells the model to name the conversation instead of answering it, and to write the title in the user's language (#277). - A provider in OpenAI format whose base URL already ends in a version, such as `https://open.bigmodel.cn/api/paas/v4` or Gemini's `.../v1beta/openai`, works: requests, model lists and the connection test no longer add another `/v1`. Base URLs without a version still get `/v1` (#262). - A streamed reply through the local proxy is no longer cut off when the provider pauses for more than 60 seconds, and stopping a reply or deleting a session now also stops the request to the provider before it starts answering (#262). - With a manual HTTP proxy set in the network settings, the agent reaches the app's local proxy directly instead of sending those requests to the HTTP proxy (#262). diff --git a/src/server/__tests__/title-service.test.ts b/src/server/__tests__/title-service.test.ts index 30e1bb77..374b0eca 100644 --- a/src/server/__tests__/title-service.test.ts +++ b/src/server/__tests__/title-service.test.ts @@ -323,6 +323,34 @@ describe('titleService', () => { } }) + test('title prompt names the session instead of answering and uses the user language', async () => { + let requestBody: Record | null = null + const server = Bun.serve({ + hostname: '127.0.0.1', + port: 0, + async fetch(req) { + requestBody = await req.json() as Record + return Response.json({ + type: 'message', + content: [{ type: 'text', text: '{"title":"Trace ok"}' }], + }) + }, + }) + + try { + await writeLoggedProvider(server.port) + + await expect(generateTitle('帮我看看为什么 bun test 在 CI 上失败?')).resolves.toBe('Trace ok') + const system = requestBody?.system + expect(typeof system).toBe('string') + expect(system).toContain('title-generation task, not a conversation') + expect(system).toContain('Never answer the user\'s question') + expect(system).toContain('user\'s primary language') + } finally { + server.stop(true) + } + }) + test('logs why the title request failed upstream', async () => { const server = Bun.serve({ hostname: '127.0.0.1', diff --git a/src/server/services/titleService.ts b/src/server/services/titleService.ts index d3596e63..05540544 100644 --- a/src/server/services/titleService.ts +++ b/src/server/services/titleService.ts @@ -11,6 +11,8 @@ const TITLE_LOG_EXCERPT_LEN = 200 const TITLE_SYSTEM_PROMPT = `Generate a concise, sentence-case title (3-7 words) that captures the main topic or goal of this coding session. The title should be clear enough that the user recognizes the session in a list. Use sentence case: capitalize only the first word and proper nouns. +This is a title-generation task, not a conversation. Never answer the user's question or fulfill their request. Write the title in the user's primary language. + Return JSON with a single "title" field. Good examples: