-
-
Notifications
You must be signed in to change notification settings - Fork 54
FB4D Reference IGeminiSchema
This interface is used to declare a JSON schema for requesting a JSON object using IGeminiAIRequest.SetJSONResponseSchema
.
For elementary data types, use one of the following methods:
function SetStringType: IGeminiSchema;
function SetFloatType: IGeminiSchema;
function SetIntegerType: IGeminiSchema;
function SetBooleanType: IGeminiSchema;
function SetEnumType(EnumValues: TStringDynArray): IGeminiSchema;
To define an array, use the following method, which in turn transfers an IGeminiSchema as the array element. This makes it easy to create nested types. The number of elements in the array can be defined with limits using the optional parameters.
function SetArrayType(ArrayElement: IGeminiSchema; MaxItems: integer = -1; MinItems: integer = -1): IGeminiSchema;
The following method is used to compile a JSON object, whereby a list of named fields must be transferred together with their data type. The type TSchemaItems, which is defined as TDictonary, is used for this. Two parameters of this type are passed to SetObjectType: The first with the list of all required fields and the second parameter with the list of all optional fields. Note that the SetObjectType function processes the transferred TDictionary objects after processing and immediately releases them for easy use with Fluid-Design.
function SetObjectType(RequiredItems: TSchemaItems; OptionalItems: TSchemaItems = nil): IGeminiSchema;
TSchemaItems = TDictionary<string, IGeminiSchema>;
In this context, it is also helpful to know the following helper class function from the FB4D.helpers unit:
class function TSchemaItemsHelper.CreateItem(const FieldName: string; Schema: IGeminiSchema): TPair<string, IGeminiSchema>;
The following code demonstrates the usage within the unit test GeminiAI.
var Request: IGeminiAIRequest;
Request := TGeminiAIRequest.Create.Prompt('Create a JSON Object for the following math formula: A * A = A^2');
Request.SetJSONResponseSchema(TGeminiSchema.Create.SetObjectType(TSchemaItems.Create(
[TSchemaItems.CreateItem('FirstFactor', TGeminiSchema.StringType),
TSchemaItems.CreateItem('SecondFactor', TGeminiSchema.StringType),
TSchemaItems.CreateItem('ResultingTerm', TGeminiSchema.StringType),
TSchemaItems.CreateItem('NumberOfFactors', TGeminiSchema.IntegerType),
TSchemaItems.CreateItem('IsFormulaCorrect', TGeminiSchema.BooleanType)])));
Have you discovered an error? Or is something unclear? Please let us know in the discussion forum.
Schneider Infosystems Ltd. CH-6340 Baar, Switzerland, www.schneider-infosys.ch
Introduction into FB4D
Getting Started
Fundamental Principles
Project Settings
GUI Pattern Self-Registration
RT-DB Sample Applications
Firestore Chat Sample Applications
PhotoBox demonstrates Firestore, Storage, VisionML
Interface Reference
Configuration and Class Factory
Helper Classes
Authentication