TsgcAIChat › Methods › ChatJSONWithAttachments
Sends a user message with documents and returns the answer as a JSON document.
function ChatJSONWithAttachments(const aMessage: string; const aAttachments: TsgcAIChatAttachments): string;
| Name | Type | Description |
|---|---|---|
aMessage | const string | User message. |
aAttachments | const TsgcAIChatAttachments | The documents to send. |
The answer of the provider, as JSON text. (string)
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.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;