如何使用 OpenAI for PDF
OpenAI是一个人工智能研究实验室,由营利性的OpenAI LP和其非营利性的母公司OpenAI Inc组成。它的成立目标是以一种造福全人类的方式推进数字智能的发展。 OpenAI 在人工智能的多个领域进行研究。(人工智能)并旨在开发安全、有益且易于获取的人工智能技术。
"(《世界人权宣言》)IronPdf.Extensions.AINuGet 包现在支持 OpenAI 进行 PDF 增强:摘要、查询和记忆。 该软件包使用Microsoft语义内核.
开始使用IronPDF
立即在您的项目中开始使用IronPDF,并享受免费试用。
如何使用 OpenAI for PDF
- 下载 C# 库以利用 OpenAI for PDF
- 为 OpenAI 准备 Azure 端点和 API 密钥
- 导入目标 PDF 文档
- 使用
总结
方法生成 PDF 摘要 - 使用
查询
连续查询方法
总结PDF示例
要使用 OpenAI 功能,需要一个 Azure 端点和一个 API 密钥。 根据下面的代码示例配置语义内核。 导入PDF文档并使用Summarize
方法生成PDF文档的摘要。 您可以从OpenAI for 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