TsgcAIChat › Methods › ChatWithDocument

ChatWithDocument Method

Sends a user message together with a PDF or image file and returns the assistant response.

Syntax

function ChatWithDocument(const aMessage, aFileName: string): string;

Parameters

NameTypeDescription
aMessageconst stringUser message, for example the question about the document.
aFileNameconst stringFull path of the PDF or image file.

Return Value

The assistant response, or an empty string on error. (string)

Remarks

The file is read, encoded as base64 and attached to the user message. The media type comes from the extension: .pdf, .png, .jpg, .jpeg, .gif or .webp. The message and the document are stored in the history, so follow up questions can refer to the document without sending it again.

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

Like Chat, a transport error, a provider error or a document the provider does not accept is reported through OnChatError and the method returns an empty string. An unsupported extension is reported the same way.

Example

vAnswer := oChat.ChatWithDocument('Summarise this report', 'report.pdf');

Back to Methods