Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor llm info #961

Merged
merged 23 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6cce2d1
llm as judge support
pelikhan Dec 19, 2024
9dcfc67
Merge remote-tracking branch 'origin/main' into judge
pelikhan Dec 20, 2024
9b572ef
style: πŸ’„ remove redundant blank line in judge.genai.mts
pelikhan Dec 20, 2024
5725842
feat: πŸ§ͺ extend judgeClassify to support WorkspaceFile
pelikhan Dec 20, 2024
e17d55b
feat: πŸ—οΈ add check for undefined text in tracePromptResult
pelikhan Dec 20, 2024
f16d915
add g2thinking
pelikhan Dec 20, 2024
c62171d
feat: ✨ add model alias support and update defaults
pelikhan Dec 20, 2024
0d394b9
feat: ✨ add support for listing model information in CLI
pelikhan Dec 20, 2024
d6da24c
updated list of models
pelikhan Dec 20, 2024
f034b86
feat: ✨ update LLM aliases and models, fix mistral typo
pelikhan Dec 20, 2024
fd17d69
feat: ✨ add logprobs and topLogprobs support
pelikhan Dec 20, 2024
aa7f334
feat: ✨ add aliases and logit_bias support to providers
pelikhan Dec 21, 2024
c7958a1
feat: πŸ”§ add `info models alias` command to CLI
pelikhan Dec 21, 2024
c3a2ca5
test: ♻️ simplify assertion and add new test case
pelikhan Dec 21, 2024
b1c78f0
chore: πŸ”§ update dependencies across multiple packages
pelikhan Dec 21, 2024
500f3fb
feat: ✨ add support for LLM provider aliases and options
pelikhan Dec 21, 2024
c5d16bf
feat: ✨ add embeddings model to llms.json configuration
pelikhan Dec 21, 2024
7c5d691
feat: πŸ“ add filter for empty user text and new aliases
pelikhan Dec 21, 2024
4e890ff
use provider in test scripts
pelikhan Dec 21, 2024
050f7f3
docs: ✏️ update CLI usage and configuration sections
pelikhan Dec 21, 2024
042a338
ci: πŸ”„ rename workflow to huggingface tests
pelikhan Dec 21, 2024
d0a02a9
env typo
pelikhan Dec 21, 2024
2408a79
feat: πŸ”§ update aliases and simplify template tracing
pelikhan Dec 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 additions & 0 deletions docs/src/content/docs/reference/cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,20 @@

Options:
-t, --token show token
-h, --help display help for command
```

## `models`

```
Usage: genaiscript models [options]

List model information

Options:
-h, --help display help for command
```

Check warning on line 264 in docs/src/content/docs/reference/cli/commands.md

View workflow job for this annotation

GitHub Actions / build

The section header for the `models` command is missing a colon at the end. It should be `## models:` instead of `## models`.
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

## `cache`

```
Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from "./parse" // Parsing functions
import { compileScript, createScript, fixScripts, listScripts } from "./scripts" // Script utilities
import { codeQuery } from "./codequery" // Code parsing and query execution
import { envInfo, modelInfo, systemInfo } from "./info" // Information utilities
import { envInfo, modelsInfo, scriptModelInfo, systemInfo } from "./info" // Information utilities
import { scriptTestList, scriptTestsView, scriptsTest } from "./test" // Test functions
import { cacheClear } from "./cache" // Cache management
import "node:console" // Importing console for side effects
Expand Down Expand Up @@ -320,7 +320,11 @@ export async function cli() {
.description("List model connection information for scripts")
.argument("[script]", "Script id or file")
.option("-t, --token", "show token")
.action(modelInfo) // Action to show model information
.action(scriptModelInfo) // Action to show model information

const models = program.command("models")
.description("List model information")
.action(modelsInfo)

// Define 'cache' command for cache management
const cache = program.command("cache").description("Cache management")
Expand Down Expand Up @@ -446,5 +450,6 @@ export async function cli() {
.option("-e, --error", "show errors")
.option("-m, --models", "show models if possible")
.action(envInfo) // Action to show environment information

program.parse() // Parse command-line arguments
}
9 changes: 8 additions & 1 deletion packages/cli/src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ async function resolveScriptsConnectionInfo(
* @param script - The specific script ID or filename to filter by (optional).
* @param options - Configuration options, including whether to show tokens.
*/
export async function modelInfo(script: string, options?: { token?: boolean }) {
export async function scriptModelInfo(
script: string,
options?: { token?: boolean }
) {
const prj = await buildProject()
const templates = prj.scripts.filter(
(t) =>
Expand All @@ -128,3 +131,7 @@ export async function modelInfo(script: string, options?: { token?: boolean }) {
const info = await resolveScriptsConnectionInfo(templates, options)
console.log(YAMLStringify(info))
}

export async function modelsInfo() {
console.log(YAML.stringify(runtimeHost.modelAliases))
}
52 changes: 4 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 { defaultModelConfigurations } from "../../core/src/llms"

class NodeServerManager implements ServerManager {
async start(): Promise<void> {
Expand All @@ -97,41 +87,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: defaultModelConfigurations(),
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
28 changes: 15 additions & 13 deletions packages/core/src/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ async function choicesToLogitBias(
disableFallback: true,
})) || {}
if (!encode) {
logWarn(
logVerbose(
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
pelikhan marked this conversation as resolved.
Show resolved Hide resolved
`unabled to compute logit bias, no token encoder found for ${model}`
)
trace.warn(
Expand Down Expand Up @@ -1052,18 +1052,20 @@ export function tracePromptResult(
const { text } = resp || {}

// try to sniff the output type
const language = JSON5TryParse(text)
? "json"
: XMLTryParse(text)
? "xml"
: /^(-|\*|#+|```)\s/im.test(text)
? "markdown"
: "text"
trace.detailsFenced(`πŸ”  output`, text, language)
if (language === "markdown")
trace.appendContent(
"\n\n" + HTMLEscape(prettifyMarkdown(text)) + "\n\n"
)
if (text !== undefined) {
const language = JSON5TryParse(text)
? "json"
: XMLTryParse(text)
? "xml"
: /^(-|\*|#+|```)\s/im.test(text)
? "markdown"
: "text"
trace.detailsFenced(`πŸ”  output`, text, language)
if (language === "markdown")
trace.appendContent(
"\n\n" + HTMLEscape(prettifyMarkdown(text)) + "\n\n"
)
}
}
pelikhan marked this conversation as resolved.
Show resolved Hide resolved

export function appendUserMessage(
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
Loading