Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/util/db-schema/purchase-quotas.ts
Views: 687
import { CREATED_BY, ID } from "./crm";1import { SCHEMA as schema } from "./index";2import { LLM_USERNAMES } from "./llm-utils";3import type { Service } from "./purchases";4import { Table } from "./types";56export type { Service };78// Users will set their spend limits for these broad categories.9// TODO: right now there is a separate limit for each quota spec,10// which has got ridiculous.11const SERVICE_CATEGORIES = ["money", "compute", "license", "ai"];12type ServiceCategory = (typeof SERVICE_CATEGORIES)[number];1314interface Spec {15display: string; // what to show user to describe this service16noSet?: boolean; // if true, then no spend limits are set for this.17color: string;18category: ServiceCategory;19}2021export type QuotaSpec = Record<Service, Spec>;2223const GPT_TURBO_128k: Spec = {24display: "OpenAI GPT-4 Turbo 128k",25color: "#10a37f",26category: "ai",27} as const;2829const GPT_TURBO_8K: Spec = {30...GPT_TURBO_128k,31display: "OpenAI GPT-4 Turbo",32} as const;3334const GPT_OMNI_128k: Spec = {35display: "OpenAI GPT-4o 128k",36color: "#10a37f",37category: "ai",38} as const;3940const GPT_OMNI_8K: Spec = {41...GPT_OMNI_128k,42display: "OpenAI GPT-4o",43} as const;4445const GPT_OMNI_MINI_128k: Spec = {46...GPT_OMNI_128k,47display: "OpenAI GPT-4o Mini 128k",48};4950const GPT_OMNI_MINI_8K: Spec = {51...GPT_OMNI_MINI_128k,52display: "OpenAI GPT-4o Mini",53};5455const GOOGLE_AI_COLOR = "#ff4d4f";5657// NOTE: all-quotas-config.tsx will automatically filter out those, which are free or not selectable by the user58export const QUOTA_SPEC: QuotaSpec = {59credit: { display: "Credit", noSet: true, color: "green", category: "money" },60refund: { display: "Refund", noSet: true, color: "red", category: "money" },61"project-upgrade": {62display: "Project Upgrade",63color: "#5bc0de",64category: "compute",65},66"compute-server": {67display: "Compute Server",68color: "#2196f3",69category: "compute",70},71"compute-server-network-usage": {72display: "Network Data",73color: "#2196f3",74category: "compute",75},76"compute-server-storage": {77display: "Cloud Storage",78color: "#fbbd05",79category: "compute",80},81license: {82display: "License",83color: "cyan",84noSet: true,85category: "license",86},87"edit-license": {88display: "Edit License",89color: "gold",90noSet: true,91category: "license",92},93voucher: {94display: "Voucher",95color: "#00238b",96noSet: true,97category: "money",98},99// ATTN: LLMs comes below this line, the quotas above are the important ones to show first!100"openai-gpt-4": { display: "OpenAI GPT-4", color: "#10a37f", category: "ai" },101"openai-gpt-3.5-turbo": {102display: "OpenAI GPT-3.5",103color: "#10a37f",104category: "ai",105},106"openai-gpt-3.5-turbo-16k": {107display: "OpenAI GPT-3.5 16k",108color: "#10a37f",109category: "ai",110},111"openai-text-embedding-ada-002": {112display: "OpenAI Text Embedding Ada 002",113color: "#10a37f",114noSet: true, // because this model is not user visible yet115category: "ai",116},117"openai-gpt-4-32k": {118display: "OpenAI GPT-4 32k",119color: "#10a37f",120category: "ai",121},122"openai-gpt-4-turbo-preview": GPT_TURBO_128k, // the "preview" is over123"openai-gpt-4-turbo-preview-8k": GPT_TURBO_8K, // the "preview" is over124"openai-gpt-4-turbo": GPT_TURBO_128k,125"openai-gpt-4-turbo-8k": GPT_TURBO_8K,126"openai-gpt-4o": GPT_OMNI_128k,127"openai-gpt-4o-8k": GPT_OMNI_8K,128"openai-gpt-4o-mini": GPT_OMNI_MINI_128k,129"openai-gpt-4o-mini-8k": GPT_OMNI_MINI_8K,130"google-text-bison-001": {131display: "Google Palm 2 (Text)",132color: GOOGLE_AI_COLOR,133noSet: true, // deprecated, will be removed134category: "ai",135},136"google-chat-bison-001": {137display: "Google Palm 2 (Chat)",138color: GOOGLE_AI_COLOR,139noSet: true, // deprecated, will be removed140category: "ai",141},142"google-embedding-gecko-001": {143display: "Google Gecko (Embedding)",144color: GOOGLE_AI_COLOR,145noSet: true, // deprecated, will be removed146category: "ai",147},148"google-gemini-1.5-flash-8k": {149display: "Google Gemini 1.5 Flash",150color: GOOGLE_AI_COLOR,151category: "ai",152},153"google-gemini-pro": {154display: "Google Gemini 1.0 Pro",155color: GOOGLE_AI_COLOR,156category: "ai",157},158"google-gemini-1.0-ultra": {159display: "Google Gemini 1.0 Ultra",160color: GOOGLE_AI_COLOR,161category: "ai",162},163"google-gemini-1.5-pro-8k": {164display: LLM_USERNAMES["gemini-1.5-pro-8k"],165color: GOOGLE_AI_COLOR,166category: "ai",167},168"google-gemini-1.5-pro": {169display: LLM_USERNAMES["gemini-1.5-pro"],170color: GOOGLE_AI_COLOR,171category: "ai",172},173"anthropic-claude-3-opus": {174display: LLM_USERNAMES["claude-3-opus"],175color: "#181818",176category: "ai",177},178"anthropic-claude-3-opus-8k": {179display: LLM_USERNAMES["claude-3-opus-8k"],180color: "#181818",181category: "ai",182},183"anthropic-claude-3-sonnet": {184display: LLM_USERNAMES["claude-3-sonnet"],185color: "#181818",186category: "ai",187},188"anthropic-claude-3-sonnet-4k": {189display: LLM_USERNAMES["claude-3-sonnet-4k"],190color: "#181818",191category: "ai",192},193"anthropic-claude-3-5-sonnet": {194display: LLM_USERNAMES["claude-3-5-sonnet"],195color: "#181818",196category: "ai",197},198"anthropic-claude-3-5-sonnet-4k": {199display: LLM_USERNAMES["claude-3-5-sonnet-4k"],200color: "#181818",201category: "ai",202},203"anthropic-claude-3-haiku": {204display: LLM_USERNAMES["claude-3-haiku"],205color: "#181818",206category: "ai",207},208"anthropic-claude-3-haiku-8k": {209display: LLM_USERNAMES["claude-3-haiku-8k"],210color: "#181818",211category: "ai",212},213"mistralai-mistral-small-latest": {214display: LLM_USERNAMES["mistral-small-latest"],215color: "#ff7000", // the orange from their website216category: "ai",217},218"mistralai-mistral-medium-latest": {219display: LLM_USERNAMES["mistral-medium-latest"],220color: "#ff7000", // the orange from their website221category: "ai",222},223"mistralai-mistral-large-latest": {224display: LLM_USERNAMES["mistral-large-latest"],225color: "#ff7000", // the orange from their website226category: "ai",227},228} as const;229230// For pay-as-you-go project quota upgrades231export interface ProjectQuota {232cost?: number; // dollars per hour233enabled?: number;234cores?: number;235disk_quota?: number;236memory?: number;237mintime?: number;238network?: number;239member_host?: number;240always_running?: number;241}242243export const PROJECT_QUOTA_KEYS = new Set<string>([244"enabled",245"cost",246"cores",247"disk_quota",248"memory",249"mintime",250"network",251"member_host",252"always_running",253]);254255export function serviceToDisplay(service: Service): string {256return QUOTA_SPEC[service]?.display ?? service;257}258259Table({260name: "purchase_quotas",261fields: {262id: ID,263account_id: CREATED_BY,264service: {265title: "Service Category",266desc: "The service being charged for, e.g., openai-gpt-4, project-upgrade, etc.",267type: "string",268pg_type: "varchar(127)",269},270value: {271title: "Value",272desc: "The maximum amount that user can be charged for this service during one month billing period, in US dollars.",273type: "number", // actually comes back as string in queries.274pg_type: "REAL",275},276},277rules: {278desc: "Purchase Quotas",279primary_key: "id",280// make it fast to find all quotas for a given account281pg_indexes: ["account_id"],282// enforce that there is only one quota for each service for a given account283pg_unique_indexes: ["(account_id,service)"],284user_query: {285// set happens though v2 api only to enforce global quota286get: {287pg_where: [{ "account_id = $::UUID": "account_id" }],288fields: {289id: null,290account_id: null,291service: null,292value: null,293},294},295},296},297});298299Table({300name: "crm_purchase_quotas",301rules: {302virtual: "purchase_quotas",303primary_key: "id",304user_query: {305get: {306pg_where: [],307admin: true,308fields: {309id: null,310account_id: null,311service: null,312value: null,313},314},315set: {316admin: true,317fields: {318id: true,319account_id: true,320service: true,321value: true,322},323},324},325},326fields: schema.purchase_quotas.fields,327});328329330