ไลบรารีน้ำหนักเบาที่เรียบง่ายที่ปิด AI API แบบเปิดด้วยการรองรับการฉีดพึ่งพา
คุณสมบัติที่รองรับ ได้แก่ :
สำหรับการแนะนำวิดีโอของแอป Blazor Web ที่สร้างขึ้นบนห้องสมุดนี้โปรดดู:
สิ่งนี้ถูกนำไปใช้กับหน้า GitHub และมีอยู่ที่: เปิด AI UI แหล่งที่มาสำหรับแอป Blazor Web อยู่ที่ 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 > ( ) ; การแชทเสร็จสมบูรณ์เป็นประเภทพิเศษที่ได้รับการปรับให้เหมาะสมสำหรับการแชท พวกเขาได้รับการออกแบบให้ใช้ในบริบทการสนทนา
สิ่งนี้แสดงให้เห็นถึงการใช้งานของรุ่น Turbo GPT-3.5
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 ( ) ) ; นี่คือตัวอย่างที่สร้างภาพ 1024x1024
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 ) ;