|
| 1 | +import { describe, it, expect } from "@jest/globals"; |
| 2 | +import { registry } from "../../../cost/models/registry"; |
| 3 | +import { buildRequestBody } from "../../../cost/models/provider-helpers"; |
| 4 | +import { toChatCompletions } from "@helicone-package/llm-mapper/transform/providers/responses/request/toChatCompletions"; |
| 5 | + |
| 6 | +describe("Helicone provider", () => { |
| 7 | + describe("GPT 4.1 models with RESPONSES bodyMapping", () => { |
| 8 | + const gpt41Models = ["gpt-4.1", "gpt-4.1-mini", "gpt-4.1-nano"]; |
| 9 | + |
| 10 | + gpt41Models.forEach((modelName) => { |
| 11 | + it(`should preserve 'input' parameter for ${modelName} (not convert to 'messages')`, async () => { |
| 12 | + const configResult = registry.getModelProviderConfig( |
| 13 | + modelName, |
| 14 | + "helicone" |
| 15 | + ); |
| 16 | + expect(configResult.data).toBeDefined(); |
| 17 | + |
| 18 | + const endpointResult = registry.buildEndpoint(configResult.data!, {}); |
| 19 | + expect(endpointResult.data).toBeDefined(); |
| 20 | + |
| 21 | + // Responses API format uses 'input', not 'messages' |
| 22 | + const responsesApiBody = { |
| 23 | + model: modelName, |
| 24 | + input: "Hello, world!", |
| 25 | + max_output_tokens: 100, |
| 26 | + }; |
| 27 | + |
| 28 | + const result = await buildRequestBody(endpointResult.data!, { |
| 29 | + parsedBody: responsesApiBody, |
| 30 | + bodyMapping: "RESPONSES", |
| 31 | + toAnthropic: (body: any) => body, |
| 32 | + toChatCompletions: (body: any) => toChatCompletions(body), |
| 33 | + }); |
| 34 | + |
| 35 | + expect(result.data).toBeDefined(); |
| 36 | + const parsedResult = JSON.parse(result.data!); |
| 37 | + |
| 38 | + // Should preserve 'input' and NOT have 'messages' |
| 39 | + expect(parsedResult.input).toBe("Hello, world!"); |
| 40 | + expect(parsedResult.messages).toBeUndefined(); |
| 41 | + }); |
| 42 | + }); |
| 43 | + }); |
| 44 | + |
| 45 | + describe("GPT 4o models with RESPONSES bodyMapping", () => { |
| 46 | + const gpt4oModels = ["gpt-4o", "gpt-4o-mini"]; |
| 47 | + |
| 48 | + gpt4oModels.forEach((modelName) => { |
| 49 | + it(`should preserve 'input' parameter for ${modelName} (not convert to 'messages')`, async () => { |
| 50 | + const configResult = registry.getModelProviderConfig( |
| 51 | + modelName, |
| 52 | + "helicone" |
| 53 | + ); |
| 54 | + |
| 55 | + // Skip if model doesn't have helicone endpoint |
| 56 | + if (!configResult.data) { |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + const endpointResult = registry.buildEndpoint(configResult.data!, {}); |
| 61 | + expect(endpointResult.data).toBeDefined(); |
| 62 | + |
| 63 | + const responsesApiBody = { |
| 64 | + model: modelName, |
| 65 | + input: "Hello, world!", |
| 66 | + max_output_tokens: 100, |
| 67 | + }; |
| 68 | + |
| 69 | + const result = await buildRequestBody(endpointResult.data!, { |
| 70 | + parsedBody: responsesApiBody, |
| 71 | + bodyMapping: "RESPONSES", |
| 72 | + toAnthropic: (body: any) => body, |
| 73 | + toChatCompletions: (body: any) => toChatCompletions(body), |
| 74 | + }); |
| 75 | + |
| 76 | + expect(result.data).toBeDefined(); |
| 77 | + const parsedResult = JSON.parse(result.data!); |
| 78 | + |
| 79 | + // Should preserve 'input' and NOT have 'messages' |
| 80 | + expect(parsedResult.input).toBe("Hello, world!"); |
| 81 | + expect(parsedResult.messages).toBeUndefined(); |
| 82 | + }); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe("Anthropic models with RESPONSES bodyMapping", () => { |
| 87 | + it("should convert 'input' to 'messages' for Claude models", async () => { |
| 88 | + const configResult = registry.getModelProviderConfig( |
| 89 | + "claude-sonnet-4", |
| 90 | + "helicone" |
| 91 | + ); |
| 92 | + |
| 93 | + // Skip if model doesn't have helicone endpoint |
| 94 | + if (!configResult.data) { |
| 95 | + return; |
| 96 | + } |
| 97 | + |
| 98 | + const endpointResult = registry.buildEndpoint(configResult.data!, {}); |
| 99 | + expect(endpointResult.data).toBeDefined(); |
| 100 | + |
| 101 | + const responsesApiBody = { |
| 102 | + model: "claude-sonnet-4", |
| 103 | + input: "Hello, world!", |
| 104 | + max_output_tokens: 100, |
| 105 | + }; |
| 106 | + |
| 107 | + const result = await buildRequestBody(endpointResult.data!, { |
| 108 | + parsedBody: responsesApiBody, |
| 109 | + bodyMapping: "RESPONSES", |
| 110 | + toAnthropic: (body: any, modelId: string) => ({ |
| 111 | + ...body, |
| 112 | + model: modelId, |
| 113 | + }), |
| 114 | + toChatCompletions: (body: any) => toChatCompletions(body), |
| 115 | + }); |
| 116 | + |
| 117 | + expect(result.data).toBeDefined(); |
| 118 | + const parsedResult = JSON.parse(result.data!); |
| 119 | + |
| 120 | + // Should have 'messages' (converted from 'input') for Anthropic |
| 121 | + // The body goes through toChatCompletions then toAnthropic |
| 122 | + expect(parsedResult.messages).toBeDefined(); |
| 123 | + expect(parsedResult.input).toBeUndefined(); |
| 124 | + }); |
| 125 | + }); |
| 126 | +}); |
0 commit comments