هذه هي مكتبة عملاء OpenAI التفاعلية.
تمت كتابته باستخدام WebFlux وSpring Boot. تحتوي المكتبة أيضًا على Spring Boot starter الذي تم تكوينه مسبقًا لتسهيل الاستخدام.
المكتبة غير رسمية ويديرها المجتمع. لا تتردد في الانضمام إلى التنمية.
استيراد التبعية عبر Maven :
< dependency >
< groupId >io.github.reactiveclown</ groupId >
< artifactId >openai-webflux-client-spring-boot-starter</ artifactId >
< version >0.9.1</ version >
</ dependency >
استيراد التبعية عبر Gradle :
implementation 'io.github.reactiveclown:openai-webflux-client-spring-boot-starter:0.9.1'
بعد إضافة التبعية، تذكر إضافة مفتاح OpenAI API الخاص بك إلى application.properties.
com.github.reactiveclown.openai.apiKey =OPENAI_API_KEY
يمكنك أيضًا إضافة معرف المؤسسة وتغيير baseUrl من خلال توفير متغيرات التكوين التالية. لكن هذه الخطوة ليست إلزامية.
com.github.reactiveclown.openai.organizationId =OPENAI_ORGANIZATION_ID
com.github.reactiveclown.openai.baseUrl =OPENAI_CUSTOM_BASE_URL
هنا يمكنك العثور على بعض أمثلة الاستخدام. يرجى أيضًا استخدام الوثائق الرسمية للحصول على مزيد من المعلومات حول المعلمات.
مستندات نماذج OpenAI
يتم استخدام خدمة النماذج لاسترداد قائمة النماذج أو معلومات حول نموذج معين.
@ Service
public class ExampleService {
private final ModelsService service ;
public ExampleService ( ModelsService service ) {
this . service = service ;
}
public Mono < ListModelsResponse > listModels () {
return service . listModels ();
}
public Mono < RetrieveModelResponse > retrieveModel ( String modelName ) {
return service . retrieveModel ( modelName );
}
}
مستندات إكمال OpenAI
يتم استخدام خدمة الإكمال لإكمال النص. لا تتردد في اللعب بمعلمات البناء.
@ Service
public class ExampleService {
private final CompletionsService service ;
public ExampleService ( CompletionsService service ) {
this . service = service ;
}
public Mono < CreateCompletionResponse > createCompletion () {
return service . createCompletion (
CreateCompletionRequest
. builder ( "babbage" )
. n ( 2 )
. bestOf ( 1 )
. build ());
}
}
مستندات الدردشة OpenAI
يتم استخدام خدمة الدردشة للدردشة مع نماذج الدردشة. لا تتردد في اللعب بمعلمات البناء.
@ Service
public class ExampleService {
private final ChatService service ;
public ExampleService ( ChatService service ) {
this . service = service ;
}
public Mono < CreateChatCompletionResponse > createChatCompletion () {
return service . createChatCompletion (
CreateChatCompletionRequest
. builder ( "gpt-3.5-turbo" , List . of ( new MessageData ( "user" , "do something" )))
. n ( 3 )
. build ());
}
}
OpenAI يقوم بتحرير المستندات
يتم استخدام خدمة التحرير لإجراء تعديلات على المدخلات المقدمة. لا تتردد في اللعب بمعلمات البناء.
@ Service
public class ExampleService {
private final EditsService service ;
public ExampleService ( EditsService service ) {
this . service = service ;
}
public Mono < CreateEditResponse > createEdit () {
return service . createEdit (
CreateEditRequest
. builder ( "babbage" , "Add one digit after every word" )
. input ( "One Two Three" )
. build ());
}
}
مستندات صور OpenAI
يتم استخدام خدمة الصور لإنشاء صور مختلفة وتحولاتها.
️ أما الآن، فقد تم حظر الطرق التي تتطلب صورًا. ومن المقرر في المستقبل القريب إضافة تطبيق FilePart غير المتزامن.
@ Service
public class ExampleService {
private final ImagesService service ;
public ExampleService ( ImagesService service ) {
this . service = service ;
}
//Non-blocking
public Mono < CreateImageResponse > createImage () {
return service . createImage (
CreateImageRequest
. builder ( "Generate a digital art of Ukraine" )
. build ());
}
//Blocking
public Mono < CreateImageVariationResponse > createImageVariation () {
return service . createImageVariation (
CreateImageVariationRequest
. builder ( "src/main/resources/exampleImage.png" )
. size ( "512x512" )
. build ());
}
//Blocking
public Mono < CreateImageEditResponse > createImageEdit () {
return service . createImageEdit (
CreateImageEditRequest
. builder ( "src/main/resources/exampleImage.png" , "Generate a green fields" )
. mask ( "src/main/resources/exampleMask.png" )
. build ());
}
}
مستندات تضمين OpenAI
يتم استخدام خدمة التضمين لإنشاء عمليات التضمين. لا تتردد في اللعب بمعلمات البناء.
@ Service
public class ExampleService {
private final EmbeddingsService service ;
public ExampleService ( EmbeddingsService service ) {
this . service = service ;
}
public Mono < CreateEmbeddingsResponse > createEmbeddings (){
return service . createEmbeddings (
CreateEmbeddingsRequest
. builder ( "babbage" , "example input" )
. build ());
}
}
المستندات الصوتية OpenAI
تُستخدم الخدمة الصوتية لتحويل الصوت إلى نص، وكذلك لإجراء ترجمات إلى اللغة الإنجليزية. لا تتردد في اللعب بمعلمات البناء.
️ أما الآن، فقد تم حظر الطرق التي تتطلب ملفات صوتية. ومن المقرر في المستقبل القريب إضافة تطبيق FilePart غير المتزامن.
@ Service
public class ExampleService {
private final AudioService service ;
public ExampleService ( AudioService service ) {
this . service = service ;
}
//Blocking
public Mono < CreateTranscriptionResponse > createTranscription () {
return service . createTranscription (
CreateTranscriptionRequest
. builder ( "src/main/resources/exampleAudio.mp3" , "whisper-1" )
. build ());
}
//Blocking
public Mono < CreateTranslationResponse > createTranslation (){
return service . createTranslation ( CreateTranslationRequest
. builder ( "src/main/resources/exampleAudio.mp3" , "whisper-1" )
. build ());
}
}
مستندات ملفات OpenAI
يتم استخدام خدمة الملفات لتحميل الملفات والعمل معها. لا تتردد في اللعب بمعلمات البناء.
️ أما الآن، فقد تم حظر الطرق التي تتطلب ملفات. ومن المقرر في المستقبل القريب إضافة تطبيق FilePart غير المتزامن.
@ Service
public class ExampleService {
private final FilesService service ;
public ExampleService ( FilesService service ) {
this . service = service ;
}
public Mono < ListFilesResponse > listFilesResponse () {
return service . listFiles ();
}
//Blocking
public Mono < UploadFileResponse > uploadFile () {
return service . uploadFile (
UploadFileRequest
. builder ( "src/main/resources/exampleFile.jsonl" , "finetune" )
. build ());
}
public Mono < DeleteFileResponse > deleteFile () {
return service . deleteFile ( "fileId" );
}
public Mono < RetrieveFileResponse > retrieveFile () {
return service . retrieveFile ( "fileId" );
}
public Mono < String > retrieveFileContent () {
return service . retrieveFileContent ( "fileId" );
}
}
يقوم OpenAI بضبط المستندات
يتم استخدام خدمة الضبط الدقيق للعمل مع الملفات والنماذج الدقيقة. لا تتردد في اللعب بمعلمات البناء.
@ Service
public class ExampleService {
private final FineTunesService service ;
public ExampleService ( FineTunesService service ) {
this . service = service ;
}
public Mono < CreateFineTuneResponse > createFineTune (){
return service . createFineTune (
CreateFineTuneRequest
. builder ( "trainingFileId" )
. build ());
}
public Mono < ListFineTunesResponse > listFineTunes (){
return service . listFineTunes ();
}
public Mono < RetrieveFineTuneResponse > retrieveFineTune (){
return service . retrieveFineTunes ( "fineTuneId" );
}
public Mono < CancelFineTuneResponse > cancelFineTune (){
return service . cancelFineTune ( "fineTuneId" );
}
public Mono < ListFineTuneEventsResponse > listFineTuneEvents (){
return service . listFineTuneEvents ( "fineTuneId" );
}
public Mono < DeleteFineTuneModelResponse > deleteFineTuneModel (){
return service . deleteFineTuneModel ( "modelId" );
}
}
مستندات اعتدال OpenAI
يتم استخدام خدمة الإشراف للتحقق من انتهاكات الإشراف. لا تتردد في اللعب بمعلمات البناء.
@ Service
public class ExampleService {
private final ModerationsService service ;
public ExampleService ( ModerationsService service ) {
this . service = service ;
}
public Mono < CreateModerationResponse > createModeration () {
return service . createModeration (
CreateModerationRequest . builder ( "violating input" ). build ());
}
}
هذه هي المكتبة مفتوحة المصدر، أي مساعدة سيكون موضع تقدير كبير. إذا كنت ترى أن هناك طريقة لتحسين الكود أو الوظيفة، فيرجى ملء المشكلة أو تقديم طلب سحب يتضمن تغييراتك. لا تتردد أيضًا في إلقاء نظرة على المشكلات المفتوحة وإرسال طلب سحب إذا كان لديك الحل.
MIT License
Copyright (c) 2023 Maksym Volkov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.