TsgcAIChat › Methods › ChatJSONWithAttachments

ChatJSONWithAttachments Method

Sends a user message with documents and returns the answer as a JSON document.

Syntax

function ChatJSONWithAttachments(const aMessage: string; const aAttachments: TsgcAIChatAttachments): string;

Parameters

NameTypeDescription
aMessageconst stringUser message.
aAttachmentsconst TsgcAIChatAttachmentsThe documents to send.

Return Value

The answer of the provider, as JSON text. (string)

Remarks

The same pipeline as ChatJSON, with the documents on the user message: set ChatOptions.ResponseFormat to rfJSON or rfJSONSchema first, the answer is parsed and retried once when it is not valid JSON, and errors propagate to the caller instead of reaching OnChatError.

See TsgcAIChat Documents and PDF for the providers that accept PDF documents.

TsgcAIDocumentExtractor uses this method and adds schema validation, presets and per field confidence on top of it.

Example

oChat.ChatOptions.ResponseFormat := rfJSON;
oAttachments := TsgcAIChatAttachments.Create;
Try
  oAttachments.AddFile('receipt.jpg');
  vJSON := oChat.ChatJSONWithAttachments('Return the total and the date as json', oAttachments);
Finally
  oAttachments.Free;
End;

Back to Methods