-
Notifications
You must be signed in to change notification settings - Fork 126
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
Filter errors from environment information output #857
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,54 +87,46 @@ | |
const BASE_SUFFIX = ["_API_BASE", "_API_ENDPOINT", "_BASE", "_ENDPOINT"] | ||
|
||
if (provider === MODEL_PROVIDER_OPENAI) { | ||
if (env.OPENAI_API_KEY || env.OPENAI_API_BASE || env.OPENAI_API_TYPE) { | ||
const token = env.OPENAI_API_KEY ?? "" | ||
let base = env.OPENAI_API_BASE | ||
let type = (env.OPENAI_API_TYPE as OpenAIAPIType) || "openai" | ||
const version = env.OPENAI_API_VERSION | ||
if ( | ||
type !== "azure" && | ||
type !== "openai" && | ||
type !== "localai" && | ||
type !== "azure_serverless" && | ||
type !== "azure_serverless_models" | ||
const token = env.OPENAI_API_KEY ?? "" | ||
let base = env.OPENAI_API_BASE | ||
let type = (env.OPENAI_API_TYPE as OpenAIAPIType) || "openai" | ||
const version = env.OPENAI_API_VERSION | ||
if ( | ||
type !== "azure" && | ||
type !== "openai" && | ||
type !== "localai" && | ||
type !== "azure_serverless" && | ||
type !== "azure_serverless_models" | ||
) | ||
throw new Error( | ||
"OPENAI_API_TYPE must be 'azure', 'azure_serverless', 'azure_serverless_models' or 'openai' or 'localai'" | ||
) | ||
throw new Error( | ||
"OPENAI_API_TYPE must be 'azure', 'azure_serverless', 'azure_serverless_models' or 'openai' or 'localai'" | ||
) | ||
if (type === "openai" && !base) base = OPENAI_API_BASE | ||
if (type === "localai" && !base) base = LOCALAI_API_BASE | ||
if ((type === "azure" || type === "azure_serverless") && !base) | ||
throw new Error( | ||
"OPENAI_API_BASE must be set when type is 'azure'" | ||
) | ||
if (type === "azure") base = cleanAzureBase(base) | ||
if ( | ||
type === "azure" && | ||
version && | ||
version !== AZURE_OPENAI_API_VERSION | ||
if (type === "openai" && !base) base = OPENAI_API_BASE | ||
if (type === "localai" && !base) base = LOCALAI_API_BASE | ||
if ((type === "azure" || type === "azure_serverless") && !base) | ||
throw new Error("OPENAI_API_BASE must be set when type is 'azure'") | ||
if (type === "azure") base = cleanAzureBase(base) | ||
if (type === "azure" && version && version !== AZURE_OPENAI_API_VERSION) | ||
throw new Error( | ||
`OPENAI_API_VERSION must be '${AZURE_OPENAI_API_VERSION}'` | ||
) | ||
throw new Error( | ||
`OPENAI_API_VERSION must be '${AZURE_OPENAI_API_VERSION}'` | ||
) | ||
if (!token && !/^http:\/\//i.test(base)) | ||
// localhost typically requires no key | ||
throw new Error("OPENAI_API_KEY missing") | ||
if (token === PLACEHOLDER_API_KEY) | ||
throw new Error("OPENAI_API_KEY not configured") | ||
if (base === PLACEHOLDER_API_BASE) | ||
throw new Error("OPENAI_API_BASE not configured") | ||
if (base && !URL.canParse(base)) | ||
throw new Error("OPENAI_API_BASE must be a valid URL") | ||
return { | ||
provider, | ||
model, | ||
base, | ||
type, | ||
token, | ||
source: "env: OPENAI_API_...", | ||
version, | ||
} | ||
if (!token && !/^http:\/\//i.test(base)) | ||
// localhost typically requires no key | ||
throw new Error("OPENAI_API_KEY missing") | ||
Check failure on line 115 in packages/core/src/connection.ts GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code throws an error if the
|
||
if (token === PLACEHOLDER_API_KEY) | ||
throw new Error("OPENAI_API_KEY not configured") | ||
if (base === PLACEHOLDER_API_BASE) | ||
throw new Error("OPENAI_API_BASE not configured") | ||
if (base && !URL.canParse(base)) | ||
throw new Error("OPENAI_API_BASE must be a valid URL") | ||
return { | ||
provider, | ||
model, | ||
base, | ||
type, | ||
token, | ||
source: "env: OPENAI_API_...", | ||
version, | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,7 +194,8 @@ | |
"https://microsoft.github.io/genaiscript/getting-started/configuration/#huggingface" | ||
export const DOCS_CONFIGURATION_CONTENT_SAFETY_URL = | ||
"https://microsoft.github.io/genaiscript/reference/scripts/content-safety" | ||
export const DOCS_DEF_FILES_IS_EMPTY_URL = "https://microsoft.github.io/genaiscript/reference/scripts/context/#empty-files" | ||
export const DOCS_DEF_FILES_IS_EMPTY_URL = | ||
"https://microsoft.github.io/genaiscript/reference/scripts/context/#empty-files" | ||
|
||
export const MODEL_PROVIDERS = Object.freeze([ | ||
{ | ||
|
@@ -222,31 +223,31 @@ | |
detail: "Azure AI Models (serverless deployments, not OpenAI)", | ||
url: DOCS_CONFIGURATION_AZURE_MODELS_SERVERLESS_URL, | ||
}, | ||
{ | ||
id: MODEL_PROVIDER_ANTHROPIC, | ||
detail: "Anthropic models", | ||
url: DOCS_CONFIGURATION_ANTHROPIC_URL, | ||
}, | ||
{ | ||
id: MODEL_PROVIDER_HUGGINGFACE, | ||
detail: "Hugging Face models", | ||
url: DOCS_CONFIGURATION_HUGGINGFACE_URL, | ||
}, | ||
{ | ||
id: MODEL_PROVIDER_OLLAMA, | ||
detail: "Ollama local model", | ||
url: DOCS_CONFIGURATION_OLLAMA_URL, | ||
}, | ||
{ | ||
id: MODEL_PROVIDER_LLAMAFILE, | ||
detail: "llamafile.ai local model", | ||
url: DOCS_CONFIGURATION_LLAMAFILE_URL, | ||
}, | ||
{ | ||
id: MODEL_PROVIDER_LITELLM, | ||
detail: "LiteLLM proxy", | ||
url: DOCS_CONFIGURATION_LITELLM_URL, | ||
}, | ||
Check failure on line 250 in packages/core/src/constants.ts GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
|
||
{ | ||
id: MODEL_PROVIDER_ANTHROPIC, | ||
detail: "Anthropic models", | ||
url: DOCS_CONFIGURATION_ANTHROPIC_URL, | ||
}, | ||
{ | ||
id: MODEL_PROVIDER_HUGGINGFACE, | ||
detail: "Hugging Face models", | ||
url: DOCS_CONFIGURATION_HUGGINGFACE_URL, | ||
}, | ||
]) | ||
|
||
export const NEW_SCRIPT_TEMPLATE = `$\`Write a short poem in code.\` | ||
|
@@ -335,4 +336,5 @@ | |
|
||
export const CHOICE_LOGIT_BIAS = 5 | ||
|
||
export const SANITIZED_PROMPT_INJECTION = "...prompt injection detected, content removed..." | ||
export const SANITIZED_PROMPT_INJECTION = | ||
"...prompt injection detected, content removed..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling logic inside the
envInfo
function only pushes errors to the result if theerror
option is set. This might lead to silent failures if the option is not set. Consider logging or handling errors in a way that ensures they are not completely ignored. 🚨