Merge pull request #10380 from uinstinct/validate-unicode
fix: validate unicode in model apikey or headers
This commit is contained in:
commit
d6069ed93b
1 changed files with 23 additions and 0 deletions
|
|
@ -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[] {
|
||||
|
|
@ -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 &&
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue