Use ChatGPT

الملحق Documentize PDF Manager for .NET هو أداة قوية صممت لدمج واجهة برمجة تطبيقات ChatGPT مع تطبيقات PDF. يتيح هذا الملحق للمطورين إنشاء ردود محادثة بناءً على رسائل الإدخال وحفظ النتيجة بتنسيق PDF، مما يجعله مناسبًا لإنشاء واجهات محادثة أو تقارير تحليلية مباشرة داخل مستندات PDF.

إنشاء ردود محادثة

لإنشاء ردود محادثة وحفظها في ملف PDF باستخدام ملحق ChatGPT، اتبع الخطوات التالية:

  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.

إضافة رسائل النظام والمستخدم

لإنشاء محادثة أكثر تفاعلية، يمكنك إضافة رسائل النظام ورسائل المستخدم. تساعد هذه الرسائل في تشكيل سياق المحادثة.

  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.

الميزات الرئيسية:

  • إكمال الدردشة: إنشاء ردود باستخدام واجهة برمجة تطبيقات ChatGPT بناءً على مدخلات مخصصة.
  • رسائل النظام والمستخدم: تقديم كل من سياق النظام ومدخلات المستخدم لإنشاء محادثات ديناميكية.
  • إخراج PDF: حفظ إكمالات الدردشة التي تم إنشاؤها في ملف PDF منسق للاستخدام لاحقًا.
  • معالجة غير متزامنة: ضمان استجابة التطبيقات عبر معالجة إكمالات الدردشة بشكل غير متزامن.
 عربي