Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/config-yaml/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export interface ConfigResult<T> {
configLoadInterrupted: boolean;
}

function containsUnicode(str: string): boolean {
return /[^\x00-\x7F]/.test(str);
}

export function validateConfigYaml(
config: ConfigYaml,
): ConfigValidationError[] {
Expand All @@ -32,6 +36,25 @@ export function validateConfigYaml(
if ("uses" in model) {
return;
}

// request headers to the llm api should not contain unicode characters
if (model.apiKey && containsUnicode(model.apiKey)) {
errors.push({
fatal: true,
message: `Model "${model.name}" has an API key containing unicode characters. API keys should only contain ASCII characters.`,
});
}

if (model.requestOptions?.headers) {
for (const [key, value] of Object.entries(model.requestOptions.headers)) {
if (containsUnicode(key) || containsUnicode(value)) {
errors.push({
fatal: true,
message: `Model "${model.name}" has a request header "${key}" containing unicode characters. Request headers should only contain ASCII characters.`,
});
}
}
}
// Max tokens not too close to context length
if (
model.defaultCompletionOptions?.contextLength &&
Expand Down
Loading