Files
dataroom/features/ai/lib/chat/generate-chat-title.ts
zeekay 98f0da7fa5 ci: amd64-only build (matches hanzo runner pool topology)
hanzo-build-linux-amd64 is the only ARC runner pool installed on
hanzo-k8s today (arm64 pool is paused until DigitalOcean ships
arm64 droplets, per ~/work/hanzo/.github/RUNNERS.md). The arm64
job was waiting on spark-hanzoai-arm64 — not provisioned in this
cluster — so every build sat in queue forever and the amd64 leg
got cancelled.

Set platforms: linux/amd64 on the reusable build call to skip
arm64 entirely. Re-add arm64 if/when DO ships arm64 droplets and
the spark runner pool comes back online.
2026-06-07 11:38:49 -07:00

37 lines
1.1 KiB
TypeScript

import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";
/**
* Generate a chat title from the first message
* @param firstMessage - The first user message
* @returns Generated title
*/
export async function generateChatTitle(firstMessage: string): Promise<string> {
try {
// Limit message length for title generation
const truncatedMessage = firstMessage.slice(0, 200);
const { text } = await generateText({
model: openai("gpt-4o-mini"),
prompt: `Generate a short, descriptive title (max 6 words) for a chat that starts with this message: "${truncatedMessage}". Only return the title, nothing else.`,
providerOptions: {
openai: {
maxOutputTokens: 20,
},
},
});
// Clean up the title
const title = text
.trim()
.replace(/^["']|["']$/g, "") // Remove quotes
.slice(0, 60); // Max 60 chars
return title;
} catch (error) {
console.error("Error generating chat title:", error);
// Return a default title based on first few words
return firstMessage.slice(0, 50) + (firstMessage.length > 50 ? "..." : "");
}
}