如何使用 OpenAI for PDF
OpenAI 是一个人工智能研究实验室,由营利性的 OpenAI LP 及其非营利性母公司 OpenAI Inc.其成立的目标是以造福全人类的方式推进数字智能的发展。OpenAI 在人工智能的各个领域开展研究 (人工智能) 并致力于开发安全、有益和可获得的人工智能技术。
该组织 IronPdf.Extensions.AI NuGet 软件包现在可以使用 OpenAI 增强 PDF:摘要、查询和记忆。该软件包利用 Microsoft 语义内核.
如何使用 OpenAI for PDF
- 下载 C# 库以利用 OpenAI for PDF
- 为 OpenAI 准备 Azure 端点和 API 密钥
- 导入目标 PDF 文档
- 使用
总结
方法生成 PDF 摘要 - 使用
查询
连续查询方法
开始在您的项目中使用IronPDF,并立即获取免费试用。
查看 IronPDF 上 Nuget 用于快速安装和部署。它有超过800万次下载,正在使用C#改变PDF。
Install-Package IronPdf
考虑安装 IronPDF DLL 直接。下载并手动安装到您的项目或GAC表单中: IronPdf.zip
手动安装到你的项目中
下载DLL总结 PDF 示例
要使用 OpenAI 功能,需要一个 Azure 端点和一个 API 密钥。根据下面的代码示例配置语义内核。导入PDF文档,利用 "Summarize "方法生成PDF文档的摘要。您可以下载示例 PDF 文件 这里.
:path=/static-assets/pdf/content-code-examples/how-to/openai-summarize.cs
using IronPdf;
using IronPdf.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
using System;
using System.Threading.Tasks;
// Setup OpenAI
string azureEndpoint = "AzureEndPoint";
string apiKey = "APIKEY";
var volatileMemoryStore = new VolatileMemoryStore();
var builder = new KernelBuilder()
.WithAzureTextEmbeddingGenerationService("oaiembed", azureEndpoint, apiKey)
.WithAzureChatCompletionService("oaichat", azureEndpoint, apiKey)
.WithMemoryStorage(volatileMemoryStore);
var kernel = builder.Build();
// Initialize IronAI
IronAI.Initialize(kernel);
// Import PDF document
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Summarize the document
string summary = await pdf.Summarize(); // optionally pass AI instance or use AI instance directly
Console.WriteLine($"Document summary: {summary}");
Imports IronPdf
Imports IronPdf.AI
Imports Microsoft.SemanticKernel
Imports Microsoft.SemanticKernel.Memory
Imports System
Imports System.Threading.Tasks
' Setup OpenAI
Private azureEndpoint As String = "AzureEndPoint"
Private apiKey As String = "APIKEY"
Private volatileMemoryStore = New VolatileMemoryStore()
Private builder = (New KernelBuilder()).WithAzureTextEmbeddingGenerationService("oaiembed", azureEndpoint, apiKey).WithAzureChatCompletionService("oaichat", azureEndpoint, apiKey).WithMemoryStorage(volatileMemoryStore)
Private kernel = builder.Build()
' Initialize IronAI
IronAI.Initialize(kernel)
' Import PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile("wikipedia.pdf")
' Summarize the document
Dim summary As String = Await pdf.Summarize() ' optionally pass AI instance or use AI instance directly
Console.WriteLine($"Document summary: {summary}")
产出摘要
连续查询示例
单一查询可能不适合所有情况。查询 IronPdf.Extensions.AI 软件包还提供了一种查询方法,允许用户执行连续查询。
:path=/static-assets/pdf/content-code-examples/how-to/openai-query.cs
using IronPdf;
using IronPdf.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
using System;
using System.Threading.Tasks;
// Setup OpenAI
string azureEndpoint = "AzureEndPoint";
string apiKey = "APIKEY";
var volatileMemoryStore = new VolatileMemoryStore();
var builder = new KernelBuilder()
.WithAzureTextEmbeddingGenerationService("oaiembed", azureEndpoint, apiKey)
.WithAzureChatCompletionService("oaichat", azureEndpoint, apiKey)
.WithMemoryStorage(volatileMemoryStore);
var kernel = builder.Build();
// Initialize IronAI
IronAI.Initialize(kernel);
// 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}");
}
Imports Microsoft.VisualBasic
Imports IronPdf
Imports IronPdf.AI
Imports Microsoft.SemanticKernel
Imports Microsoft.SemanticKernel.Memory
Imports System
Imports System.Threading.Tasks
' Setup OpenAI
Private azureEndpoint As String = "AzureEndPoint"
Private apiKey As String = "APIKEY"
Private volatileMemoryStore = New VolatileMemoryStore()
Private builder = (New KernelBuilder()).WithAzureTextEmbeddingGenerationService("oaiembed", azureEndpoint, apiKey).WithAzureChatCompletionService("oaichat", azureEndpoint, apiKey).WithMemoryStorage(volatileMemoryStore)
Private kernel = builder.Build()
' Initialize IronAI
IronAI.Initialize(kernel)
' Import PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile("wikipedia.pdf")
' Continuous query
Do
Console.Write("User Input: ")
Dim response = Await pdf.Query(Console.ReadLine())
Console.WriteLine($vbLf & "{response}")
Loop