مكتبة بسيطة للوزن الخفيف التي تلتف واجهة برمجة تطبيقات AI المفتوحة بدعم من حقن التبعية.
تتضمن الميزات المدعومة:
للحصول على تجول في مقطع فيديو لتطبيق ويب Blazor مبني على هذه المكتبة ، يرجى الاطلاع على:
يتم نشر هذا على صفحات github ومتاح على: افتح AI UI. مصدر لتطبيق ويب Blazor في whetstone.chatgpt.blazor.app.
تشمل الأمثلة:
services . Configure < ChatGPTCredentials > ( options =>
{
options . ApiKey = " YOURAPIKEY " ;
options . Organization = " YOURORGANIZATIONID " ;
} ) ;يستخدم:
services . AddHttpClient ( ) ;أو:
services . AddHttpClient < IChatGPTClient , ChatGPTClient > ( ) ; تكوين خدمة IChatGPTClient :
services . AddScoped < IChatGPTClient , ChatGPTClient > ( ) ; إكمال الدردشة هي نوع خاص من الانتهاء تم تحسينه للدردشة. وهي مصممة لاستخدامها في سياق المحادثة.
هذا يدل على استخدام نموذج GPT-3.5 Turbo.
using Whetstone . ChatGPT ;
using Whetstone . ChatGPT . Models ;
. . .
var gptRequest = new ChatGPTChatCompletionRequest
{
Model = ChatGPT35Models . Turbo ,
Messages = new List < ChatGPTChatCompletionMessage > ( )
{
new ChatGPTChatCompletionMessage ( ChatGPTMessageRoles . System , " You are a helpful assistant. " ) ,
new ChatGPTChatCompletionMessage ( ChatGPTMessageRoles . User , " Who won the world series in 2020? " ) ,
new ChatGPTChatCompletionMessage ( ChatGPTMessageRoles . Assistant , " The Los Angeles Dodgers won the World Series in 2020. " ) ,
new ChatGPTChatCompletionMessage ( ChatGPTMessageRoles . User , " Where was it played? " )
} ,
Temperature = 0.9f ,
MaxTokens = 100
} ;
using IChatGPTClient client = new ChatGPTClient ( " YOURAPIKEY " ) ;
var response = await client . CreateChatCompletionAsync ( gptRequest ) ;
Console . WriteLine ( response ? . GetCompletionText ( ) ) ;يمكن أيضًا استخدام نماذج GPT-4 شريطة منح حسابك الوصول إلى الإصدار التجريبي المحدود.
تستخدم الإكمال نماذج للإجابة على مجموعة واسعة من المهام ، بما في ذلك على سبيل المثال لا الحصر ، التصنيف ، تحليل المشاعر ، الإجابة على الأسئلة ، إلخ.
هذا يوضح مستخدمًا مباشرًا لنموذج GPT-3.5-Turbo-instruct دون أي مطالبات.
يرجى ملاحظة أن CreateCompletionAsync عفا عليها الزمن. استخدم chatgptchatcompletionRequest ، و chatgptChatCompletionResponse ، وطريقة CreateChatCompleTionAsync بدلاً من ذلك.
using Whetstone . ChatGPT ;
using Whetstone . ChatGPT . Models ;
. . .
var gptRequest = new ChatGPTCompletionRequest
{
Model = ChatGPT35Models . Gpt35TurboInstruct ,
Prompt = " How is the weather? "
} ;
using IChatGPTClient client = new ChatGPTClient ( " YOURAPIKEY " ) ;
var response = await client . CreateCompletionAsync ( gptRequest ) ;
Console . WriteLine ( response . GetCompletionText ( ) ) ;GPT-3.5 ليست حتمية. تم إرجاع أحد عمليات الاختبار للعينة أعلاه:
يمكن أن يختلف الطقس اختلافًا كبيرًا اعتمادًا على الموقع. بشكل عام ، يمكنك أن تتوقع أن تكون درجات الحرارة معتدلة وأن تكون المناخ مريحة ، ولكن من الأفضل دائمًا التحقق من التوقعات في منطقتك المحددة.
يتوفر تطبيق وحدة التحكم AC# الذي يستخدم الإكمال على:
Whetstone.Chatgpt.CommandlineBot (Chatgpt-Marv)
تتضمن هذه العينة:
كيفية إنشاء ملف توليف دقيق جديد.
List < ChatGPTTurboFineTuneLine > tuningInput = new ( )
{
new ChatGPTTurboFineTuneLine ( )
{
Messages = new List < ChatGPTTurboFineTuneLineMessage > ( )
{
new ( ChatGPTMessageRoles . System , " Marv is a factual chatbot that is also sarcastic. " ) ,
new ( ChatGPTMessageRoles . User , " What's the capital of France? " ) ,
new ( ChatGPTMessageRoles . Assistant , " Paris, as if everyone doesn't know that already. " )
} ,
} ,
new ChatGPTTurboFineTuneLine ( )
{
Messages = new List < ChatGPTTurboFineTuneLineMessage > ( )
{
new ( ChatGPTMessageRoles . System , " Marv is a factual chatbot that is also sarcastic. " ) ,
new ( ChatGPTMessageRoles . User , " Who wrote 'Romeo and Juliet'? " ) ,
new ( ChatGPTMessageRoles . Assistant , " Oh, just some guy named William Shakespeare. Ever heard of him? " )
} ,
} ,
. . .
} ;
byte [ ] tuningText = tuningInput . ToJsonLBinary ( ) ;
string fileName = " marvin.jsonl " ;
ChatGPTUploadFileRequest ? uploadRequest = new ChatGPTUploadFileRequest
{
File = new ChatGPTFileContent
{
FileName = fileName ,
Content = tuningText
}
} ;
ChatGPTFileInfo ? newTurboTestFile ;
using ( IChatGPTClient client = new ChatGPTClient ( " YOURAPIKEY " ) )
{
newTurboTestFile = await client . UploadFileAsync ( uploadRequest ) ;
} بمجرد إنشاء الملف ، احصل على ملف fileID ، ثم الرجوع إليه عند إنشاء ضبط دقيق جديد.
IChatGPTClient client = new ChatGPTClient ( " YOURAPIKEY " ) ;
uploadedFileInfo = await client . UploadFileAsync ( uploadRequest ) ;
var fileList = await client . ListFilesAsync ( ) ;
var foundFile = fileList ? . Data ? . First ( x => x . Filename . Equals ( " marvin.jsonl " ) ) ;
ChatGPTCreateFineTuneRequest tuningRequest = new ChatGPTCreateFineTuneRequest
{
TrainingFileId = foundFile ? . Id ,
Model = " gpt-3.5-turbo-1106 "
} ;
ChatGPTFineTuneJob ? tuneResponse = await client . CreateFineTuneAsync ( tuningRequest ) ;
string ? fineTuneId = tuneResponse ? . Id ;ستستغرق معالجة طلب الضبط الدقيق بعض الوقت. بمجرد الانتهاء من ذلك ، سيتم الإبلاغ عن الحالة "نجح" وهي جاهزة لاستخدامها في طلب الانتهاء.
using IChatGPTClient client = new ChatGPTClient ( " YOURAPIKEY " ) ;
ChatGPTFineTuneJob ? tuneResponse = await client . RetrieveFineTuneAsync ( " FINETUNEID " ) ;
if ( tuneResponse . Status . Equals ( " succeeded " ) )
{
var gptRequest = new ChatGPTChatCompletionRequest
{
Model = " FINETUNEID " ,
Messages = new List < ChatGPTChatCompletionMessage > ( )
{
new ChatGPTChatCompletionMessage ( ChatGPTMessageRoles . System , " You are a helpful assistant. " ) ,
new ChatGPTChatCompletionMessage ( ChatGPTMessageRoles . User , " Who won the world series in 2020? " ) ,
new ChatGPTChatCompletionMessage ( ChatGPTMessageRoles . Assistant , " The Los Angeles Dodgers won the World Series in 2020. " ) ,
new ChatGPTChatCompletionMessage ( ChatGPTMessageRoles . User , " Where was it played? " )
} ,
Temperature = 0.9f ,
MaxTokens = 100
} ;
var response = await client . CreateChatCompletionAsync ( gptRequest ) ;
Console . WriteLine ( response ? . GetCompletionText ( ) ) ; إليك مثال يولد صورة 1024 × 1024.
ChatGPTCreateImageRequest imageRequest = new ( )
{
Prompt = " A sail boat " ,
Size = CreatedImageSize . Size1024 ,
ResponseFormat = CreatedImageFormat . Base64
} ;
using IChatGPTClient client = new ChatGPTClient ( " YOURAPIKEY " ) ;
ChatGPTImageResponse ? imageResponse = await client . CreateImageAsync ( imageRequest ) ;
var imageData = imageResponse ? . Data ? [ 0 ] ;
if ( imageData != null )
{
byte [ ] ? imageBytes = await client . DownloadImageAsync ( imageData ) ;
} مثال عليها ينسخ ملف صوتي باستخدام الهمس.
string audioFile = @"audiofilestranscriptiontest.mp3" ;
byte [ ] fileContents = File . ReadAllBytes ( audioFile ) ;
ChatGPTFileContent gptFile = new ChatGPTFileContent
{
FileName = audioFile ,
Content = fileContents
} ;
ChatGPTAudioTranscriptionRequest ? transcriptionRequest = new ChatGPTAudioTranscriptionRequest
{
File = gptFile
} ;
using IChatGPTClient client = new ChatGPTClient ( " YOURAPIKEY " ) ;
ChatGPTAudioResponse ? audioResponse = await client . CreateTranscriptionAsync ( transcriptionRequest , true ) ;
Console . WriteLine ( audioResponse ? . Text ) ;