1
- import { ILlmSchema , IOpenApiSchemaError , IResult } from "@samchon/openapi" ;
1
+ import {
2
+ IChatGptSchema ,
3
+ ILlmSchema ,
4
+ IOpenApiSchemaError ,
5
+ IResult ,
6
+ } from "@samchon/openapi" ;
2
7
import { LlmSchemaComposer } from "@samchon/openapi/lib/composers/LlmSchemaComposer" ;
3
8
4
9
import { IJsonSchemaCollection } from "../../schemas/json/IJsonSchemaCollection" ;
@@ -60,25 +65,52 @@ export namespace LlmSchemaProgrammer {
60
65
} ;
61
66
62
67
export const validate =
63
- ( model : ILlmSchema . Model ) =>
68
+ < Model extends ILlmSchema . Model > ( props : {
69
+ model : ILlmSchema . Model ;
70
+ config ?: Partial < ILlmSchema . ModelConfig [ Model ] > ;
71
+ } ) =>
64
72
( metadata : Metadata ) : string [ ] => {
65
73
const output : string [ ] = [ ] ;
74
+
75
+ // no additionalProperties in ChatGPT strict mode or Gemini
66
76
if (
67
- metadata . atomics . some ( ( a ) => a . type === "bigint" ) ||
68
- metadata . constants . some ( ( c ) => c . type === "bigint" )
69
- )
70
- output . push ( "LLM schema does not support bigint type." ) ;
71
- if (
72
- ( model === "chatgpt" || model === "gemini" ) &&
77
+ ( ( props . model === "chatgpt" &&
78
+ ( props . config as Partial < IChatGptSchema . IConfig > | undefined )
79
+ ?. strict === true ) ||
80
+ props . model === "gemini" ) &&
73
81
metadata . objects . some ( ( o ) =>
74
82
o . type . properties . some (
75
83
( p ) => p . key . isSoleLiteral ( ) === false && p . value . size ( ) !== 0 ,
76
84
) ,
77
85
)
78
86
)
79
87
output . push (
80
- `LLM schema of "${ model } " does not support dynamic property in object.` ,
88
+ `LLM schema of "${ props . model } "${ props . model === "chatgpt" ? " (strict mode)" : "" } does not support dynamic property in object.` ,
89
+ ) ;
90
+
91
+ // ChatGPT strict mode even does not support the optional property
92
+ if (
93
+ props . model === "chatgpt" &&
94
+ ( props . config as Partial < IChatGptSchema . IConfig > | undefined )
95
+ ?. strict === true &&
96
+ metadata . objects . some ( ( o ) =>
97
+ o . type . properties . some ( ( p ) => p . value . isRequired ( ) === false ) ,
98
+ )
99
+ )
100
+ output . push (
101
+ `LLM schema of "chatgpt" (strict mode) does not support optional property in object.` ,
81
102
) ;
103
+
104
+ // Gemini does not support the union type
105
+ if ( props . model === "gemini" && size ( metadata ) > 1 )
106
+ output . push ( "Gemini model does not support the union type." ) ;
107
+
108
+ // just JSON rule
109
+ if (
110
+ metadata . atomics . some ( ( a ) => a . type === "bigint" ) ||
111
+ metadata . constants . some ( ( c ) => c . type === "bigint" )
112
+ )
113
+ output . push ( "LLM schema does not support bigint type." ) ;
82
114
if (
83
115
metadata . tuples . some ( ( t ) =>
84
116
t . type . elements . some ( ( e ) => e . isRequired ( ) === false ) ,
@@ -98,8 +130,6 @@ export namespace LlmSchemaProgrammer {
98
130
native . name !== "File"
99
131
)
100
132
output . push ( `LLM schema does not support ${ native . name } type.` ) ;
101
- if ( model === "gemini" && size ( metadata ) > 1 )
102
- output . push ( "Gemini model does not support the union type." ) ;
103
133
return output ;
104
134
} ;
105
135
}
0 commit comments