Json Schema for LLMs
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
unit Myc.Ast.Attributes;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
system.sysutils;
|
||||
|
||||
type
|
||||
{ Defines the content type for the LLM schema generation. }
|
||||
TFieldKind = (
|
||||
fkNode, // IAstNode (recursive structure)
|
||||
fkTuple, // ITupleNode (explicit ["Tuple", [...]] structure)
|
||||
fkString, // Raw String (for identifiers/names)
|
||||
fkValue, // TDataValue (primitive constants like number, string, boolean)
|
||||
fkNullableNode, // Optional Node (emits 'AstNode | null' in TypeScript)
|
||||
fkArrayOfPairs // Special structure for CondExpr: [[Cond, Branch], ...]
|
||||
);
|
||||
|
||||
{ AstTagAttribute: Defines the JSON Tag for an AST Node. }
|
||||
AstTagAttribute = class(TCustomAttribute)
|
||||
private
|
||||
FTag: string;
|
||||
public
|
||||
constructor Create(const ATag: string);
|
||||
property Tag: string read FTag;
|
||||
end;
|
||||
|
||||
{ AstFieldAttribute: Defines a field within the JSON Array. }
|
||||
AstFieldAttribute = class(TCustomAttribute)
|
||||
private
|
||||
FName: string;
|
||||
FKind: TFieldKind;
|
||||
FIndex: Integer;
|
||||
public
|
||||
constructor Create(AIndex: Integer; const AName: string; AKind: TFieldKind);
|
||||
property Index: Integer read FIndex;
|
||||
property Name: string read FName;
|
||||
property Kind: TFieldKind read FKind;
|
||||
end;
|
||||
|
||||
{ AstDocAttribute: Provides semantic documentation for the LLM. }
|
||||
AstDocAttribute = class(TCustomAttribute)
|
||||
private
|
||||
FDescription: string;
|
||||
public
|
||||
constructor Create(const ADescription: string);
|
||||
property Description: string read FDescription;
|
||||
end;
|
||||
|
||||
{ AstScriptExampleAttribute: Provides an example in script syntax.
|
||||
The generator converts this to JSON AST for the LLM prompt. }
|
||||
AstScriptExampleAttribute = class(TCustomAttribute)
|
||||
private
|
||||
FScript: string;
|
||||
public
|
||||
constructor Create(const AScript: string);
|
||||
property Script: string read FScript;
|
||||
end;
|
||||
|
||||
{ AstSignatureAttribute: Defines a specific overload signature for an RTL function. }
|
||||
AstSignatureAttribute = class(TCustomAttribute)
|
||||
private
|
||||
FSignature: string;
|
||||
public
|
||||
constructor Create(const ASignature: string);
|
||||
property Signature: string read FSignature;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ AstTagAttribute }
|
||||
|
||||
constructor AstTagAttribute.Create(const ATag: string);
|
||||
begin
|
||||
inherited Create;
|
||||
FTag := ATag;
|
||||
end;
|
||||
|
||||
{ AstFieldAttribute }
|
||||
|
||||
constructor AstFieldAttribute.Create(AIndex: Integer; const AName: string; AKind: TFieldKind);
|
||||
begin
|
||||
inherited Create;
|
||||
FIndex := AIndex;
|
||||
FName := AName;
|
||||
FKind := AKind;
|
||||
end;
|
||||
|
||||
{ AstDocAttribute }
|
||||
|
||||
constructor AstDocAttribute.Create(const ADescription: string);
|
||||
begin
|
||||
inherited Create;
|
||||
FDescription := ADescription;
|
||||
end;
|
||||
|
||||
{ AstScriptExampleAttribute }
|
||||
|
||||
constructor AstScriptExampleAttribute.Create(const AScript: string);
|
||||
begin
|
||||
inherited Create;
|
||||
FScript := AScript;
|
||||
end;
|
||||
|
||||
{ AstSignatureAttribute }
|
||||
|
||||
constructor AstSignatureAttribute.Create(const ASignature: string);
|
||||
begin
|
||||
inherited Create;
|
||||
FSignature := ASignature;
|
||||
end;
|
||||
|
||||
end.
|
||||
Reference in New Issue
Block a user