264 lines
7.5 KiB
TypeScript
264 lines
7.5 KiB
TypeScript
import type { LanguageModel } from "ai";
|
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
import { createOpenAI } from "@ai-sdk/openai";
|
|
import { AVAILABLE_CLIENT_MODELS } from "./models-client.ts";
|
|
|
|
const traceFetch = async (
|
|
input: RequestInfo | URL,
|
|
init?: RequestInit,
|
|
): Promise<Response> => {
|
|
await Promise.try(() =>
|
|
console.log(JSON.parse(init?.body?.toString() ?? ""))
|
|
);
|
|
const response = fetch(input, init);
|
|
await response.then((v) => console.log(v.status)).catch(console.error);
|
|
return response;
|
|
};
|
|
|
|
const google = createGoogleGenerativeAI({
|
|
apiKey: Deno.env.get("GEMINI_API_KEY"),
|
|
fetch: traceFetch,
|
|
});
|
|
|
|
const openrouter = createOpenAICompatible({
|
|
name: "openrouter",
|
|
baseURL: "https://openrouter.ai/api/v1",
|
|
headers: {
|
|
"Authorization": `Bearer ${Deno.env.get("OPENROUTER_API_KEY")}`,
|
|
},
|
|
fetch: traceFetch,
|
|
});
|
|
|
|
const nousresearch = createOpenAI({
|
|
name: "nousresearch",
|
|
baseURL: "https://inference-api.nousresearch.com/v1",
|
|
apiKey: Deno.env.get("NOUSRESEARCH_API_KEY"),
|
|
headers: {
|
|
"Authorization": `Bearer ${Deno.env.get("NOUSRESEARCH_API_KEY")}`,
|
|
},
|
|
fetch: traceFetch,
|
|
});
|
|
|
|
const createHf = (baseURL: string) =>
|
|
createOpenAI({
|
|
name: "hf",
|
|
baseURL,
|
|
apiKey: Deno.env.get("HF_API_KEY"),
|
|
headers: {
|
|
"Authorization": `Bearer ${Deno.env.get("HF_API_KEY")}`,
|
|
},
|
|
fetch: traceFetch,
|
|
});
|
|
|
|
const models = [
|
|
{
|
|
id: "gemini-3-flash-preview",
|
|
name: "Gemini 3 Flash (Google; Private)",
|
|
getModel: () => google("models/gemini-3-flash-preview"),
|
|
parameters: {
|
|
temperature: 1.5,
|
|
stopSequences: [
|
|
...Array(5).keys().map((v) => v.toString().repeat(6)),
|
|
] as string[],
|
|
maxOutputTokens: 8024,
|
|
},
|
|
startPage: {
|
|
label: "googleModelChoice",
|
|
},
|
|
},
|
|
// {
|
|
// id: "gemini-2.5-flash",
|
|
// name: "Gemini 2.5 Flash (Google; Private)",
|
|
// getModel: () => google("models/gemini-2.5-flash"),
|
|
// parameters: {
|
|
// temperature: 1.5,
|
|
// stopSequences: [
|
|
// ...Array(5).keys().map((v) => v.toString().repeat(6)),
|
|
// ] as string[],
|
|
// maxOutputTokens: 8024,
|
|
// // frequencyPenalty: 1.5,
|
|
// // presencePenalty: 1.5,
|
|
// },
|
|
// startPage: {
|
|
// label: "googleModelChoice",
|
|
// },
|
|
// },
|
|
{
|
|
id: "gemini-2.5-flash-lite-preview-06-17",
|
|
name: "Gemini 2.5 Flash-Lite Preview 06-17",
|
|
getModel: () => google("models/gemini-2.5-flash-lite-preview-06-17"),
|
|
parameters: {
|
|
temperature: 1.5,
|
|
stopSequences: [
|
|
...Array(5).keys().map((v) => v.toString().repeat(6)),
|
|
] as string[],
|
|
maxOutputTokens: 8024,
|
|
// frequencyPenalty: 1.5,
|
|
// presencePenalty: 1.5,
|
|
},
|
|
},
|
|
{
|
|
id: "Hermes-3-Llama-3.1-70B-HF",
|
|
name: "Hermes-3-Llama-3.1-70B (Hugging Face; OS)",
|
|
getModel: ((hf) => () => hf("NousResearch/Hermes-3-Llama-3.1-70B"))(
|
|
createHf(
|
|
"https://router.huggingface.co/featherless-ai/v1",
|
|
),
|
|
),
|
|
startPage: {
|
|
label: "openSourceModelChoice",
|
|
},
|
|
parameters: {
|
|
maxOutputTokens: 8024,
|
|
},
|
|
},
|
|
{
|
|
id: "Hermes-3-Llama-3.1-405B-Nous",
|
|
name: "Hermes-3-Llama-3.1-405B (NousResearch; OS)",
|
|
getModel: () => nousresearch("Hermes-3-Llama-3.1-405B"),
|
|
parameters: {
|
|
maxOutputTokens: 8024,
|
|
},
|
|
disabled: true,
|
|
},
|
|
{
|
|
id: "gemini-2.5-flash-preview-04-17",
|
|
name: "Gemini 2.5 Flash 04-17 (Google; Private)",
|
|
getModel: () => google("models/gemini-2.5-flash-preview-04-17"),
|
|
parameters: { maxOutputTokens: 8024 },
|
|
disabled: true,
|
|
},
|
|
{
|
|
id: "gemma-3n-e4b-it",
|
|
name: "Gemma 3n E4B (Google; OS)",
|
|
getModel: () => google("models/gemma-3n-e4b-it"),
|
|
features: {
|
|
structuredOutputDisabled: true,
|
|
developerInstructionDisabled: true,
|
|
maxPersonaHistoryLength: 700,
|
|
maxPersonas: 2,
|
|
guideStepAdditionalUserText:
|
|
"Oh *Guide*, dirige moi vers un des personas qui satisfait mes désirs. Et propose-moi texte ou text-image.",
|
|
guideStepAdditionalAssistantText:
|
|
"CRITICAL: YOU MUST FILL `personaId` NOW !!!!! NOW !!!",
|
|
},
|
|
parameters: { maxOutputTokens: 8024 },
|
|
},
|
|
{
|
|
id: "gemma-3-12b-it",
|
|
name: "Gemma-3 12B (OpenRouter)",
|
|
getModel: () => openrouter("google/gemma-3-12b-it"),
|
|
features: {
|
|
structuredOutputDisabled: true,
|
|
developerInstructionDisabled: true,
|
|
},
|
|
parameters: { maxOutputTokens: 8024 },
|
|
disabled: true,
|
|
},
|
|
{
|
|
id: "valkyrie-49b-v1",
|
|
name: "Valkyrie 49B (OpenRouter)",
|
|
getModel: () => openrouter("thedrummer/valkyrie-49b-v1"),
|
|
features: {
|
|
structuredOutputDisabled: true,
|
|
developerInstructionDisabled: true,
|
|
},
|
|
parameters: { maxOutputTokens: 8024 },
|
|
disabled: true,
|
|
},
|
|
{
|
|
id: "mlabonne/gemma-3-12b-it-abliterated-v2-GGUF",
|
|
name: "mlabonne/gemma-3-12b-it-abliterated-v2-GGUF",
|
|
getModel: ((hf) => () => hf("mlabonne/gemma-3-12b-it-abliterated-v2-GGUF"))(
|
|
createHf(
|
|
"https://v1h2xjxd4ej911mo.us-east4.gcp.endpoints.huggingface.cloud",
|
|
),
|
|
),
|
|
features: {
|
|
structuredOutputDisabled: true,
|
|
developerInstructionDisabled: true,
|
|
},
|
|
parameters: { maxOutputTokens: 8024 },
|
|
disabled: true,
|
|
},
|
|
{
|
|
id: "bartowski/TheDrummer_Fallen-Gemma3-12B-v1-Q6_K.gguf",
|
|
name: "bartowski/TheDrummer_Fallen-Gemma3-12B-v1-GGUF",
|
|
getModel:
|
|
((hf) => () => hf("bartowski/TheDrummer_Fallen-Gemma3-12B-v1-GGUF"))(
|
|
createHf(
|
|
"https://mt8rdzh29h3vnpap.us-east4.gcp.endpoints.huggingface.cloud",
|
|
),
|
|
),
|
|
features: {
|
|
structuredOutputDisabled: true,
|
|
developerInstructionDisabled: true,
|
|
},
|
|
parameters: { maxOutputTokens: 8024 },
|
|
disabled: true,
|
|
},
|
|
{
|
|
id: "mradermacher/The-Omega-Directive-G-12B-v1.0.Q6_K.gguf",
|
|
name: "mradermacher/The-Omega-Directive-G-12B-v1.0-GGUF",
|
|
getModel:
|
|
((hf) => () => hf("mradermacher/The-Omega-Directive-G-12B-v1.0-GGUF"))(
|
|
createHf(
|
|
"https://l5u01e71s8ovsa6e.us-east4.gcp.endpoints.huggingface.cloud",
|
|
),
|
|
),
|
|
features: {
|
|
structuredOutputDisabled: true,
|
|
developerInstructionDisabled: true,
|
|
},
|
|
parameters: {
|
|
temperature: 1.1,
|
|
presencePenalty: 1.3,
|
|
maxOutputTokens: 8024,
|
|
},
|
|
disabled: true,
|
|
},
|
|
];
|
|
|
|
export type ModelId = typeof models[number]["id"];
|
|
|
|
export interface ModelParameters {
|
|
temperature?: number;
|
|
presencePenalty?: number;
|
|
frequencyPenalty?: number;
|
|
stopSequences?: string[];
|
|
maxOutputTokens?: number;
|
|
}
|
|
|
|
export interface ModelFeatures {
|
|
structuredOutputDisabled?: boolean;
|
|
developerInstructionDisabled?: boolean;
|
|
maxPersonaHistoryLength?: number;
|
|
maxPersonas?: number;
|
|
guideStepAdditionalAssistantText?: string;
|
|
guideStepAdditionalUserText?: string;
|
|
}
|
|
|
|
export interface ModelDefinition {
|
|
id: ModelId;
|
|
name: string;
|
|
getModel: () => Exclude<LanguageModel, "string">;
|
|
parameters?: ModelParameters;
|
|
features?: ModelFeatures;
|
|
disabled?: boolean;
|
|
type: "client" | "server";
|
|
startPage?: { label: string };
|
|
}
|
|
|
|
export const AVAILABLE_MODELS: readonly ModelDefinition[] = [
|
|
...models.map((v) => ({ ...v, type: "server" as const })),
|
|
...AVAILABLE_CLIENT_MODELS.map((v) => ({ ...v, type: "client" as const })),
|
|
].filter((v) => !(v as ModelDefinition).disabled);
|
|
|
|
export function getModelDefinition(modelId?: ModelId | null): ModelDefinition {
|
|
if (!modelId) {
|
|
return AVAILABLE_MODELS[0];
|
|
}
|
|
const model = AVAILABLE_MODELS.find((m) => m.id === modelId);
|
|
return model || AVAILABLE_MODELS[0];
|
|
}
|