File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ export interface ConfigResult<T> {
1212 configLoadInterrupted : boolean ;
1313}
1414
15+ function containsUnicode ( str : string ) : boolean {
16+ return / [ ^ \x00 - \x7F ] / . test ( str ) ;
17+ }
18+
1519export function validateConfigYaml (
1620 config : ConfigYaml ,
1721) : ConfigValidationError [ ] {
@@ -32,6 +36,25 @@ export function validateConfigYaml(
3236 if ( "uses" in model ) {
3337 return ;
3438 }
39+
40+ // request headers to the llm api should not contain unicode characters
41+ if ( model . apiKey && containsUnicode ( model . apiKey ) ) {
42+ errors . push ( {
43+ fatal : true ,
44+ message : `Model "${ model . name } " has an API key containing unicode characters. API keys should only contain ASCII characters.` ,
45+ } ) ;
46+ }
47+
48+ if ( model . requestOptions ?. headers ) {
49+ for ( const [ key , value ] of Object . entries ( model . requestOptions . headers ) ) {
50+ if ( containsUnicode ( key ) || containsUnicode ( value ) ) {
51+ errors . push ( {
52+ fatal : true ,
53+ message : `Model "${ model . name } " has a request header "${ key } " containing unicode characters. Request headers should only contain ASCII characters.` ,
54+ } ) ;
55+ }
56+ }
57+ }
3558 // Max tokens not too close to context length
3659 if (
3760 model . defaultCompletionOptions ?. contextLength &&
You can’t perform that action at this time.
0 commit comments