:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(aio): normalize playground provider names before completion requests (#113040)
Juraj Majerikc96ea7eb5966
diff --git a/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.test.ts b/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.test.tsindex 93ccbe5ad5ca..cfb81f8fdfa2 100644--- a/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.test.ts+++ b/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.test.ts@@ -109,6 +109,38 @@ describe('llmPlaygroundRunLogic', () => {streamSpy.mockRestore()})+ it('normalizes a display-name provider to its enum value in the completion payload', async () => {+ useMocks({+ get: {+ '/api/llm_proxy/models/': [+ {+ id: 'my-gpt4-deployment',+ name: 'my-gpt4-deployment',+ provider: 'Azure OpenAI',+ description: '',+ },+ ],+ },+ })+ const streamSpy = jest.spyOn(api, 'stream').mockImplementation(async () => {})++ const logic = llmPlaygroundRunLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ llmPlaygroundPromptsLogic.actions.setModel('my-gpt4-deployment')+ llmPlaygroundPromptsLogic.actions.setMessages([{ role: 'user', content: 'hello' }])+ llmPlaygroundRunLogic.actions.submitPrompt()++ await expectLogic(logic).toFinishAllListeners()++ expect(streamSpy).toHaveBeenCalledTimes(1)+ expect(streamSpy.mock.calls[0][1]?.data).toMatchObject({ provider: 'azure_openai' })++ logic.unmount()+ streamSpy.mockRestore()+ })+it('sends variable-substituted content while the editor keeps the raw template', async () => {const streamSpy = jest.spyOn(api, 'stream').mockImplementation(async () => {})diff --git a/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.ts b/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.tsindex db3e42129a18..df8fd375d0e7 100644--- a/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.ts+++ b/products/ai_observability/frontend/playground/llmPlaygroundRunLogic.ts@@ -11,7 +11,7 @@ import { uuid } from 'lib/utils/dom'import { AccessControlLevel, AccessControlResourceType } from '~/types'import type { ModelOption } from '../modelPickerLogic'-import { llmProviderKeysLogic } from '../settings/llmProviderKeysLogic'+import { llmProviderKeysLogic, normalizeLLMProvider } from '../settings/llmProviderKeysLogic'import type { LLMProviderKey } from '../settings/llmProviderKeysLogic'import { llmPlaygroundModelLogic } from './llmPlaygroundModelLogic'import { llmPlaygroundPromptsLogic, type Message, type PromptConfig } from './llmPlaygroundPromptsLogic'@@ -437,10 +437,23 @@ export const llmPlaygroundRunLogic = kea<llmPlaygroundRunLogicType>([return}+ // Model options carry the provider's display name ("Azure OpenAI"), but the+ // completion endpoint validates against enum values ("azure_openai").+ const normalizedProvider = normalizeLLMProvider(selectedModel.provider)+ if (!normalizedProvider) {+ const describeUnknownProvider = (model: string): string =>+ `Model '${model}' has a provider PostHog does not recognize. Pick a different model and try again.`+ lemonToast.error(describeUnknownProvider(prompt.model))+ responseText = `**Error:** ${describeUnknownProvider(escapeMarkdownInline(prompt.model))}`+ responseHasError = true+ upsertLiveItem()+ return+ }+providerKeyId =resolveProviderKeyForPrompt(prompt, values.effectiveModelOptions, values.providerKeys)?.id ?? values.activeProviderKeyId- selectedModelProvider = selectedModel.provider.toLowerCase()+ selectedModelProvider = normalizedProviderconst requestData: Record<string, unknown> = {system: resolvedSystemPrompt,