From 3ec47bd3fe5ef076e44755a9b0830a5d7e29be88 Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 22 Jan 2025 15:02:24 -0800 Subject: [PATCH] fix cost test --- bifrost/packages/cost/providers/mappings.ts | 9 +++++++++ costs/__tests__/ensureOnlyOne.ts | 9 +++++++++ valhalla/jawn/src/packages/cost/providers/mappings.ts | 9 +++++++++ valhalla/jawn/src/tsoa-build/private/routes.ts | 2 +- valhalla/jawn/src/tsoa-build/private/swagger.json | 3 ++- web/packages/cost/providers/mappings.ts | 9 +++++++++ worker/src/packages/cost/providers/mappings.ts | 9 +++++++++ 7 files changed, 48 insertions(+), 2 deletions(-) diff --git a/bifrost/packages/cost/providers/mappings.ts b/bifrost/packages/cost/providers/mappings.ts index 33d6215fe..2a7fdf359 100644 --- a/bifrost/packages/cost/providers/mappings.ts +++ b/bifrost/packages/cost/providers/mappings.ts @@ -16,6 +16,7 @@ import { openAIProvider } from "./openai"; import { anthropicProvider } from "./anthropic"; import { costs as awsBedrockCosts } from "./awsBedrock"; import { costs as deepseekCosts } from "./deepseek"; +import { costs as xCosts } from "./x"; const openAiPattern = /^https:\/\/api\.openai\.com/; const anthropicPattern = /^https:\/\/api\.anthropic\.com/; @@ -52,6 +53,8 @@ const firecrawl = /^https:\/\/api\.firecrawl\.dev/; const awsBedrock = /^https:\/\/bedrock-runtime\.[a-z0-9-]+\.amazonaws\.com\/.*/; // https://api.deepseek.com const deepseek = /^https:\/\/api\.deepseek\.com/; +// https://api.x.ai +const x = /^https:\/\/api\.x\.ai/; export const providersNames = [ "OPENAI", @@ -78,6 +81,7 @@ export const providersNames = [ "FIRECRAWL", "AWS", "DEEPSEEK", + "X", ] as const; export type ProviderName = (typeof providersNames)[number]; @@ -127,6 +131,11 @@ export const providers: { pattern: cloudflareAiGatewayPattern, provider: "CLOUDFLARE", }, + { + pattern: x, + provider: "X", + costs: xCosts, + }, { pattern: twoYFV, provider: "2YFV", diff --git a/costs/__tests__/ensureOnlyOne.ts b/costs/__tests__/ensureOnlyOne.ts index af56e59da..c2b7da7ce 100644 --- a/costs/__tests__/ensureOnlyOne.ts +++ b/costs/__tests__/ensureOnlyOne.ts @@ -388,6 +388,15 @@ WHEN (request_response_rmt.model ILIKE 'o1-mini-2024-09-12') THEN 3000 * request ELSE 0 END ) +WHEN (request_response_rmt.provider = 'X') THEN ( + CASE + WHEN (request_response_rmt.model ILIKE 'grok-beta') THEN 5000 * request_response_rmt.prompt_tokens + 15000 * request_response_rmt.completion_tokens +WHEN (request_response_rmt.model ILIKE 'grok-vision-beta') THEN 5000 * request_response_rmt.prompt_tokens + 15000 * request_response_rmt.completion_tokens +WHEN (request_response_rmt.model ILIKE 'grok-2-1212') THEN 2000 * request_response_rmt.prompt_tokens + 10000 * request_response_rmt.completion_tokens +WHEN (request_response_rmt.model ILIKE 'grok-2-vision-1212') THEN 2000 * request_response_rmt.prompt_tokens + 10000 * request_response_rmt.completion_tokens + ELSE 0 +END +) WHEN (request_response_rmt.provider = 'TOGETHER') THEN ( CASE WHEN (request_response_rmt.model ILIKE 'allenai/OLMo-7B-Instruct') THEN 200 * request_response_rmt.prompt_tokens + 200 * request_response_rmt.completion_tokens diff --git a/valhalla/jawn/src/packages/cost/providers/mappings.ts b/valhalla/jawn/src/packages/cost/providers/mappings.ts index 33d6215fe..2a7fdf359 100644 --- a/valhalla/jawn/src/packages/cost/providers/mappings.ts +++ b/valhalla/jawn/src/packages/cost/providers/mappings.ts @@ -16,6 +16,7 @@ import { openAIProvider } from "./openai"; import { anthropicProvider } from "./anthropic"; import { costs as awsBedrockCosts } from "./awsBedrock"; import { costs as deepseekCosts } from "./deepseek"; +import { costs as xCosts } from "./x"; const openAiPattern = /^https:\/\/api\.openai\.com/; const anthropicPattern = /^https:\/\/api\.anthropic\.com/; @@ -52,6 +53,8 @@ const firecrawl = /^https:\/\/api\.firecrawl\.dev/; const awsBedrock = /^https:\/\/bedrock-runtime\.[a-z0-9-]+\.amazonaws\.com\/.*/; // https://api.deepseek.com const deepseek = /^https:\/\/api\.deepseek\.com/; +// https://api.x.ai +const x = /^https:\/\/api\.x\.ai/; export const providersNames = [ "OPENAI", @@ -78,6 +81,7 @@ export const providersNames = [ "FIRECRAWL", "AWS", "DEEPSEEK", + "X", ] as const; export type ProviderName = (typeof providersNames)[number]; @@ -127,6 +131,11 @@ export const providers: { pattern: cloudflareAiGatewayPattern, provider: "CLOUDFLARE", }, + { + pattern: x, + provider: "X", + costs: xCosts, + }, { pattern: twoYFV, provider: "2YFV", diff --git a/valhalla/jawn/src/tsoa-build/private/routes.ts b/valhalla/jawn/src/tsoa-build/private/routes.ts index 1f6be8c40..1ceee6112 100644 --- a/valhalla/jawn/src/tsoa-build/private/routes.ts +++ b/valhalla/jawn/src/tsoa-build/private/routes.ts @@ -496,7 +496,7 @@ const models: TsoaRoute.Models = { // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa "ProviderName": { "dataType": "refAlias", - "type": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["OPENAI"]},{"dataType":"enum","enums":["ANTHROPIC"]},{"dataType":"enum","enums":["AZURE"]},{"dataType":"enum","enums":["LOCAL"]},{"dataType":"enum","enums":["HELICONE"]},{"dataType":"enum","enums":["AMDBARTEK"]},{"dataType":"enum","enums":["ANYSCALE"]},{"dataType":"enum","enums":["CLOUDFLARE"]},{"dataType":"enum","enums":["2YFV"]},{"dataType":"enum","enums":["TOGETHER"]},{"dataType":"enum","enums":["LEMONFOX"]},{"dataType":"enum","enums":["FIREWORKS"]},{"dataType":"enum","enums":["PERPLEXITY"]},{"dataType":"enum","enums":["GOOGLE"]},{"dataType":"enum","enums":["OPENROUTER"]},{"dataType":"enum","enums":["WISDOMINANUTSHELL"]},{"dataType":"enum","enums":["GROQ"]},{"dataType":"enum","enums":["COHERE"]},{"dataType":"enum","enums":["MISTRAL"]},{"dataType":"enum","enums":["DEEPINFRA"]},{"dataType":"enum","enums":["QSTASH"]},{"dataType":"enum","enums":["FIRECRAWL"]},{"dataType":"enum","enums":["AWS"]},{"dataType":"enum","enums":["DEEPSEEK"]}],"validators":{}}, + "type": {"dataType":"union","subSchemas":[{"dataType":"enum","enums":["OPENAI"]},{"dataType":"enum","enums":["ANTHROPIC"]},{"dataType":"enum","enums":["AZURE"]},{"dataType":"enum","enums":["LOCAL"]},{"dataType":"enum","enums":["HELICONE"]},{"dataType":"enum","enums":["AMDBARTEK"]},{"dataType":"enum","enums":["ANYSCALE"]},{"dataType":"enum","enums":["CLOUDFLARE"]},{"dataType":"enum","enums":["2YFV"]},{"dataType":"enum","enums":["TOGETHER"]},{"dataType":"enum","enums":["LEMONFOX"]},{"dataType":"enum","enums":["FIREWORKS"]},{"dataType":"enum","enums":["PERPLEXITY"]},{"dataType":"enum","enums":["GOOGLE"]},{"dataType":"enum","enums":["OPENROUTER"]},{"dataType":"enum","enums":["WISDOMINANUTSHELL"]},{"dataType":"enum","enums":["GROQ"]},{"dataType":"enum","enums":["COHERE"]},{"dataType":"enum","enums":["MISTRAL"]},{"dataType":"enum","enums":["DEEPINFRA"]},{"dataType":"enum","enums":["QSTASH"]},{"dataType":"enum","enums":["FIRECRAWL"]},{"dataType":"enum","enums":["AWS"]},{"dataType":"enum","enums":["DEEPSEEK"]},{"dataType":"enum","enums":["X"]}],"validators":{}}, }, // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa "Provider": { diff --git a/valhalla/jawn/src/tsoa-build/private/swagger.json b/valhalla/jawn/src/tsoa-build/private/swagger.json index 17d7e6787..8f6f98840 100644 --- a/valhalla/jawn/src/tsoa-build/private/swagger.json +++ b/valhalla/jawn/src/tsoa-build/private/swagger.json @@ -1180,7 +1180,8 @@ "QSTASH", "FIRECRAWL", "AWS", - "DEEPSEEK" + "DEEPSEEK", + "X" ] }, "Provider": { diff --git a/web/packages/cost/providers/mappings.ts b/web/packages/cost/providers/mappings.ts index 33d6215fe..2a7fdf359 100644 --- a/web/packages/cost/providers/mappings.ts +++ b/web/packages/cost/providers/mappings.ts @@ -16,6 +16,7 @@ import { openAIProvider } from "./openai"; import { anthropicProvider } from "./anthropic"; import { costs as awsBedrockCosts } from "./awsBedrock"; import { costs as deepseekCosts } from "./deepseek"; +import { costs as xCosts } from "./x"; const openAiPattern = /^https:\/\/api\.openai\.com/; const anthropicPattern = /^https:\/\/api\.anthropic\.com/; @@ -52,6 +53,8 @@ const firecrawl = /^https:\/\/api\.firecrawl\.dev/; const awsBedrock = /^https:\/\/bedrock-runtime\.[a-z0-9-]+\.amazonaws\.com\/.*/; // https://api.deepseek.com const deepseek = /^https:\/\/api\.deepseek\.com/; +// https://api.x.ai +const x = /^https:\/\/api\.x\.ai/; export const providersNames = [ "OPENAI", @@ -78,6 +81,7 @@ export const providersNames = [ "FIRECRAWL", "AWS", "DEEPSEEK", + "X", ] as const; export type ProviderName = (typeof providersNames)[number]; @@ -127,6 +131,11 @@ export const providers: { pattern: cloudflareAiGatewayPattern, provider: "CLOUDFLARE", }, + { + pattern: x, + provider: "X", + costs: xCosts, + }, { pattern: twoYFV, provider: "2YFV", diff --git a/worker/src/packages/cost/providers/mappings.ts b/worker/src/packages/cost/providers/mappings.ts index 33d6215fe..2a7fdf359 100644 --- a/worker/src/packages/cost/providers/mappings.ts +++ b/worker/src/packages/cost/providers/mappings.ts @@ -16,6 +16,7 @@ import { openAIProvider } from "./openai"; import { anthropicProvider } from "./anthropic"; import { costs as awsBedrockCosts } from "./awsBedrock"; import { costs as deepseekCosts } from "./deepseek"; +import { costs as xCosts } from "./x"; const openAiPattern = /^https:\/\/api\.openai\.com/; const anthropicPattern = /^https:\/\/api\.anthropic\.com/; @@ -52,6 +53,8 @@ const firecrawl = /^https:\/\/api\.firecrawl\.dev/; const awsBedrock = /^https:\/\/bedrock-runtime\.[a-z0-9-]+\.amazonaws\.com\/.*/; // https://api.deepseek.com const deepseek = /^https:\/\/api\.deepseek\.com/; +// https://api.x.ai +const x = /^https:\/\/api\.x\.ai/; export const providersNames = [ "OPENAI", @@ -78,6 +81,7 @@ export const providersNames = [ "FIRECRAWL", "AWS", "DEEPSEEK", + "X", ] as const; export type ProviderName = (typeof providersNames)[number]; @@ -127,6 +131,11 @@ export const providers: { pattern: cloudflareAiGatewayPattern, provider: "CLOUDFLARE", }, + { + pattern: x, + provider: "X", + costs: xCosts, + }, { pattern: twoYFV, provider: "2YFV",