wip: zen lite
This commit is contained in:
@@ -36,7 +36,7 @@ const getModelsInfo = query(async (workspaceID: string) => {
|
|||||||
"use server"
|
"use server"
|
||||||
return withActor(async () => {
|
return withActor(async () => {
|
||||||
return {
|
return {
|
||||||
all: Object.entries(ZenData.list().models)
|
all: Object.entries(ZenData.list("full").models)
|
||||||
.filter(([id, _model]) => !["claude-3-5-haiku"].includes(id))
|
.filter(([id, _model]) => !["claude-3-5-haiku"].includes(id))
|
||||||
.filter(([id, _model]) => !id.startsWith("alpha-"))
|
.filter(([id, _model]) => !id.startsWith("alpha-"))
|
||||||
.sort(([idA, modelA], [idB, modelB]) => {
|
.sort(([idA, modelA], [idB, modelB]) => {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import type { APIEvent } from "@solidjs/start/server"
|
||||||
|
import { handler } from "~/routes/zen/util/handler"
|
||||||
|
|
||||||
|
export function POST(input: APIEvent) {
|
||||||
|
return handler(input, {
|
||||||
|
format: "oa-compat",
|
||||||
|
modelList: "lite",
|
||||||
|
parseApiKey: (headers: Headers) => headers.get("authorization")?.split(" ")[1],
|
||||||
|
parseModel: (url: string, body: any) => body.model,
|
||||||
|
parseIsStream: (url: string, body: any) => !!body.stream,
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -44,6 +44,7 @@ export async function handler(
|
|||||||
input: APIEvent,
|
input: APIEvent,
|
||||||
opts: {
|
opts: {
|
||||||
format: ZenData.Format
|
format: ZenData.Format
|
||||||
|
modelList: "lite" | "full"
|
||||||
parseApiKey: (headers: Headers) => string | undefined
|
parseApiKey: (headers: Headers) => string | undefined
|
||||||
parseModel: (url: string, body: any) => string
|
parseModel: (url: string, body: any) => string
|
||||||
parseIsStream: (url: string, body: any) => boolean
|
parseIsStream: (url: string, body: any) => boolean
|
||||||
@@ -77,7 +78,7 @@ export async function handler(
|
|||||||
request: requestId,
|
request: requestId,
|
||||||
client: ocClient,
|
client: ocClient,
|
||||||
})
|
})
|
||||||
const zenData = ZenData.list()
|
const zenData = ZenData.list(opts.modelList)
|
||||||
const modelInfo = validateModel(zenData, model)
|
const modelInfo = validateModel(zenData, model)
|
||||||
const dataDumper = createDataDumper(sessionId, requestId, projectId)
|
const dataDumper = createDataDumper(sessionId, requestId, projectId)
|
||||||
const trialLimiter = createTrialLimiter(modelInfo.trial, ip, ocClient)
|
const trialLimiter = createTrialLimiter(modelInfo.trial, ip, ocClient)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { handler } from "~/routes/zen/util/handler"
|
|||||||
export function POST(input: APIEvent) {
|
export function POST(input: APIEvent) {
|
||||||
return handler(input, {
|
return handler(input, {
|
||||||
format: "oa-compat",
|
format: "oa-compat",
|
||||||
|
modelList: "full",
|
||||||
parseApiKey: (headers: Headers) => headers.get("authorization")?.split(" ")[1],
|
parseApiKey: (headers: Headers) => headers.get("authorization")?.split(" ")[1],
|
||||||
parseModel: (url: string, body: any) => body.model,
|
parseModel: (url: string, body: any) => body.model,
|
||||||
parseIsStream: (url: string, body: any) => !!body.stream,
|
parseIsStream: (url: string, body: any) => !!body.stream,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { handler } from "~/routes/zen/util/handler"
|
|||||||
export function POST(input: APIEvent) {
|
export function POST(input: APIEvent) {
|
||||||
return handler(input, {
|
return handler(input, {
|
||||||
format: "anthropic",
|
format: "anthropic",
|
||||||
|
modelList: "full",
|
||||||
parseApiKey: (headers: Headers) => headers.get("x-api-key") ?? undefined,
|
parseApiKey: (headers: Headers) => headers.get("x-api-key") ?? undefined,
|
||||||
parseModel: (url: string, body: any) => body.model,
|
parseModel: (url: string, body: any) => body.model,
|
||||||
parseIsStream: (url: string, body: any) => !!body.stream,
|
parseIsStream: (url: string, body: any) => !!body.stream,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export async function OPTIONS(input: APIEvent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(input: APIEvent) {
|
export async function GET(input: APIEvent) {
|
||||||
const zenData = ZenData.list()
|
const zenData = ZenData.list("full")
|
||||||
const disabledModels = await authenticate()
|
const disabledModels = await authenticate()
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { handler } from "~/routes/zen/util/handler"
|
|||||||
export function POST(input: APIEvent) {
|
export function POST(input: APIEvent) {
|
||||||
return handler(input, {
|
return handler(input, {
|
||||||
format: "google",
|
format: "google",
|
||||||
|
modelList: "full",
|
||||||
parseApiKey: (headers: Headers) => headers.get("x-goog-api-key") ?? undefined,
|
parseApiKey: (headers: Headers) => headers.get("x-goog-api-key") ?? undefined,
|
||||||
parseModel: (url: string, body: any) => url.split("/").pop()?.split(":")?.[0] ?? "",
|
parseModel: (url: string, body: any) => url.split("/").pop()?.split(":")?.[0] ?? "",
|
||||||
parseIsStream: (url: string, body: any) =>
|
parseIsStream: (url: string, body: any) =>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { handler } from "~/routes/zen/util/handler"
|
|||||||
export function POST(input: APIEvent) {
|
export function POST(input: APIEvent) {
|
||||||
return handler(input, {
|
return handler(input, {
|
||||||
format: "openai",
|
format: "openai",
|
||||||
|
modelList: "full",
|
||||||
parseApiKey: (headers: Headers) => headers.get("authorization")?.split(" ")[1],
|
parseApiKey: (headers: Headers) => headers.get("authorization")?.split(" ")[1],
|
||||||
parseModel: (url: string, body: any) => body.model,
|
parseModel: (url: string, body: any) => body.model,
|
||||||
parseIsStream: (url: string, body: any) => !!body.stream,
|
parseIsStream: (url: string, body: any) => !!body.stream,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ export namespace ZenData {
|
|||||||
|
|
||||||
const ModelsSchema = z.object({
|
const ModelsSchema = z.object({
|
||||||
models: z.record(z.string(), z.union([ModelSchema, z.array(ModelSchema.extend({ formatFilter: FormatSchema }))])),
|
models: z.record(z.string(), z.union([ModelSchema, z.array(ModelSchema.extend({ formatFilter: FormatSchema }))])),
|
||||||
|
liteModels: z.record(z.string(), ModelSchema),
|
||||||
providers: z.record(z.string(), ProviderSchema),
|
providers: z.record(z.string(), ProviderSchema),
|
||||||
providerFamilies: z.record(z.string(), ProviderFamilySchema),
|
providerFamilies: z.record(z.string(), ProviderFamilySchema),
|
||||||
})
|
})
|
||||||
@@ -81,7 +82,7 @@ export namespace ZenData {
|
|||||||
return input
|
return input
|
||||||
})
|
})
|
||||||
|
|
||||||
export const list = fn(z.void(), () => {
|
export const list = fn(z.enum(["lite", "full"]), (modelList) => {
|
||||||
const json = JSON.parse(
|
const json = JSON.parse(
|
||||||
Resource.ZEN_MODELS1.value +
|
Resource.ZEN_MODELS1.value +
|
||||||
Resource.ZEN_MODELS2.value +
|
Resource.ZEN_MODELS2.value +
|
||||||
@@ -114,9 +115,9 @@ export namespace ZenData {
|
|||||||
Resource.ZEN_MODELS29.value +
|
Resource.ZEN_MODELS29.value +
|
||||||
Resource.ZEN_MODELS30.value,
|
Resource.ZEN_MODELS30.value,
|
||||||
)
|
)
|
||||||
const { models, providers, providerFamilies } = ModelsSchema.parse(json)
|
const { models, liteModels, providers, providerFamilies } = ModelsSchema.parse(json)
|
||||||
return {
|
return {
|
||||||
models,
|
models: modelList === "lite" ? liteModels : models,
|
||||||
providers: Object.fromEntries(
|
providers: Object.fromEntries(
|
||||||
Object.entries(providers).map(([id, provider]) => [
|
Object.entries(providers).map(([id, provider]) => [
|
||||||
id,
|
id,
|
||||||
|
|||||||
Reference in New Issue
Block a user