OpenAIを利用してPDFを使用する方法
OpenAIは営利会社であるOpenAI LPとその非営利親会社であるOpenAI Inc.から構成される人工知能研究所です。OpenAIは、人類全体に利益をもたらす方法でデジタルインテリジェンスを進歩させることを目標に設立されました。 OpenAIは、さまざまな人工知能の分野で研究を行っています。(AI)そして、安全で有益かつアクセス可能なAI技術の開発を目指しています。
についてIronPdf.Extensions.AI
NuGetパッケージは、PDFの強化のためにOpenAIを有効にしました: 要約、クエリ、およびメモリ化。 パッケージではMicrosoftを使用していますセマンティックカーネル.
IronPDFを始めましょう
今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。
OpenAIを利用してPDFを使用する方法
- PDFのためにOpenAIを利用するためのC#ライブラリをダウンロードする
- AzureエンドポイントとOpenAIのAPIキーを準備する
- ターゲットPDFドキュメントをインポートする
- 以下を使用
要約
PDFの概要を生成する方法 - 以下を使用
クエリ
連続クエリのメソッド
今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。
他のIronPDFパッケージには、次の2つのパッケージも必要です。
PDF例の概要
OpenAI機能を使用するには、AzureエンドポイントとAPIキーが必要です。 以下のコード例に従ってセマンティックカーネルを構成します。 PDFドキュメントをインポートして、Summarize
メソッドを利用してPDFドキュメントの要約を生成します。 サンプルPDFファイルはOpenAI for PDF要約の例.
次の内容にご注意ください。
SKEXP0001、SKEXP0010、SKEXP0050エラーが発生します。 これは、セマンティックカーネルのメソッドが実験的であるためです。 これらのエラーを抑制するには、次のコードを.csprojファイルに追加してください。
<PropertyGroup>
<NoWarn>$(NoWarn);SKEXP0001,SKEXP0010,SKEXP0050</NoWarn>
:path=/static-assets/pdf/content-code-examples/how-to/openai-summarize.cs
using IronPdf;
using IronPdf.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Memory;
using System;
using System.Threading.Tasks;
// Setup OpenAI
var azureEndpoint = "<<enter your azure endpoint here>>";
var apiKey = "<<enter your azure API key here>>";
var builder = Kernel.CreateBuilder()
.AddAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
.AddAzureOpenAIChatCompletion("oaichat", azureEndpoint, apiKey);
var kernel = builder.Build();
// Setup Memory
var memory_builder = new MemoryBuilder()
// optionally use new ChromaMemoryStore("http://127.0.0.1:8000") (see https://github.com/microsoft/semantic-kernel/blob/main/dotnet/notebooks/09-memory-with-chroma.ipynb)
.WithMemoryStore(new VolatileMemoryStore())
.WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey);
var memory = memory_builder.Build();
// Initialize IronAI
IronDocumentAI.Initialize(kernel, memory);
License.LicenseKey = "<<enter your IronPdf license key here";
// Import PDF document
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Summarize the document
Console.WriteLine("Please wait while I summarize the document...");
string summary = await pdf.Summarize(); // optionally pass AI instance or use AI instance directly
Console.WriteLine($"Document summary: {summary}\n\n");
出力概要

連続クエリの例
単一のクエリがすべてのシナリオに適しているとは限りません。 についてIronPdf.Extensions.AI
パッケージには、ユーザーが継続的なクエリを実行するためのQueryメソッドも含まれています。
:path=/static-assets/pdf/content-code-examples/how-to/openai-query.cs
using IronPdf;
using IronPdf.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Memory;
using System;
using System.Threading.Tasks;
// Setup OpenAI
var azureEndpoint = "<<enter your azure endpoint here>>";
var apiKey = "<<enter your azure API key here>>";
var builder = Kernel.CreateBuilder()
.AddAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
.AddAzureOpenAIChatCompletion("oaichat", azureEndpoint, apiKey);
var kernel = builder.Build();
// Setup Memory
var memory_builder = new MemoryBuilder()
// optionally use new ChromaMemoryStore("http://127.0.0.1:8000") (see https://github.com/microsoft/semantic-kernel/blob/main/dotnet/notebooks/09-memory-with-chroma.ipynb)
.WithMemoryStore(new VolatileMemoryStore())
.WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey);
var memory = memory_builder.Build();
// Initialize IronAI
IronDocumentAI.Initialize(kernel, memory);
License.LicenseKey = "<<enter your IronPdf license key here";
// Import PDF document
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Continuous query
while (true)
{
Console.Write("User Input: ");
var response = await pdf.Query(Console.ReadLine());
Console.WriteLine($"\n{response}");
}