@@ -13,9 +13,9 @@ import { AttemptExecutor } from "./AttemptExecutor";
1313import { Attempt , DisallowListEntry , EscrowInfo } from "./types" ;
1414import { oai2antResponse } from "../clients/llmmapper/router/oai2ant/nonStream" ;
1515import { oai2antStreamResponse } from "../clients/llmmapper/router/oai2ant/stream" ;
16- import { ModelProviderName } from "@helicone-package/cost/models/providers" ;
1716import { RequestParams } from "@helicone-package/cost/models/types" ;
1817import { SecureCacheProvider } from "../util/cache/secureCache" ;
18+ import { determineResponseFormat } from "@helicone-package/cost/models/provider-helpers" ;
1919
2020export interface AuthContext {
2121 orgId : string ;
@@ -303,22 +303,6 @@ export class SimpleAIGateway {
303303 ) ;
304304 }
305305
306- private determineResponseFormat (
307- provider : ModelProviderName ,
308- modelId : string
309- ) : "ANTHROPIC" | "OPENAI" {
310- // TODO: make enum type when there's more map formats
311- if (
312- provider === "anthropic" ||
313- ( provider === "bedrock" && modelId . includes ( "claude-" ) ) ||
314- ( provider === "vertex" && modelId . includes ( "claude-" ) )
315- ) {
316- return "ANTHROPIC" ;
317- }
318-
319- return "OPENAI" ;
320- }
321-
322306 private async mapResponse (
323307 attempt : Attempt ,
324308 response : Response ,
@@ -328,17 +312,18 @@ export class SimpleAIGateway {
328312 return ok ( response ) ; // do not map response
329313 }
330314
331- const mappingType = this . determineResponseFormat (
332- attempt . endpoint . provider ,
333- attempt . endpoint . providerModelId
334- ) ; // finds format of the response that we are mapping to OPENAI
315+ const mappingType = determineResponseFormat ( attempt . endpoint ) ;
316+
317+ if ( isErr ( mappingType ) ) {
318+ return err ( `Failed to determine response format: ${ mappingType . error } ` ) ;
319+ }
335320
336- if ( mappingType === "OPENAI" ) {
321+ if ( mappingType . data === "OPENAI" ) {
337322 return ok ( response ) ; // already in OPENAI format
338323 }
339324
340325 try {
341- if ( mappingType === "ANTHROPIC" ) {
326+ if ( mappingType . data === "ANTHROPIC" ) {
342327 const contentType = response . headers . get ( "content-type" ) ;
343328 const isStream = contentType ?. includes ( "text/event-stream" ) ;
344329
0 commit comments