Skip to content

Commit

Permalink
feat: add --models option to show model details 🆕
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Nov 27, 2024
1 parent ffb7bdb commit f2d3eaf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 4 additions & 3 deletions docs/src/content/docs/reference/cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
1 change: 1 addition & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
25 changes: 20 additions & 5 deletions packages/cli/src/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit f2d3eaf

Please sign in to comment.