TsgcAIOpenAIEmbeddingsEvents › OnBeforeCreateEmbedding

OnBeforeCreateEmbedding Event

Fired before each chunk is sent, allowing the request to be inspected or skipped.

Syntax

property OnBeforeCreateEmbedding: TsgcOpenAIBeforeCreateEmbedding;
// TsgcOpenAIBeforeCreateEmbedding = procedure(Sender: TObject; const aRequest: TsgcOpenAIClass_Request_Embeddings; var Accept: Boolean) of object

Default Value

Remarks

Raised once per chunk, just before the HTTP call to the OpenAI embeddings endpoint. aRequest exposes the populated Model and Input fields, allowing you to log them, modify them in place or filter them. Set Accept to False to skip the current chunk (no HTTP call is performed and no storage is written); it defaults to True. This is the recommended place to implement custom filtering, auditing or content redaction.

Example

procedure TForm1.oEmbeddingsBeforeCreateEmbedding(Sender: TObject;
  const aRequest: TsgcOpenAIClass_Request_Embeddings; var Accept: Boolean);
begin
  Memo1.Lines.Add('Sending chunk: ' + Copy(aRequest.Input, 1, 60) + '...');
  // Skip empty or whitespace-only chunks
  if Trim(aRequest.Input) = '' then
    Accept := False;
end;

Back to Events