Class PdfChatGpt

Class PdfChatGpt

Namespace: Aspose.Pdf.Plugins
Assembly: Aspose.PDF.dll

Represents PdfChatGpt plugin.

public sealed class PdfChatGpt : IPlugin, IDisposable

Inheritance

objectPdfChatGpt

Implements

IPlugin, IDisposable

Inherited Members

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Examples

The example demonstrates how to use PdfChatGpt plugin by adding messages to the request.

using (var plugin = new PdfChatGpt())
{
    var options = new PdfChatGptRequestOptions();
    options.AddOutput(new FileDataSource("PdfChatGPT_output.pdf")); // Add the output file path.
    options.ApiKey = "Your API key."; // You need to provide the key to access the API.
    options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.

    // Add the request messages.
    options.Messages.Add(new Message
    {
        Content = "You are a helpful assistant.",
        Role = Role.System
    });
    options.Messages.Add(new Message
    {
        Content = "What is the biggest pizza diameter ever made?",
        Role = Role.User
    });

    // Process the request.
    var result = await plugin.ProcessAsync(options);

    var fileResultPath = result.ResultCollection[0].Data;
    var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.
}

The example demonstrates how to use PdfChatGpt plugin by adding one message to the request.

using (var plugin = new PdfChatGpt())
{
    var options = new PdfChatGptRequestOptions();
    options.AddOutput(new FileDataSource("PdfChatGPT_output.pdf")); // Add the output file path.
    options.ApiKey = "Your API key."; // You need to provide the key to access the API.
    options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.

    // Add the request message.
    // In this case, the system message with Content = "You are a helpful assistant." is added by default.
    // The role of the query message is "user" by default.
    options.Query = "What is the lowest temperature recorded on the Earth?";

    // Process the request.
    var result = await plugin.ProcessAsync(options);

    var fileResultPath = result.ResultCollection[0].Data;
    var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.
}

The example demonstrates how to use PdfChatGpt plugin by adding file(s) as the message source(s).

using (var plugin = new PdfChatGpt())
{
    var options = new PdfChatGptRequestOptions();
    options.AddOutput(new FileDataSource("PdfChatGPT_output.pdf")); // Add the output file path.

    // Add the PDF text source.
    // In case of multiple sources, the text from each document will be added to the request message collection
    // as a separate message with the role "user".
    options.AddInput(new FileDataSource("TextSource.pdf"));

    options.ApiKey = "Your API key."; // You need to provide the key to access the API.
    options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.

    // Add the request message.
    // In this case, the system message with Content = "You are a helpful assistant." is added by default.
    // The role of the query message is "user" by default.
    options.Query = "How many letters in the provided text?";

    // Process the request.
    var result = await plugin.ProcessAsync(options);

    var fileResultPath = result.ResultCollection[0].Data;
    var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.
}

Remarks

The Aspose.Pdf.Plugins.PdfChatGpt object is used to send requests to ChatGPT directly or by adding PDF file sources and save the reply to the output source.

Constructors

PdfChatGpt()

public PdfChatGpt()

Methods

Dispose()

Implementation of IDisposable. In fact, it is not necessary for PdfChatGpt.

public void Dispose()

Process(IPluginOptions)

The method has no synchronous version. Use the ProcessAsync method instead.

public ResultContainer Process(IPluginOptions options)

Parameters

options IPluginOptions

An options object containing instructions for the PdfChatGpt.

Returns

ResultContainer

Exceptions

NotImplementedException

ProcessAsync(IPluginOptions)

Starts the PdfChatGpt processing with the specified parameters.

public Task<resultcontainer> ProcessAsync(IPluginOptions options)

Parameters

options IPluginOptions

An options object containing instructions for the PdfChatGpt.

Returns

Task<ResultContainer&gt;

The task object representing the asynchronous operation.

Exceptions

ArgumentException

InvalidOperationException

SetCancellationToken(CancellationToken)

Sets the cancellation token.

public void SetCancellationToken(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The cancellation token.

 English