Skip to content

Commit

Permalink
feat: ✨ add model alias support and update defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 20, 2024
1 parent f16d915 commit c62171d
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 113 deletions.
51 changes: 51 additions & 0 deletions docs/public/schemas/llms.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,64 @@
"bearerToken": {
"type": "boolean",
"description": "Indicates if bearer token is supported"
},
"aliases": {
"type": "object",
"description": "List of model aliases for the provider",
"properties": {
"large": {
"type": "string",
"description": "Alias for large model"
},
"small": {
"type": "string",
"description": "Alias for small model"
},
"vision": {
"type": "string",
"description": "Alias for vision model"
},
"reasoning": {
"type": "string",
"description": "Alias for reasoning model"
},
"reasoning_small": {
"type": "string",
"description": "Alias for reasoning small model"
},
"long": {
"type": "string",
"description": "Alias for long model"
},
"agent": {
"type": "string",
"description": "Alias for agent model"
},
"memory": {
"type": "string",
"description": "Alias for memory model"
},
"embeddings": {
"type": "string",
"description": "Alias for embeddings model"
}
}
}
},
"additionalProperties": false,
"required": ["id", "detail"]
}
}
},
"aliases": {
"type": "object",
"additionalProperties": true,
"patternProperties": {
"^[a-zA-Z0-9:_-]+$": {
"type": "string"
}
}
},
"pricings": {
"type": "object",
"additionalProperties": false,
Expand Down
75 changes: 75 additions & 0 deletions docs/src/content/docs/reference/cli/commands.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
{
"large": {
"model": "openai:gpt-4o",
"source": "default",
"candidates": [
"openai:gpt-4o",
"azure_serverless:gpt-4o",
"anthropic:claude-2.1",
"google:gemini-1.5-pro-latest",
"github:gpt-4o",
"client:gpt-4o"
]
},
"small": {
"model": "openai:gpt-4o-mini",
"source": "default",
"candidates": [
"openai:gpt-4o-mini",
"azure_serverless:gpt-4o-mini",
"anthropic:claude-instant-1.2",
"google:gemini-1.5-flash-latest",
"github:gpt-4o-mini",
"client:gpt-4o-mini"
]
},
"vision": {
"model": "openai:gpt-4o",
"source": "default",
"candidates": [
"openai:gpt-4o",
"azure_serverless:gpt-4o",
"anthropic:claude-2.1",
"google:gemini-1.5-flash-latest",
"github:gpt-4o"
]
},
"embeddings": {
"model": "openai:text-embedding-3-small",
"source": "default",
"candidates": [
"openai:text-embedding-3-small",
"github:text-embedding-3-small"
]
},
"reasoning": {
"model": "openai:o1",
"source": "default",
"candidates": [
"openai:o1",
"azure_serverless:o1-preview",
"github:o1-preview"
]
},
"reasoning_small": {
"model": "openai:o1-mini",
"source": "default",
"candidates": [
"openai:o1-mini",
"azure_serverless:o1-mini",
"github:o1-mini"
]
},
"agent": {
"model": "large",
"source": "default"
},
"long": {
"model": "large",
"source": "default"
},
"memory": {
"model": "large",
"source": "default"
}
}
---
title: Commands
description: List of all CLI commands
Expand Down
89 changes: 41 additions & 48 deletions packages/cli/src/nodehost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,16 @@ import {
parseTokenFromEnv,
} from "../../core/src/connection"
import {
DEFAULT_LARGE_MODEL,
MODEL_PROVIDER_AZURE_OPENAI,
SHELL_EXEC_TIMEOUT,
DEFAULT_EMBEDDINGS_MODEL,
DEFAULT_SMALL_MODEL,
AZURE_COGNITIVE_SERVICES_TOKEN_SCOPES,
MODEL_PROVIDER_AZURE_SERVERLESS_MODELS,
AZURE_AI_INFERENCE_TOKEN_SCOPES,
MODEL_PROVIDER_AZURE_SERVERLESS_OPENAI,
DOT_ENV_FILENAME,
DEFAULT_VISION_MODEL,
LARGE_MODEL_ID,
SMALL_MODEL_ID,
DEFAULT_SMALL_MODEL_CANDIDATES,
DEFAULT_LARGE_MODEL_CANDIDATES,
DEFAULT_EMBEDDINGS_MODEL_CANDIDATES,
DEFAULT_VISION_MODEL_CANDIDATES,
DEFAULT_REASONING_MODEL,
DEFAULT_REASONING_SMALL_MODEL,
DEFAULT_REASONING_SMALL_MODEL_CANDIDATES,
DEFAULT_REASONING_MODEL_CANDIDATES,
VISION_MODEL_ID,
} from "../../core/src/constants"
import { tryReadText } from "../../core/src/fs"
import {
Expand All @@ -54,7 +43,7 @@ import {
ModelConfiguration,
} from "../../core/src/host"
import { TraceOptions } from "../../core/src/trace"
import { logError, logVerbose } from "../../core/src/util"
import { deleteEmptyValues, logError, logVerbose } from "../../core/src/util"
import { parseModelIdentifier } from "../../core/src/models"
import { LanguageModel } from "../../core/src/chat"
import { errorMessage, NotSupportedError } from "../../core/src/error"
Expand All @@ -73,6 +62,7 @@ import { resolveGlobalConfiguration } from "../../core/src/config"
import { HostConfiguration } from "../../core/src/hostconfiguration"
import { resolveLanguageModel } from "../../core/src/lm"
import { CancellationOptions } from "../../core/src/cancellation"
import LLMS from "../../../packages/core/src/llms.json"

class NodeServerManager implements ServerManager {
async start(): Promise<void> {
Expand All @@ -83,6 +73,43 @@ class NodeServerManager implements ServerManager {
}
}

function readModelAliases(): ModelConfigurations {
const aliases = [
LARGE_MODEL_ID,
SMALL_MODEL_ID,
VISION_MODEL_ID,
"embeddings",
"reasoning",
"reasoning_small",
]
const res = {
...(Object.fromEntries(
aliases.map((alias) => [alias, readModelAlias(alias)])
) as ModelConfigurations),
...Object.fromEntries(
Object.entries(LLMS.aliases).map((kv) => [
kv[0],
{
model: kv[1],
source: "default",
} satisfies ModelConfiguration,
])
),
}
return res

function readModelAlias(alias: string) {
const candidates = Object.values(LLMS.providers)
.map(({ aliases }) => (aliases as Record<string, string>)?.[alias])
.filter((c) => !!c)
return deleteEmptyValues({
model: candidates[0],
source: "default",
candidates,
})
}
}

export class NodeHost implements RuntimeHost {
private pulledModels: string[] = []
readonly dotEnvPath: string
Expand All @@ -97,41 +124,7 @@ export class NodeHost implements RuntimeHost {
"default" | "cli" | "env" | "config",
Omit<ModelConfigurations, "large" | "small" | "vision" | "embeddings">
> = {
default: {
large: {
model: DEFAULT_LARGE_MODEL,
source: "default",
candidates: DEFAULT_LARGE_MODEL_CANDIDATES,
},
small: {
model: DEFAULT_SMALL_MODEL,
source: "default",
candidates: DEFAULT_SMALL_MODEL_CANDIDATES,
},
vision: {
model: DEFAULT_VISION_MODEL,
source: "default",
candidates: DEFAULT_VISION_MODEL_CANDIDATES,
},
embeddings: {
model: DEFAULT_EMBEDDINGS_MODEL,
source: "default",
candidates: DEFAULT_EMBEDDINGS_MODEL_CANDIDATES,
},
reasoning: {
model: DEFAULT_REASONING_MODEL,
source: "default",
candidates: DEFAULT_REASONING_MODEL_CANDIDATES,
},
["reasoning_small"]: {
model: DEFAULT_REASONING_SMALL_MODEL,
source: "default",
candidates: DEFAULT_REASONING_SMALL_MODEL_CANDIDATES,
},
long: { model: LARGE_MODEL_ID, source: "default" },
agent: { model: LARGE_MODEL_ID, source: "default" },
memory: { model: SMALL_MODEL_ID, source: "default" },
},
default: readModelAliases(),
cli: {},
env: {},
config: {},
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { YAMLParse, YAMLStringify } from "../../core/src/yaml"
import { resolveTokenEncoder } from "../../core/src/encoders"
import {
CSV_REGEX,
DEFAULT_LARGE_MODEL,
INI_REGEX,
JSON5_REGEX,
MD_REGEX,
Expand Down Expand Up @@ -203,7 +202,7 @@ export async function parseTokens(
filesGlobs: string[],
options: { excludedFiles: string[]; model: string }
) {
const { model = DEFAULT_LARGE_MODEL } = options || {}
const { model } = options || {}
const { encode: encoder } = await resolveTokenEncoder(model)

const files = await expandFiles(filesGlobs, options?.excludedFiles)
Expand Down
50 changes: 0 additions & 50 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,56 +57,6 @@ export const SMALL_MODEL_ID = "small"
export const LARGE_MODEL_ID = "large"
export const VISION_MODEL_ID = "vision"
export const DEFAULT_FENCE_FORMAT: FenceFormat = "xml"
export const DEFAULT_LARGE_MODEL = "openai:gpt-4o"
export const DEFAULT_LARGE_MODEL_CANDIDATES = [
"azure_serverless:gpt-4o",
DEFAULT_LARGE_MODEL,
"google:gemini-1.5-pro-latest",
"anthropic:claude-2.1",
"mistral:mistral-large-latest",
"github:gpt-4o",
"client:gpt-4",
]
export const DEFAULT_VISION_MODEL = "openai:gpt-4o"
export const DEFAULT_VISION_MODEL_CANDIDATES = [
"azure_serverless:gpt-4o",
DEFAULT_VISION_MODEL,
"google:gemini-1.5-flash-latest",
"anthropic:claude-2.1",
"github:gpt-4o",
]
export const DEFAULT_SMALL_MODEL = "openai:gpt-4o-mini"
export const DEFAULT_SMALL_MODEL_CANDIDATES = [
"azure_serverless:gpt-4o-mini",
DEFAULT_SMALL_MODEL,
"google:gemini-1.5-flash-latest",
"anthropic:claude-instant-1.2",
"mistral:mistral-small-latest",
"github:gpt-4o-mini",
"client:gpt-4-mini",
]
export const DEFAULT_EMBEDDINGS_MODEL_CANDIDATES = [
"azure:text-embedding-3-small",
"azure:text-embedding-2-small",
"openai:text-embedding-3-small",
"github:text-embedding-3-small",
"client:text-embedding-3-small",
]
export const DEFAULT_REASONING_SMALL_MODEL = "openai:o1-mini"
export const DEFAULT_REASONING_SMALL_MODEL_CANDIDATES = [
"azure_serverless:o1-mini",
DEFAULT_REASONING_SMALL_MODEL,
"github:o1-mini",
"client:o1-mini",
]
export const DEFAULT_REASONING_MODEL = "openai:o1"
export const DEFAULT_REASONING_MODEL_CANDIDATES = [
"azure_serverless:o1-preview",
DEFAULT_REASONING_MODEL,
"github:o1-preview",
"client:o1-preview",
]
export const DEFAULT_EMBEDDINGS_MODEL = "openai:text-embedding-ada-002"
export const DEFAULT_TEMPERATURE = 0.8
export const BUILTIN_PREFIX = "_builtin/"
export const CACHE_LLMREQUEST_PREFIX = "genaiscript/cache/llm/"
Expand Down
Loading

0 comments on commit c62171d

Please sign in to comment.