Skip to content

Commit

Permalink
generate curl friendly headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed May 17, 2024
1 parent a93c21a commit d543fdc
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/core/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ export async function parseTokenFromEnv(
token,
source: "env: OPENAI_API_...",
version,
curlHeaders: {
Authorization: `Bearer $OPENAI_API_KEY`,
},
}
}
}
Expand All @@ -83,6 +86,11 @@ export async function parseTokenFromEnv(
env.AZURE_OPENAI_API_KEY ||
env.AZURE_API_KEY ||
env.OPENAI_API_KEY
const tokenVar = env.AZURE_OPENAI_API_KEY
? "AZURE_OPENAI_API_KEY"
: env.AZURE_API_KEY
? "AZURE_API_KEY"
: "OPENAI_API_KEY"
let base = trimTrailingSlash(
env.AZURE_OPENAI_ENDPOINT ||
env.AZURE_OPENAI_API_BASE ||
Expand Down Expand Up @@ -113,6 +121,9 @@ export async function parseTokenFromEnv(
type: "azure",
source: "env: AZURE_...",
version,
curlHeaders: {
"api-key": `$${tokenVar}`,
},
}
}
}
Expand All @@ -136,7 +147,18 @@ export async function parseTokenFromEnv(
const type: APIType = "openai"
if (base && !URL.canParse(base))
throw new Error(`${modelBase} must be a valid URL`)
return { token, base, type, version, source }
return {
token,
base,
type,
version,
source,
curlHeaders: token
? {
Authorization: `Bearer $${modelKey}`,
}
: undefined,
}
}
}

Expand Down

0 comments on commit d543fdc

Please sign in to comment.