PDF ChatGPT
The Documentize ChatGPT for .NET plugin is a powerful tool designed to integrate the ChatGPT API with PDF applications. This plugin allows developers to generate chat responses based on input messages and save the output in PDF format, making it suitable for creating conversational interfaces or analysis reports directly within PDF documents.
Key Features:
- Chat Completions: Generate responses using the ChatGPT API based on custom input.
- System & User Messages: Provide both system context and user input to create dynamic conversations.
- PDF Output: Save generated chat completions in a structured PDF file for further use.
- Asynchronous Processing: Ensure responsive applications by processing chat completions asynchronously.
Generate Chat Responses
To generate chat responses and save them to a PDF file using the ChatGPT plugin, follow these steps:
- Create an instance of the
PdfChatGptRequestOptions
class to configure the request options. - Add input and output PDF files.
- Set the API key and specify parameters such as maximum token count and the query for the ChatGPT model.
- Run the
ProcessAsync
method to generate the chat completion.
1var options = new PdfChatGptRequestOptions();
2options.ApiKey = "sk-******"; // Set your API key
3options.MaxTokens = 1000; // Set the maximum number of tokens
4options.Query = "Analyze this text for key themes.";
5
6// Add the input PDF file
7options.AddInput(new FileDataSource("input.pdf"));
8
9// Specify where to save the output PDF with chat responses
10options.AddOutput(new FileDataSource("output.pdf"));
11
12// Create an instance of the PdfChatGpt plugin
13var plugin = new PdfChatGpt();
14
15// Run the process asynchronously
16var result = await plugin.ProcessAsync(options);
Adding System and User Messages
To create a more interactive conversation, you can add both system and user messages. These messages help shape the conversation context.
- Add a system message that sets the context for ChatGPT.
- Add a user message that represents the user’s input for the conversation.
1var options = new PdfChatGptRequestOptions();
2options.ApiKey = "sk-******"; // Set your API key
3
4// Add system message for context
5options.AddSystemMessage("You are an AI trained to summarize text.");
6
7// Add user message to query the ChatGPT model
8options.AddUserMessage("Please summarize the attached document.");
9
10// Add input and output PDFs
11options.AddInput(new FileDataSource("input.pdf"));
12options.AddOutput(new FileDataSource("output.pdf"));
13
14// Process the request asynchronously
15var plugin = new PdfChatGpt();
16var result = await plugin.ProcessAsync(options);