mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Extract context_length and pricing from API if available
This commit is contained in:
3 files changed
+45
-10
No files matched your search
Generated
+4
-4
@@ -51,6 +51,7 @@
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.0.0",
|
||||
"decimal.js": "^10.6.0",
|
||||
"embla-carousel-react": "^8.3.0",
|
||||
"esbuild-wasm": "^0.25.8",
|
||||
"input-otp": "^1.2.4",
|
||||
@@ -5201,10 +5202,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/decimal.js": {
|
||||
"version": "10.5.0",
|
||||
"resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.5.0.tgz",
|
||||
"integrity": "sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw==",
|
||||
"dev": true,
|
||||
"version": "10.6.0",
|
||||
"resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz",
|
||||
"integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/decimal.js-light": {
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.0.0",
|
||||
"decimal.js": "^10.6.0",
|
||||
"embla-carousel-react": "^8.3.0",
|
||||
"esbuild-wasm": "^0.25.8",
|
||||
"input-otp": "^1.2.4",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { Decimal } from 'decimal.js';
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import OpenAI from 'openai';
|
||||
@@ -8,6 +9,15 @@ interface ProviderModel {
|
||||
name: string;
|
||||
provider: string;
|
||||
fullId: string; // provider/model format
|
||||
/** Maximum size of context window, if available */
|
||||
context_length?: number;
|
||||
/** Pricing information, if available */
|
||||
pricing?: {
|
||||
/** Input/prompt pricing per token */
|
||||
prompt: Decimal;
|
||||
/** Output/completion pricing per token */
|
||||
completion: Decimal;
|
||||
}
|
||||
}
|
||||
|
||||
interface ModelFetchResult {
|
||||
@@ -46,13 +56,37 @@ export function useProviderModels(): ModelFetchResult {
|
||||
signal: AbortSignal.timeout(10_000),
|
||||
});
|
||||
|
||||
console.log(response);
|
||||
|
||||
// Transform models to our format
|
||||
const providerModels = response.data.map((model) => ({
|
||||
id: model.id,
|
||||
name: model.id,
|
||||
provider: providerKey,
|
||||
fullId: `${providerKey}/${model.id}`,
|
||||
}));
|
||||
const providerModels = response.data.map((model) => {
|
||||
const providerModel: ProviderModel = {
|
||||
id: model.id,
|
||||
name: model.id,
|
||||
provider: providerKey,
|
||||
fullId: `${providerKey}/${model.id}`,
|
||||
};
|
||||
|
||||
if ('context_length' in model && typeof model.context_length === 'number') {
|
||||
providerModel.context_length = model.context_length;
|
||||
}
|
||||
|
||||
if (
|
||||
"pricing" in model && model.pricing && typeof model.pricing === "object" &&
|
||||
"prompt" in model.pricing && "completion" in model.pricing &&
|
||||
typeof model.pricing.prompt === "string" &&
|
||||
typeof model.pricing.completion === "string" &&
|
||||
!isNaN(Number(model.pricing.prompt)) &&
|
||||
!isNaN(Number(model.pricing.completion))
|
||||
) {
|
||||
providerModel.pricing = {
|
||||
prompt: new Decimal(model.pricing.prompt),
|
||||
completion: new Decimal(model.pricing.completion),
|
||||
};
|
||||
}
|
||||
|
||||
return providerModel;
|
||||
});
|
||||
|
||||
allModels.push(...providerModels);
|
||||
} catch (fetchError) {
|
||||
|
||||
Reference in new issue
Block a user