PDF AI Copilot
Aspose.PDF AI Copilot API dirancang untuk memungkinkan pengguna memproses dokumen PDF menggunakan LLM dari berbagai penyedia.
API ini akan membantu pengguna dalam membangun aplikasi chatbot dan mengintegrasikan solusi PDF dengan LLM.
Fitur Utama
Ringkasan dokumen.
Obrolan dengan dokumen.
Dapatkan gambar dari dokumen dan berikan deskripsi.
Contoh
Saat ini, copilots berikut tersedia:
OpenAI Summary memungkinkan pengguna untuk menghasilkan ringkasan dari dokumen. Ini menyediakan cara yang nyaman untuk membuat ringkasan dengan mengonfigurasi opsi seperti model, suhu, jumlah token, instruksi model, lampiran dokumen, dan lainnya. Copilot dapat secara asinkron menghasilkan ringkasan sebagai teks, dokumen, dan menyimpan ringkasan dalam berbagai format. Kode demo yang disediakan menunjukkan pembuatan klien OpenAI, konfigurasi opsi copilot, dan penggunaan SummaryCopilot untuk menghasilkan dan menyimpan ringkasan.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static async Task GetSummary ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_AI ();
// Create AI client
using ( var openAiClient = Aspose . Pdf . AI . OpenAIClient
. CreateWithApiKey ( ApiKey ) // Create OpenAI client with the API key
//.WithProject("proj_123") // Configure optional parameters
. Build ())
{
// Create copilot options
var options = Aspose . Pdf . AI . OpenAISummaryCopilotOptions
. Create () // Create options like this, or...
//.Create(options => { options.Model = OpenAIModels.Gpt35Turbo; }) // ...create using delegate
. WithTemperature ( 0.5 ) // Configure other optional parameters
. WithDocument ( "SampleDocument.pdf" ); // .WithDocument methods allows to add text, pdf and paths to documents
//.WithDocuments(new List<Aspose.Pdf.AI.TextDocument> { new Aspose.Pdf.AI.TextDocument() }); // .WithDocuments methods allows to add text, pdf and path collections
// Create summary copilot
Aspose . Pdf . AI . ISummaryCopilot summaryCopilot = Aspose . Pdf . AI . AICopilotFactory . CreateSummaryCopilot ( openAiClient , options );
// Get summary text
string summaryText = await summaryCopilot . GetSummaryAsync ();
// Get summary document
Aspose . Pdf . Document summaryDocument = await summaryCopilot . GetSummaryDocumentAsync ();
// Get summary document with page info
Aspose . Pdf . Document summaryDocumentWithPageInfo = await summaryCopilot . GetSummaryDocumentAsync ( new Aspose . Pdf . PageInfo ());
// Save PDF document
await summaryCopilot . SaveSummaryAsync ( dataDir + "Summary_out.pdf" );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static async Task GetSummary ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_AI ();
// Create AI client
using var openAiClient = Aspose . Pdf . AI . OpenAIClient
. CreateWithApiKey ( ApiKey ) // Create OpenAI client with the API key
//.WithProject("proj_123") // Configure optional parameters
. Build ();
// Create copilot options
var options = Aspose . Pdf . AI . OpenAISummaryCopilotOptions
. Create () // Create options like this, or...
//.Create(options => { options.Model = OpenAIModels.Gpt35Turbo; }) // ...create using delegate
. WithTemperature ( 0.5 ) // Configure other optional parameters
. WithDocument ( "SampleDocument.pdf" ); // .WithDocument methods allows to add text, pdf and paths to documents
//.WithDocuments(new List<Aspose.Pdf.AI.TextDocument> { new Aspose.Pdf.AI.TextDocument() }); // .WithDocuments methods allows to add text, pdf and path collections
// Create summary copilot
Aspose . Pdf . AI . ISummaryCopilot summaryCopilot = Aspose . Pdf . AI . AICopilotFactory . CreateSummaryCopilot ( openAiClient , options );
// Get summary text
string summaryText = await summaryCopilot . GetSummaryAsync ();
// Get summary document
Aspose . Pdf . Document summaryDocument = await summaryCopilot . GetSummaryDocumentAsync ();
// Get summary document with page info
Aspose . Pdf . Document summaryDocumentWithPageInfo = await summaryCopilot . GetSummaryDocumentAsync ( new Aspose . Pdf . PageInfo ());
// Save PDF document
await summaryCopilot . SaveSummaryAsync ( dataDir + "Summary_out.pdf" );
}
OpenAI Chat adalah copilot AI yang dirancang untuk interaksi obrolan dengan dokumen. Ini memfasilitasi pembuatan respons terhadap pertanyaan pengguna dan pengelolaan konteks. Pengguna dapat mengonfigurasi opsi copilot, seperti model, suhu, jumlah token, instruksi model, lampiran dokumen, dan lainnya. Copilot dapat memberikan respons terhadap satu atau beberapa pertanyaan, menyimpan respons dalam berbagai format, menyimpan dan menghapus konteks.
Kode yang disediakan menunjukkan pembuatan klien OpenAI, konfigurasi opsi ChatCopilot, dan penggunaan ChatCopilot untuk berinteraksi dengan pertanyaan pengguna dan mengelola konteks.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static async Task ChatWithDocument ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_AI ();
// Create AI client
using ( var openAiClient = Aspose . Pdf . AI . OpenAIClient
. CreateWithApiKey ( ApiKey ) // Create OpenAI client with the API key
//.WithProject("proj_123") // Configure optional parameters
//.WithOrganization("org_123")
. Build ()) // Build
{
// Create copilot options
var options = Aspose . Pdf . AI . OpenAIChatCopilotOptions
. Create () // Create options like this, or...
//.Create(options => { options.Model = OpenAIModels.Gpt35Turbo; }) // ...create using delegate
. WithModel ( Aspose . Pdf . AI . OpenAIModels . Gpt35Turbo ) // Configure other optional parameters
. WithTemperature ( 0.5 )
. WithTopP ( 1 )
//.WithContextBackupJsonPath("ContextBackup.json") // Supply context backup to resume the conversation session
//.WithRestoreContextFromBackup(true) // If set to true, the context will be restored
. WithDocument ( dataDir + "SampleDocument.pdf" ); // Attach documents using .WithDocument(s) methods allows to add text, pdf and paths to documents
// Create summary copilot
Aspose . Pdf . AI . IChatCopilot chatCopilot = Aspose . Pdf . AI . AICopilotFactory . CreateChatCopilot ( openAiClient , options );
// Get response on a user query
string copilotResponse1 = await chatCopilot . GetResponseAsync ( "Summarize this document." );
// Get response on a list of queries
string copilotResponse2 = await chatCopilot . GetResponseAsync ( new List < string >
{
"What is the subject of this document?" ,
"How many words in it?"
});
// Save PDF document
await chatCopilot . SaveResponseAsync ( "Summarize this document." , dataDir + "ResponseDocument1_out.pdf" );
// Save PDF document
await chatCopilot . SaveResponseAsync ( new List < string >
{
"What is the subject of this document?" ,
"How many words in it?"
},
dataDir + "ResponseDocument2_out.pdf" );
// Save context (ids of assistant, thread, documents)
await chatCopilot . SaveContextAsync ( dataDir + "ContextBackup.json" );
// Deletes the context
await chatCopilot . DeleteContextAsync ();
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static async Task ChatWithDocument ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_AI ();
// Create AI client
using var openAiClient = Aspose . Pdf . AI . OpenAIClient
. CreateWithApiKey ( ApiKey ) // Create OpenAI client with the API key
//.WithProject("proj_123") // Configure optional parameters
//.WithOrganization("org_123")
. Build (); // Build
// Create copilot options
var options = Aspose . Pdf . AI . OpenAIChatCopilotOptions
. Create () // Create options like this, or...
//.Create(options => { options.Model = OpenAIModels.Gpt35Turbo; }) // ...create using delegate
. WithModel ( Aspose . Pdf . AI . OpenAIModels . Gpt35Turbo ) // Configure other optional parameters
. WithTemperature ( 0.5 )
. WithTopP ( 1 )
//.WithContextBackupJsonPath("ContextBackup.json") // Supply context backup to resume the conversation session
//.WithRestoreContextFromBackup(true) // If set to true, the context will be restored
. WithDocument ( dataDir + "SampleDocument.pdf" ); // Attach documents using .WithDocument(s) methods allows to add text, pdf and paths to documents
// Create summary copilot
Aspose . Pdf . AI . IChatCopilot chatCopilot = Aspose . Pdf . AI . AICopilotFactory . CreateChatCopilot ( openAiClient , options );
// Get response on a user query
string copilotResponse1 = await chatCopilot . GetResponseAsync ( "Summarize this document." );
// Get response on a list of queries
string copilotResponse2 = await chatCopilot . GetResponseAsync ( new List < string >
{
"What is the subject of this document?" ,
"How many words in it?"
});
// Save summary as PDF document
await chatCopilot . SaveResponseAsync ( "Summarize this document." , dataDir + "ResponseDocument1_out.pdf" );
// Save summary as PDF document
await chatCopilot . SaveResponseAsync ( new List < string >
{
"What is the subject of this document?" ,
"How many words in it?"
},
dataDir + "ResponseDocument2_out.pdf" );
// Save context (ids of assistant, thread, documents)
await chatCopilot . SaveContextAsync ( dataDir + "ContextBackup.json" );
// Deletes the context
await chatCopilot . DeleteContextAsync ();
}
OpenAI Image Description adalah copilot AI yang dirancang untuk menghasilkan deskripsi gambar dari gambar di dalam dokumen PDF serta file gambar terpisah. Pengguna dapat mengonfigurasi opsi copilot, seperti model, suhu, jumlah token, instruksi model, lampiran dokumen, dan lainnya. Copilot memberikan kemampuan untuk mendapatkan deskripsi gambar untuk semua dokumen yang dilampirkan sekaligus.
Potongan kode yang disediakan menunjukkan pembuatan klien OpenAI, konfigurasi opsi ImageDescriptionCopilot, dan penggunaan copilot untuk memperoleh deskripsi gambar untuk dokumen yang dilampirkan. Selain itu, ada metode ekstensi yang memungkinkan menambahkan deskripsi gambar ke gambar dalam dokumen yang dilampirkan dan menyimpan dokumen baru di direktori yang disediakan.
OpenAI OCR adalah copilot AI yang dirancang untuk mengekstrak teks dari dokumen dan gambar yang dipindai. Pengguna dapat mengonfigurasi opsi copilot, seperti model, suhu, jumlah token, instruksi model, lampiran dokumen, dan lainnya.
Potongan kode yang disediakan menunjukkan pembuatan klien OpenAI, konfigurasi opsi OpenAIOcrCopilotOptions
, dan penggunaan copilot untuk memperoleh teks dari dokumen dan gambar yang dipindai.
Llama Chat memungkinkan pembuatan klien untuk mengirim permintaan ke API penyelesaian obrolan Llama.
Llama Summary memungkinkan klien digunakan untuk membuat Summary Copilot.
.NET Core 3.1
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static async Task GenerateSummary ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_AI ();
using ( var llamaClient = Aspose . Pdf . AI . LlamaClient
. CreateWithApiKey ( ApiKey ) // Create Llama client with the API key
. Build ())
{
// Create copilot options
var options = Aspose . Pdf . AI . LlamaSummaryCopilotOptions
. Create () // Create options like this, or...
//.Create(options => { options.Model = LlamaModels.Llama13BChat; }) // ...create using delegate
. WithTemperature ( 0.5 ) // Configure other optional parameters
. WithDocument ( dataDir + "SampleDocument.pdf" ); // .WithDocument methods allow to add text, pdf, and paths to documents
//.WithDocuments(new List<Aspose.Pdf.AI.TextDocument> { new Aspose.Pdf.AI.TextDocument() }); // .WithDocuments methods allow to add text, pdf and path collections
// Create summary copilot
var summaryCopilot = Aspose . Pdf . AI . AICopilotFactory . CreateSummaryCopilot ( llamaClient , options );
// Get summary text
string summaryText = await summaryCopilot . GetSummaryAsync ();
// Get summary document
Aspose . Pdf . Document summaryDocument = await summaryCopilot . GetSummaryDocumentAsync ();
// Get the summary document with page info
Aspose . Pdf . Document summaryDocumentWithPageInfo = await summaryCopilot . GetSummaryDocumentAsync ( new Aspose . Pdf . PageInfo ());
// Save the summary as a PDF document
await summaryCopilot . SaveSummaryAsync ( dataDir + "Llama_out.pdf" );
// Save summary with specified format
await summaryCopilot . SaveSummaryAsync ( dataDir + "Llama_out.docx" , Aspose . Pdf . SaveFormat . DocX );
}
}
.NET 8
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static async Task GenerateSummary ()
{
// The path to the documents directory
var dataDir = RunExamples . GetDataDir_AsposePdf_AI ();
using var llamaClient = Aspose . Pdf . AI . LlamaClient
. CreateWithApiKey ( ApiKey ) // Create Llama client with the API key
. Build ();
// Create copilot options
var options = Aspose . Pdf . AI . LlamaSummaryCopilotOptions
. Create () // Create options like this, or...
//.Create(options => { options.Model = LlamaModels.Llama13BChat; }) // ...create using delegate
. WithTemperature ( 0.5 ) // Configure other optional parameters
. WithDocument ( dataDir + "SampleDocument.pdf" ); // .WithDocument methods allow to add text, pdf, and paths to documents
//.WithDocuments(new List<Aspose.Pdf.AI.TextDocument> { new Aspose.Pdf.AI.TextDocument() }); // .WithDocuments methods allow to add text, pdf and path collections
// Create summary copilot
var summaryCopilot = Aspose . Pdf . AI . AICopilotFactory . CreateSummaryCopilot ( llamaClient , options );
// Get summary text
string summaryText = await summaryCopilot . GetSummaryAsync ();
// Get summary document
Aspose . Pdf . Document summaryDocument = await summaryCopilot . GetSummaryDocumentAsync ();
// Get the summary document with page info
Aspose . Pdf . Document summaryDocumentWithPageInfo = await summaryCopilot . GetSummaryDocumentAsync ( new Aspose . Pdf . PageInfo ());
// Save the summary as a PDF document
await summaryCopilot . SaveSummaryAsync ( dataDir + "Llama_out.pdf" );
// Save summary with specified format
await summaryCopilot . SaveSummaryAsync ( dataDir + "Llama_out.docx" , Aspose . Pdf . SaveFormat . DocX );
}