Skip to content

Commit

Permalink
fix info env when partial info
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Jul 16, 2024
1 parent 8c34c55 commit f05875e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 13 additions & 5 deletions packages/cli/src/info.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parseTokenFromEnv } from "../../core/src/connection"
import { MODEL_PROVIDERS } from "../../core/src/constants"
import { errorMessage } from "../../core/src/error"
import { host } from "../../core/src/host"
import {
ModelConnectionInfo,
Expand All @@ -26,11 +27,18 @@ export async function envInfo(provider: string, options?: { token?: boolean }) {
for (const modelProvider of MODEL_PROVIDERS.filter(
(mp) => !provider || mp.id === provider
)) {
const conn = await parseTokenFromEnv(env, `${modelProvider.id}:*`)
if (conn) {
if (!token && conn.token)
conn.token = conn.token.slice(0, 5) + "***"
res.providers.push(conn)
try {
const conn = await parseTokenFromEnv(env, `${modelProvider.id}:*`)
if (conn) {
if (!token && conn.token)
conn.token = "***"
res.providers.push(conn)
}
} catch (e) {
res.providers.push({
provider: modelProvider.id,
error: errorMessage(e),
})
}
}
console.log(YAMLStringify(res))
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export async function parseTokenFromEnv(
env.AZURE_API_BASE ||
env.AZURE_OPENAI_API_ENDPOINT
)
if (!token && !base) return undefined
if (!token)
throw new Error("AZURE_OPENAI_API_KEY or AZURE_API_KEY missing")
if (token === PLACEHOLDER_API_KEY)
Expand All @@ -135,7 +136,9 @@ export async function parseTokenFromEnv(
base,
token,
type: "azure",
source: token ? "env: AZURE_..." : "env: AZURE_... + Entra ID",
source: token
? "env: AZURE_OPENAI_API_..."
: "env: AZURE_OPENAI_API_... + Entra ID",
version,
curlHeaders: tokenVar
? {
Expand Down

0 comments on commit f05875e

Please sign in to comment.