diff --git a/docs/src/content/docs/reference/cli/commands.md b/docs/src/content/docs/reference/cli/commands.md index fd49caa9c..3460c5abe 100644 --- a/docs/src/content/docs/reference/cli/commands.md +++ b/docs/src/content/docs/reference/cli/commands.md @@ -497,7 +497,8 @@ Usage: genaiscript info env [options] [provider] Show .env information Options: - -t, --token show token - -e, --error show errors - -h, --help display help for command + -t, --token show token + -e, --error show errors + -m, --models show models if possible + -h, --help display help for command ``` diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index b50334176..f4c0fee85 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -393,6 +393,7 @@ export async function cli() { .arguments("[provider]") .option("-t, --token", "show token") .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 } diff --git a/packages/cli/src/info.ts b/packages/cli/src/info.ts index 66fb9677c..78009a990 100644 --- a/packages/cli/src/info.ts +++ b/packages/cli/src/info.ts @@ -4,10 +4,16 @@ * and resolving model connection info for specific scripts. */ +import { LanguageModelInfo } from "../../core/src/chat" import { parseTokenFromEnv } from "../../core/src/connection" import { MODEL_PROVIDERS } from "../../core/src/constants" import { errorMessage } from "../../core/src/error" -import { host, runtimeHost } from "../../core/src/host" +import { + host, + LanguageModelConfiguration, + runtimeHost, +} from "../../core/src/host" +import { resolveLanguageModel } from "../../core/src/lm" import { ModelConnectionInfo, resolveModelConnectionInfo, @@ -34,11 +40,11 @@ export async function systemInfo() { */ export async function envInfo( provider: string, - options?: { token?: boolean; error?: boolean } + options?: { token?: boolean; error?: boolean; models?: boolean } ) { - const { token, error } = options || {} + const { token, error, models } = options || {} const config = await runtimeHost.readConfig() - const res: any = {} + const res: any = {} res[".env"] = config.envFile ?? "" res.providers = [] const env = process.env @@ -49,10 +55,19 @@ export async function envInfo( )) { try { // Attempt to parse connection token from environment variables - const conn = await parseTokenFromEnv(env, `${modelProvider.id}:*`) + const conn: LanguageModelConfiguration & { + models?: LanguageModelInfo[] + } = await parseTokenFromEnv(env, `${modelProvider.id}:*`) if (conn) { // Mask the token if the option is set if (!token && conn.token) conn.token = "***" + if (models) { + const lm = await resolveLanguageModel(modelProvider.id) + if (lm.listModels) { + const ms = await lm.listModels(conn) + if (ms?.length) conn.models = ms + } + } res.providers.push(conn) } } catch (e) {