-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FireworksAI: support via custom OpenAI on https://api.fireworks.ai/in…
- Loading branch information
Showing
4 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { z } from 'zod'; | ||
|
||
|
||
// [Fireworks AI] Models List API - Response | ||
|
||
export const wireFireworksAIListOutputSchema = z.array(z.object({ | ||
|
||
id: z.string(), | ||
object: z.literal('model'), | ||
owned_by: z.union([ | ||
z.literal('fireworks'), | ||
z.literal('yi-01-ai'), | ||
z.string(), | ||
]), | ||
created: z.number(), | ||
kind: z.union([ | ||
z.literal('HF_BASE_MODEL'), | ||
z.literal('HF_PEFT_ADDON'), | ||
z.literal('FLUMINA_BASE_MODEL'), | ||
z.string(), | ||
]).optional(), | ||
// these seem to be there all the time, but just in case make them optional | ||
supports_chat: z.boolean().optional(), | ||
supports_image_input: z.boolean().optional(), | ||
supports_tools: z.boolean().optional(), | ||
// Not all models have this, so make it optional | ||
context_length: z.number().optional(), | ||
})); |
89 changes: 89 additions & 0 deletions
89
src/modules/llms/server/openai/models/fireworksai.models.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { DModelInterfaceV1, LLM_IF_OAI_Chat, LLM_IF_OAI_Fn, LLM_IF_OAI_Vision } from '~/common/stores/llms/llms.types'; | ||
|
||
import { serverCapitalizeFirstLetter } from '~/server/wire'; | ||
|
||
import type { ModelDescriptionSchema } from '../../llm.server.types'; | ||
|
||
import { fromManualMapping, ManualMappings } from './models.data'; | ||
import { wireFireworksAIListOutputSchema } from '../fireworksai.wiretypes'; | ||
|
||
|
||
export function fireworksAIHeuristic(hostname: string) { | ||
return hostname.includes('fireworks.ai/'); | ||
} | ||
|
||
|
||
const _fireworksKnownModels: ManualMappings = [ | ||
// NOTE: we don't need manual patching as we have enough info for now | ||
] as const; | ||
|
||
const _fireworksDenyListContains: string[] = [ | ||
// nothing to deny for now | ||
] as const; | ||
|
||
|
||
function _prettyModelId(id: string, isVision: boolean): string { | ||
// example: "accounts/fireworks/models/llama-v3p1-405b-instruct" => "Fireworks · Llama V3p1 405b Instruct" | ||
let prettyName = id | ||
.replace(/^accounts\//, '') // remove the leading "accounts/" if present | ||
.replace(/\/models\//, ' · ') // turn the next "/models/" into " · " | ||
.replaceAll(/[_-]/g, ' ') // replace underscores or dashes with spaces | ||
.split(' ') | ||
.filter(piece => piece !== 'instruct') | ||
.map(serverCapitalizeFirstLetter) | ||
.join(' ') | ||
.replaceAll('/', ' · ') // replace any additional slash with " · " | ||
.trim(); | ||
// add "Vision" to the name if it's a vision model | ||
if (isVision && !id.includes('-vision')) | ||
prettyName += ' Vision'; | ||
prettyName = prettyName.replace(' Vision', ' (Vision)'); | ||
return prettyName; | ||
} | ||
|
||
|
||
export function fireworksAIModelsToModelDescriptions(wireModels: unknown): ModelDescriptionSchema[] { | ||
return wireFireworksAIListOutputSchema | ||
.parse(wireModels) | ||
|
||
.filter((model) => { | ||
// filter-out non-llms | ||
if (model.supports_chat === false) | ||
return false; | ||
|
||
return !_fireworksDenyListContains.some(contains => model.id.includes(contains)); | ||
}) | ||
|
||
.map((model): ModelDescriptionSchema => { | ||
|
||
// heuristics | ||
const label = _prettyModelId(model.id, !!model.supports_image_input); | ||
const description = `${model.owned_by} \`${model.kind || 'unknown'}\` type.`; | ||
const contextWindow = model.context_length || null; | ||
const interfaces: DModelInterfaceV1[] = [LLM_IF_OAI_Chat]; | ||
if (model.supports_image_input) | ||
interfaces.push(LLM_IF_OAI_Vision); | ||
if (model.supports_tools) | ||
interfaces.push(LLM_IF_OAI_Fn); | ||
|
||
return fromManualMapping(_fireworksKnownModels, model.id, model.created, undefined, { | ||
idPrefix: model.id, | ||
label, | ||
description, | ||
contextWindow, | ||
interfaces, | ||
// parameterSpecs: ... | ||
// maxCompletionTokens: ... | ||
// trainingDataCutoff: ... | ||
// benchmark: ... | ||
// chatPrice, | ||
hidden: false, | ||
}); | ||
}) | ||
|
||
.sort((a: ModelDescriptionSchema, b: ModelDescriptionSchema): number => { | ||
if (a.created !== b.created) | ||
return (b.created || 0) - (a.created || 0); | ||
return a.id.localeCompare(b.id); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters