Skip to content

Commit 816a3eb

Browse files
committed
fix chat thread summaries
1 parent 59a5047 commit 816a3eb

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/actions/summarizeChatThread.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const SummarizeChatThreadParams = new Archetype({
1717
}]
1818
}).compile('SummarizeChatThreadParams');
1919

20-
const systemPrompt = 'Summarize the following chat thread in 6 words or less, as a helpful thread title';
20+
const systemPrompt = 'You are a helpful assistant that writes concise thread titles. ' +
21+
'Return ONLY the title, no quotes or punctuation, 6 words or fewer.';
2122

2223
module.exports = async function summarizeChatThread(params) {
2324
const { authorization, messages } = new SummarizeChatThreadParams(params);
@@ -36,11 +37,28 @@ module.exports = async function summarizeChatThread(params) {
3637

3738
await RateLimit.checkRateLimit('openai', 1000);
3839

39-
messages.unshift({
40-
role: 'system',
41-
content: systemPrompt
42-
});
43-
const res = await getChatCompletion(messages);
40+
const threadText = messages
41+
.filter(m => m.role === 'user' || m.role === 'assistant')
42+
.map(m => `${m.role.toUpperCase()}: ${m.content}`)
43+
.join('\n')
44+
.slice(0, 5000);
45+
46+
const res = await getChatCompletion(
47+
[
48+
{ role: 'system', content: systemPrompt },
49+
{
50+
role: 'user',
51+
content:
52+
'`Summarize the following chat thread into a concise, helpful title (≤ 6 words).\n\n`' +
53+
`${threadText}\n\n` +
54+
'Return only the title.'
55+
}
56+
],
57+
{
58+
max_tokens: 16,
59+
temperature: 0.2
60+
}
61+
);
4462

4563
return {
4664
response: res.choices?.[0]?.message?.content,
@@ -56,8 +74,7 @@ async function getChatCompletion(messages, options = {}) {
5674
'Content-Type': 'application/json'
5775
},
5876
body: JSON.stringify({
59-
model: 'gpt-4o',
60-
max_tokens: 2500,
77+
model: 'gpt-4o-mini',
6178
...options,
6279
messages
6380
})

0 commit comments

Comments
 (0)