add metadata to generate suggested prompts

This commit is contained in:
Wells Bunker 2025-09-24 15:10:11 -06:00
parent e46da44445
commit 9a046f7911
No known key found for this signature in database
GPG Key ID: DB16D6F2679B78FC
1 changed files with 13 additions and 5 deletions

View File

@ -1,6 +1,7 @@
import { getUser } from '@buster/database/queries';
import { DEFAULT_USER_SUGGESTED_PROMPTS } from '@buster/database/schema-types'; import { DEFAULT_USER_SUGGESTED_PROMPTS } from '@buster/database/schema-types';
import { generateObject } from 'ai'; import { generateObject } from 'ai';
import { wrapTraced } from 'braintrust'; import { currentSpan, wrapTraced } from 'braintrust';
import { z } from 'zod'; import { z } from 'zod';
import { GPT5Nano } from '../../llm'; import { GPT5Nano } from '../../llm';
import SUGGESTED_PROMPTS_SYSTEM_PROMPT from './suggested-prompts-system-prompt.txt'; import SUGGESTED_PROMPTS_SYSTEM_PROMPT from './suggested-prompts-system-prompt.txt';
@ -46,8 +47,19 @@ ${chatHistoryText}
Generate suggestions that are relevant to the conversation context and available data.`; Generate suggestions that are relevant to the conversation context and available data.`;
const userInfo = await getUser({ id: userId });
const tracedGeneration = wrapTraced( const tracedGeneration = wrapTraced(
async () => { async () => {
currentSpan().log({
metadata: {
userName: userInfo.name || 'Unknown',
userEmail: userInfo.email,
userId: userId,
chatHistoryTextLength: chatHistoryText.length,
},
});
const result = await generateObject({ const result = await generateObject({
model: GPT5Nano, model: GPT5Nano,
prompt: userMessage, prompt: userMessage,
@ -74,10 +86,6 @@ Generate suggestions that are relevant to the conversation context and available
}, },
{ {
name: 'Generate Suggested Prompts', name: 'Generate Suggested Prompts',
spanAttributes: {
chatHistoryLength: chatHistoryText.length,
userId: userId,
},
} }
); );