@@ -73,132 +73,3 @@ json OpenAIChatSchemaBuilder::build() const {
7373 }
7474 return json{{" type" , " text" }}; // fallback
7575}
76-
77- // OpenAISchemaPatterns implementation
78- OpenAI::TextOutputConfig OpenAISchemaPatterns::sentimentAnalysis () {
79- return OpenAIResponsesSchemaBuilder (" sentiment_analysis" )
80- .description (" Analyze the sentiment of the given text" )
81- .property (" sentiment" , JsonSchemaBuilder::stringEnum ({" positive" , " negative" , " neutral" }))
82- .property (" confidence" , JsonSchemaBuilder::number ().minimum (0 ).maximum (1 ).description (
83- " Confidence score from 0 to 1" ))
84- .required ({" sentiment" , " confidence" })
85- .build ();
86- }
87-
88- OpenAI::TextOutputConfig OpenAISchemaPatterns::dataExtraction (
89- const std::vector<std::string>& fields) {
90- auto builder = OpenAIResponsesSchemaBuilder (" data_extraction" )
91- .description (" Extract structured data from text" );
92-
93- for (const auto & field : fields) {
94- builder.property (field, JsonSchemaBuilder::string ().description (" Extracted " + field));
95- }
96-
97- builder.required (fields);
98- return builder.build ();
99- }
100-
101- OpenAI::TextOutputConfig OpenAISchemaPatterns::classification (
102- const std::vector<std::string>& categories) {
103- return OpenAIResponsesSchemaBuilder (" classification" )
104- .description (" Classify the input into one of the predefined categories" )
105- .property (" category" , JsonSchemaBuilder::stringEnum (categories))
106- .property (" confidence" , JsonSchemaBuilder::number ().minimum (0 ).maximum (1 ))
107- .property (" reasoning" , JsonSchemaBuilder::string ().description (
108- " Brief explanation of the classification" ))
109- .required ({" category" , " confidence" })
110- .build ();
111- }
112-
113- OpenAI::TextOutputConfig OpenAISchemaPatterns::summary (int maxLength) {
114- return OpenAIResponsesSchemaBuilder (" summary" )
115- .description (" Generate a concise summary of the input text" )
116- .property (" summary" ,
117- JsonSchemaBuilder::string ().maxLength (maxLength).description (" Concise summary" ))
118- .property (
119- " key_points" ,
120- JsonSchemaBuilder::arrayOf (JsonSchemaBuilder::string ()).description (" Main points" ))
121- .property (" word_count" ,
122- JsonSchemaBuilder::integer ().minimum (1 ).description (" Number of words in summary" ))
123- .required ({" summary" , " key_points" , " word_count" })
124- .build ();
125- }
126-
127- OpenAI::TextOutputConfig OpenAISchemaPatterns::keyValueExtraction () {
128- return OpenAIResponsesSchemaBuilder (" key_value_extraction" )
129- .description (" Extract key-value pairs from the text" )
130- .property (" extracted_data" ,
131- JsonSchemaBuilder::object ().additionalProperties (JsonSchemaBuilder::string ()))
132- .property (" metadata" , JsonSchemaBuilder::object ()
133- .property (" extraction_confidence" ,
134- JsonSchemaBuilder::number ().minimum (0 ).maximum (1 ))
135- .property (" total_pairs" , JsonSchemaBuilder::integer ().minimum (0 )))
136- .required ({" extracted_data" , " metadata" })
137- .build ();
138- }
139-
140- OpenAI::TextOutputConfig OpenAISchemaPatterns::booleanDecision (const std::string& question) {
141- return OpenAIResponsesSchemaBuilder (" boolean_decision" )
142- .description (" Make a yes/no decision based on: " + question)
143- .property (" decision" ,
144- JsonSchemaBuilder::boolean ().description (" True for yes, false for no" ))
145- .property (" reasoning" ,
146- JsonSchemaBuilder::string ().description (" Explanation for the decision" ))
147- .property (" confidence" , JsonSchemaBuilder::number ().minimum (0 ).maximum (1 ))
148- .required ({" decision" , " reasoning" , " confidence" })
149- .build ();
150- }
151-
152- OpenAI::TextOutputConfig OpenAISchemaPatterns::entityExtraction () {
153- auto entitySchema =
154- JsonSchemaBuilder::object ()
155- .property (" text" , JsonSchemaBuilder::string ().description (" The extracted entity text" ))
156- .property (" type" , JsonSchemaBuilder::stringEnum (
157- {" PERSON" , " ORGANIZATION" , " LOCATION" , " DATE" , " MONEY" , " OTHER" }))
158- .property (" start_pos" ,
159- JsonSchemaBuilder::integer ().minimum (0 ).description (" Start position in text" ))
160- .property (" end_pos" ,
161- JsonSchemaBuilder::integer ().minimum (0 ).description (" End position in text" ))
162- .required ({" text" , " type" });
163-
164- return OpenAIResponsesSchemaBuilder (" entity_extraction" )
165- .description (" Extract named entities from the text" )
166- .property (" entities" , JsonSchemaBuilder::arrayOf (entitySchema))
167- .property (" entity_count" , JsonSchemaBuilder::integer ().minimum (0 ))
168- .required ({" entities" , " entity_count" })
169- .build ();
170- }
171-
172- OpenAI::TextOutputConfig OpenAISchemaPatterns::translation (const std::string& targetLanguage) {
173- return OpenAIResponsesSchemaBuilder (" translation" )
174- .description (" Translate text to " + targetLanguage)
175- .property (" translated_text" , JsonSchemaBuilder::string ().description (" The translated text" ))
176- .property (" source_language" ,
177- JsonSchemaBuilder::string ().description (" Detected source language" ))
178- .property (" target_language" , JsonSchemaBuilder::string ().constValue (targetLanguage))
179- .property (" confidence" , JsonSchemaBuilder::number ().minimum (0 ).maximum (1 ))
180- .required ({" translated_text" , " source_language" , " target_language" , " confidence" })
181- .build ();
182- }
183-
184- // Chat completions patterns
185- json OpenAISchemaPatterns::chatJsonMode () { return OpenAIChatSchemaBuilder ().jsonMode ().build (); }
186-
187- json OpenAISchemaPatterns::chatClassification (const std::vector<std::string>& categories) {
188- auto schema = JsonSchemaBuilder::object ()
189- .property (" category" , JsonSchemaBuilder::stringEnum (categories))
190- .property (" confidence" , JsonSchemaBuilder::number ().minimum (0 ).maximum (1 ))
191- .required ({" category" , " confidence" });
192-
193- return OpenAIChatSchemaBuilder ().jsonSchema (" classification" , schema).build ();
194- }
195-
196- json OpenAISchemaPatterns::chatSentiment () {
197- auto schema = JsonSchemaBuilder::object ()
198- .property (" sentiment" ,
199- JsonSchemaBuilder::stringEnum ({" positive" , " negative" , " neutral" }))
200- .property (" confidence" , JsonSchemaBuilder::number ().minimum (0 ).maximum (1 ))
201- .required ({" sentiment" , " confidence" });
202-
203- return OpenAIChatSchemaBuilder ().jsonSchema (" sentiment" , schema).build ();
204- }
0 commit comments