Use ChatGPT

The Documentize PDF Manager for .NET plugin は、ChatGPT API を PDF アプリケーションに統合するよう設計された強力なツールです。このプラグインにより、開発者は入力メッセージに基づいてチャット応答を生成し、その出力を PDF 形式で保存できるため、PDF ドキュメント内で対話型インターフェイスや分析レポートを直接作成するのに適しています。

Generate Chat Responses

ChatGPT プラグインを使用してチャット応答を生成し、PDF ファイルに保存するには、次の手順に従ってください。

  1. ChatGptRequestOptions クラスのインスタンスを作成し、リクエストオプションを構成します。
  2. 入力および出力の PDF ファイルを追加します。
  3. API キーを設定し、最大トークン数や ChatGPT モデルへのクエリなどのパラメータを指定します。
  4. CreatePdfByChatGptRequestAsync メソッドを実行して、チャット完了を生成します。
 1var options = new ChatGptRequestOptions();
 2// Set output file path
 3options.AddOutput(new FileData("path_to_result_pdf_file.pdf")); 
 4options.ApiKey = "Your API key."; // You need to provide the key to access the API.
 5options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.
 6
 7// Add the request messages.
 8options.Messages.Add(new Message
 9{
10    Content = "You are a helpful assistant.",
11    Role = Role.System
12});
13options.Messages.Add(new Message
14{
15    Content = "What is the biggest pizza diameter ever made?",
16    Role = Role.User
17});
18
19// Process the request.
20var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
21
22var fileResultPath = result.ResultCollection[0].Data;
23var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.

Adding System and User Messages

よりインタラクティブな会話を作成するために、システムメッセージとユーザーメッセージの両方を追加できます。これらのメッセージは会話のコンテキストを形成するのに役立ちます。

  1. ChatGPT のコンテキストを設定するシステムメッセージを追加します。
  2. 会話のユーザー入力を表すユーザーメッセージを追加します。
 1var options = new ChatGptRequestOptions();
 2// Set output file path
 3options.AddOutput(new FileData("path_to_result_pdf_file.pdf"));
 4
 5// Add the PDF text source.
 6// In case of multiple sources, the text from each document will be added to the request message collection
 7// as a separate message with the role "user".
 8options.AddInput(new FileData("TextSource.pdf"));
 9
10options.ApiKey = "Your API key."; // You need to provide the key to access the API.
11options.MaxTokens = 1000; // The maximum number of tokens to generate in the chat completion.
12
13// Add the request message.
14// In this case, the system message with Content = "You are a helpful assistant." is added by default.
15// The role of the query message is "user" by default.
16options.Query = "How many letters in the provided text?";
17
18// Process the request.
19var result = await PdfManager.CreatePdfByChatGptRequestAsync(options);
20
21var fileResultPath = result.ResultCollection[0].Data;
22var chatCompletionObject = result.ResultCollection[1].Data as ChatCompletion; // The ChatGPT API chat completion object.

Key Features:

  • Chat Completions: カスタム入力に基づき ChatGPT API を使用して応答を生成します。
  • System & User Messages: システムコンテキストとユーザー入力の両方を提供し、動的な会話を実現します。
  • PDF Output: 生成されたチャット完了を構造化された PDF ファイルとして保存し、後続の利用が可能です。
  • Asynchronous Processing: 非同期でチャット完了を処理し、アプリケーションの応答性を確保します。
 日本語