diff --git a/products/ai_observability/frontend/prompts/promptSceneComponents.tsx b/products/ai_observability/frontend/prompts/promptSceneComponents.tsx index d43e32ac5251..712ed1f404bd 100644 --- a/products/ai_observability/frontend/prompts/promptSceneComponents.tsx +++ b/products/ai_observability/frontend/prompts/promptSceneComponents.tsx @@ -530,11 +530,15 @@ function buildPythonSnippet( host: string, projectApiKey: string, variables: string[], - labelName?: string + labelName?: string, + showConfig?: boolean ): string { const compileLines = variables.length ? `\nsystem_prompt = prompts.compile(result.prompt, {${variables.map((v) => `${JSON.stringify(v)}: '...'`).join(', ')}})` : '' + const configLines = showConfig + ? `\nmodel = (result.config or {}).get('model', 'your-default-model') # config stored with this prompt version` + : '' const labelArg = labelName ? `label=${JSON.stringify(labelName)}, ` : '' return `from posthog import Posthog from posthog.ai.prompts import Prompts @@ -546,7 +550,7 @@ posthog = Posthog( ) prompts = Prompts(posthog) -result = prompts.get(${JSON.stringify(promptName)}, ${labelArg}with_metadata=True, fallback='You are a helpful assistant.')${compileLines} +result = prompts.get(${JSON.stringify(promptName)}, ${labelArg}with_metadata=True, fallback='You are a helpful assistant.')${compileLines}${configLines} # result.name / result.version -> send as $ai_prompt_name / $ai_prompt_version on your LLM events` } @@ -555,11 +559,15 @@ function buildNodeSnippet( host: string, projectApiKey: string, variables: string[], - labelName?: string + labelName?: string, + showConfig?: boolean ): string { const compileLines = variables.length ? `\nconst systemPrompt = prompts.compile(result.prompt, {${variables.map((v) => ` ${JSON.stringify(v)}: '...'`).join(',')} })` : '' + const configLines = showConfig + ? `\nconst model = result.config?.model ?? 'your-default-model' // config stored with this prompt version` + : '' const labelArg = labelName ? `label: '${labelName}', ` : '' return `import { Prompts } from '@posthog/ai' import { PostHog } from 'posthog-node' @@ -570,7 +578,7 @@ const posthog = new PostHog('${projectApiKey}', { }) const prompts = new Prompts({ posthog }) -const result = await prompts.get(${JSON.stringify(promptName)}, { ${labelArg}fallback: 'You are a helpful assistant.' })${compileLines} +const result = await prompts.get(${JSON.stringify(promptName)}, { ${labelArg}fallback: 'You are a helpful assistant.' })${compileLines}${configLines} // result.name / result.version -> send as $ai_prompt_name / $ai_prompt_version on your LLM events` } @@ -588,6 +596,8 @@ export function PromptCodeSnippets({ prompt }: { prompt: LLMPrompt }): JSX.Eleme const snippetLabel = labelsEnabled ? (promptLabels.find((label) => label.name === 'production') ?? promptLabels[0])?.name : undefined + // Same principle for config: only show the usage line once this prompt has one. + const showConfig = !!featureFlags[FEATURE_FLAGS.LLM_PROMPT_CONFIG] && prompt.config != null return (
@@ -620,7 +630,14 @@ export function PromptCodeSnippets({ prompt }: { prompt: LLMPrompt }): JSX.Eleme label: 'Python', content: ( - {buildPythonSnippet(prompt.name, host, projectApiKey, variables, snippetLabel)} + {buildPythonSnippet( + prompt.name, + host, + projectApiKey, + variables, + snippetLabel, + showConfig + )} ), }, @@ -629,7 +646,14 @@ export function PromptCodeSnippets({ prompt }: { prompt: LLMPrompt }): JSX.Eleme label: 'Node.js', content: ( - {buildNodeSnippet(prompt.name, host, projectApiKey, variables, snippetLabel)} + {buildNodeSnippet( + prompt.name, + host, + projectApiKey, + variables, + snippetLabel, + showConfig + )} ), },