From 930355a53ef7d65836281633beb3a580d1aa453d Mon Sep 17 00:00:00 2001 From: "redev.rx" Date: Thu, 1 Feb 2024 15:45:44 +0700 Subject: [PATCH] add new docs --- README.md | 202 ++++++++++++++---- example/lib/main.dart | 17 +- lib/chat_gpt_sdk.dart | 3 +- lib/src/edit.dart | 2 +- .../model/audio/request/audio_request.dart | 4 +- lib/src/model/file/request/upload_file.dart | 4 +- .../{edit_file.dart => file_info.dart} | 8 +- .../model/gen_image/request/variation.dart | 4 +- .../audio/request/audio_request_test.dart | 8 +- test/model/file/request/upload_file_test.dart | 2 +- .../gen_image/request/edit_file_test.dart | 4 +- .../gen_image/request/variation_test.dart | 4 +- test/openai_test.dart | 50 ++--- test/openai_test.mocks.dart | 2 +- 14 files changed, 208 insertions(+), 106 deletions(-) rename lib/src/model/gen_image/request/{edit_file.dart => file_info.dart} (96%) diff --git a/README.md b/README.md index fd1173c..daa4c49 100644 --- a/README.md +++ b/README.md @@ -43,26 +43,56 @@ supervised and reinforcement learning techniques. - [x] [Create OpenAI Instance](#create-openai-instance) - [x] [Change Access Token](#change-access-token) - [x] [Complete Text](#complete-text) - - Support Server Sent Event + - [Complete with Future](#Complete-with-feature) + - [Support Server Sent Event](#gpt-3-with-sse) - [x] [Chat Complete GPT-4](#chat-complete-gpt-4-and-gpt-35) - - Support GPT3.5 and GPT-4 - - Support Server Sent Event - - Support Function Calling + - [Support GPT3.5 and GPT-4](#chat-complete) + - [Support Server Sent Event](#gpt-4-with-sse) + - [Support Function Calling](#Chat-Complete-Function-Calling) + - [Chat Complete Image Input](#Chat-Complete-Image-Input) - [x] [Assistants API](#assistants) - - CRUD + - [Create assistant](#create-assistant) + - [Create assistant file](#create-assistant-file) + - [List assistants](#list-assistants) + - [List assistant files](#list-assistants-files) + - [Retrieve assistant](#retrieve-assistant) + - [Retrieve assistant file](#retrieve-assistant-file) + - [Modify assistant](#modify-assistant) + - [Delete assistant](#delete-assistant) + - [Delete assistant file](#delete-assistant-file) - [x] [Error Handle](#error-handle) - [x] [Example Q&A](#qa) - [x] [Generate Image With Prompt](#generate-image-with-prompt) - [x] [Editing](#edit) + - [Edit Prompt](#Edit-Prompt) + - [Edit Image](#Edit-Image) + - [Variations](#Variations) - [x] [Cancel Generate](#cancel-generate) + - [Stop Generate Prompt](#Stop-Generate-Prompt) + - [Stop Edit](#Stop-Edit) + - [Stop Embedding](#Stop-Embedding) - [x] [File](#file) + - [Get File](#Get-File) + - [Upload File](#Upload-File) + - [Delete File](#Delete-File) + - [Retrieve File](#Retrieve-File) + - [Retrieve Content File](#Retrieve-Content-File) - [x] [Audio](#audio) + - [Audio Translate](#Audio-Translate) + - [Audio Transcribe](#Audio-Transcribe) + - [Create speech](#Create-speech) - [x] [Embedding](#embedding) - [x] [Fine-Tune](#fine-tune) - - Support Server Sent Event + - [Create Fine Tune](#Create-Fine-Tune) + - [Fine Tune List](#Fine-Tune-List) + - [Fine Tune List Stream (SSE)](#Fine-Tune-List-Stream) + - [Fine Tune Get by Id](#Fine-Tune-Get-by-Id) + - [Cancel Fine Tune](#Cancel-Fine-Tune) + - [Delete Fine Tune](#Delete-Fine-Tune) - Fine-Tune Deprecate - New Fine-Tune Job -- [x] [Moderations](#modelengine) +- [x] [Moderations](#Moderations) + - [Create Moderation](#Create-Moderation) - [x] [Model And Engine](#modelengine) - [x] [Translate Example](#translate-app) - [x] [Video Tutorial](#video-tutorials) @@ -112,7 +142,7 @@ openAI.token; - Find the time complexity of a function. - https://beta.openai.com/examples -- Complete with Feature +- ### Complete with Feature ```dart void _translateEngToThai() async{ @@ -146,7 +176,7 @@ FutureBuilder( }) ``` -- GPT-3 with SSE +- ### GPT 3 with SSE ```dart void completeWithSSE() { final request = CompleteText( @@ -159,7 +189,7 @@ FutureBuilder( ## Chat Complete (GPT-4 and GPT-3.5) -- GPT-4 +- ### Chat Complete ```dart void chatComplete() async { final request = ChatCompleteText(messages: [ @@ -173,7 +203,7 @@ FutureBuilder( } ``` -- GPT-4 with SSE(Server Send Event) +- ### GPT 4 with SSE ```dart void chatCompleteWithSSE() { final request = ChatCompleteText(messages: [ @@ -214,7 +244,7 @@ FutureBuilder( } ``` -- Chat Complete Function Calling +- ### Chat Complete Function Calling ```dart void gptFunctionCalling() async { @@ -257,7 +287,7 @@ FutureBuilder( } ``` -- Chat Complete Image Input +- ### Chat Complete Image Input ```dart void imageInput() async { @@ -284,7 +314,7 @@ FutureBuilder( ``` ## Assistants -- Create Assistant +- ### Create Assistant ```dart void createAssistant() async { final assistant = Assistant( @@ -303,6 +333,78 @@ FutureBuilder( ``` +- ### Create Assistant File +```dart +void createAssistantFile() async { + await openAI.assistant.createFile(assistantId: '',fileId: '',); +} +``` + +- ### List assistants +```dart + void listAssistant() async { + final assistants = await openAI.assistant.list(); + assistants.map((e) => e.toJson()).forEach(print); +} +``` + +- ### List assistants files +```dart + void listAssistantFile() async { + final assistants = await openAI.assistant.listFile(assistantId: ''); + assistants.data.map((e) => e.toJson()).forEach(print); +} +``` + +- ### Retrieve assistant +```dart + void retrieveAssistant() async { + final assistants = await openAI.assistant.retrieves(assistantId: ''); +} +``` + +- ### Retrieve assistant file +```dart + void retrieveAssistantFiles() async { + final assistants = await openAI.assistant.retrievesFile(assistantId: '',fileId: ''); +} +``` + +- ### Modify assistant +```dart + void modifyAssistant() async { + final assistant = Assistant( + model: Gpt4AModel(), + instructions: + 'You are an HR bot, and you have access to files to answer employee questions about company policies. Always response with info from either of the files.', + tools: [ + { + "type": "retrieval", + } + ], + fileIds: [ + "file-abc123", + "file-abc456", + ], + ); + await openAI.assistant.modifies(assistantId: '', assistant: assistant); +} +``` + +- ### Delete assistant +```dart + void deleteAssistant() async { + await openAI.assistant.delete(assistantId: ''); +} +``` + +- ### Delete assistant file +```dart + void deleteAssistantFile() async { + await openAI.assistant.deleteFile(assistantId: '',fileId: ''); +} +``` + ## Error Handle @@ -377,19 +479,20 @@ A: Human life expectancy in the United States is 78 years. - A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. - -- Generate with feature +- ### Generate with feature ```dart void _generateImage() { const prompt = "cat eating snake blue red."; - final request = GenerateImage(prompt, 1,size: ImageSize.size256, + final request = GenerateImage( model: DallE2(),prompt, 1,size: ImageSize.size256, responseFormat: Format.url); final response = openAI.generateImage(request); print("img url :${response.data?.last?.url}"); } ``` + ## Edit -- Edit Prompt +- ### Edit Prompt ```dart void editPrompt() async { final response = await openAI.editor.prompt(EditRequest( @@ -401,24 +504,25 @@ void editPrompt() async { } ``` -- Edit Image +- ### Edit Image ```dart void editImage() async { final response = await openAI.editor.editImage(EditImageRequest( - image: EditFile("${image?.path}", '${image?.name}'), - mask: EditFile('file path', 'file name'), + image: FileInfo("${image?.path}", '${image?.name}'), + mask: FileInfo('file path', 'file name'), size: ImageSize.size1024, - prompt: 'King Snake')); + prompt: 'King Snake'), + model: DallE3(),); print(response.data?.last?.url); } ``` -- Variations +- ### Variations ```dart void variation() async { final request = - Variation(image: EditFile('${image?.path}', '${image?.name}')); + Variation(model: DallE2(),image: FileInfo('${image?.path}', '${image?.name}')); final response = await openAI.editor.variation(request); print(response.data?.last?.url); @@ -426,7 +530,7 @@ void editPrompt() async { ``` ## Cancel Generate -- Stop Generate Prompt +- ### Stop Generate Prompt ```dart _openAI .onChatCompletionSSE(request: request, onCancel: onCancel); @@ -440,7 +544,7 @@ void onCancel(CancelData cancelData) { mCancel?.cancelToken.cancel("canceled "); ``` -- Stop Edit +- ### Stop Edit - image - prompt ```dart @@ -455,7 +559,7 @@ void onCancel(CancelData cancelData) { mCancel?.cancelToken.cancel("canceled edit image"); ``` -- Stop Embedding +- ### Stop Embedding ```dart openAI.embed.embedding(request,onCancel: onCancel); @@ -501,7 +605,7 @@ mCancel?.cancelToken.cancel("canceled uploadFile"); ## File -- Get File +- ### Get File ```dart void getFile() async { final response = await openAI.file.get(); @@ -509,16 +613,16 @@ void getFile() async { } ``` -- Upload File +- ### Upload File ```dart void uploadFile() async { - final request = UploadFile(file: EditFile('file-path', 'file-name'),purpose: 'fine-tune'); + final request = UploadFile(file: FileInfo('file-path', 'file-name'),purpose: 'fine-tune'); final response = await openAI.file.uploadFile(request); print(response); } ``` -- Delete File +- ### Delete File ```dart void delete() async { final response = await openAI.file.delete("file-Id"); @@ -526,7 +630,7 @@ void uploadFile() async { } ``` -- Retrieve File +- ### Retrieve File ```dart void retrieve() async { final response = await openAI.file.retrieve("file-Id"); @@ -534,7 +638,7 @@ void uploadFile() async { } ``` -- Retrieve Content File +- ### Retrieve Content File ```dart void retrieveContent() async { final response = await openAI.file.retrieveContent("file-Id"); @@ -544,27 +648,39 @@ void uploadFile() async { ## Audio -- Audio Translate +- ### Audio Translate ```dart void audioTranslate() async { final mAudio = File('mp3-path'); final request = - AudioRequest(file: EditFile(mAudio.path, 'name'), prompt: '...'); + AudioRequest(file: FileInfo(mAudio.path, 'name'), prompt: '...'); final response = await openAI.audio.translate(request); } ``` -- Audio Transcribe +- ### Audio Transcribe ```dart void audioTranscribe() async { final mAudio = File('mp3-path'); final request = - AudioRequest(file: EditFile(mAudio.path, 'name'), prompt: '...'); + AudioRequest(file: FileInfo(mAudio.path, 'name'), prompt: '...'); final response = await openAI.audio.transcribes(request); } ``` + +- ### Create speech +```dart + void createSpeech() async { + final request = SpeechRequest( + model: 'tts-1', input: 'The quick brown fox jumped over the lazy dog.'); + + final response = await openAI.audio + .createSpeech(request: request, fileName: '', savePath: ''); +} +``` + ## Embedding - Embedding @@ -582,7 +698,7 @@ void embedding() async { ## Fine Tune -- Create Fine Tune +- ### Create Fine Tune ```dart void createTineTune() async { final request = CreateFineTuneJob(trainingFile: 'The ID of an uploaded file'); @@ -590,14 +706,14 @@ void createTineTune() async { } ``` -- Fine Tune List +- ### Fine Tune List ```dart void tineTuneList() async { final response = await openAI.fineTune.listFineTuneJob(); } ``` -- Fine Tune List Stream (SSE) +- ### Fine Tune List Stream ```dart void tineTuneListStream() { openAI.fineTune.listFineTuneJobStream('fineTuneId').listen((it) { @@ -606,21 +722,21 @@ void createTineTune() async { } ``` -- Fine Tune Get by Id +- ### Fine Tune Get by Id ```dart void tineTuneById() async { final response = await openAI.fineTune.retrieveFineTuneJob('fineTuneId'); } ``` -- Cancel Fine Tune +- ### Cancel Fine Tune ```dart void tineTuneCancel() async { final response = await openAI.fineTune.cancel('fineTuneId'); } ``` -- Delete Fine Tune +- ### Delete Fine Tune ```dart void deleteTineTune() async { final response = await openAI.fineTune.delete('model'); @@ -629,7 +745,7 @@ void tineTuneById() async { ## Moderations -- Create Moderation +- ### Create Moderation ```dart void createModeration() async { final response = await openAI.moderation diff --git a/example/lib/main.dart b/example/lib/main.dart index 185c02d..e8f6083 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -116,22 +116,7 @@ class _TranslateScreenState extends State { await openAI.onChatCompletion(request: request); } - - void createAssistant() async { - final assistant = Assistant( - model: Gpt4AModel(), - name: 'Math Tutor', - instructions: - 'You are a personal math tutor. When asked a question, write and run Python code to answer the question.', - tools: [ - { - "type": "code_interpreter", - } - ], - ); - await openAI.assistant.create(assistant: assistant); - } - + @override void initState() { openAI = OpenAI.instance.build( diff --git a/lib/chat_gpt_sdk.dart b/lib/chat_gpt_sdk.dart index bf74f49..c2812b8 100644 --- a/lib/chat_gpt_sdk.dart +++ b/lib/chat_gpt_sdk.dart @@ -13,7 +13,7 @@ export 'src/model/chat_complete/request/chat_complete_text.dart'; export 'src/model/chat_complete/response/chat_ct_response.dart'; export 'src/model/edits/request/edit_request.dart'; export 'src/model/edits/response/edit_response.dart'; -export 'src/model/gen_image/request/edit_file.dart'; +export 'src/model/gen_image/request/file_info.dart'; export 'src/model/gen_image/request/variation.dart'; export 'src/model/embedding/request/embed_request.dart'; export 'src/model/embedding/response/embed_data.dart'; @@ -70,3 +70,4 @@ export 'src/model/run/response/create_thread_and_run_data.dart'; export 'src/model/run/response/list_run.dart'; export 'src/model/run/response/message_creation.dart'; export 'src/model/run/response/step_detail.dart'; +export 'src/model/audio/request/speech_request.dart'; diff --git a/lib/src/edit.dart b/lib/src/edit.dart index 320adfc..707954d 100644 --- a/lib/src/edit.dart +++ b/lib/src/edit.dart @@ -1,7 +1,7 @@ import 'package:chat_gpt_sdk/src/model/cancel/cancel_data.dart'; import 'package:chat_gpt_sdk/src/model/edits/request/edit_request.dart'; import 'package:chat_gpt_sdk/src/model/edits/response/edit_response.dart'; -import 'package:chat_gpt_sdk/src/model/gen_image/request/edit_file.dart'; +import 'package:chat_gpt_sdk/src/model/gen_image/request/file_info.dart'; import 'package:chat_gpt_sdk/src/model/gen_image/response/gen_img_response.dart'; import 'package:chat_gpt_sdk/src/utils/constants.dart'; diff --git a/lib/src/model/audio/request/audio_request.dart b/lib/src/model/audio/request/audio_request.dart index aa1bd40..c7c34a8 100644 --- a/lib/src/model/audio/request/audio_request.dart +++ b/lib/src/model/audio/request/audio_request.dart @@ -1,14 +1,14 @@ import 'dart:io'; import 'package:chat_gpt_sdk/src/model/audio/enum/audio_format.dart'; -import 'package:chat_gpt_sdk/src/model/gen_image/request/edit_file.dart'; +import 'package:chat_gpt_sdk/src/model/gen_image/request/file_info.dart'; import 'package:dio/dio.dart'; class AudioRequest { ///The audio file to transcribe, in one of /// these formats: mp3, mp4, mpeg, mpga, /// m4a, wav, or webm.[file] - final EditFile file; + final FileInfo file; ///The language of the input audio. /// Supplying the input language in diff --git a/lib/src/model/file/request/upload_file.dart b/lib/src/model/file/request/upload_file.dart index 857a188..9f7912c 100644 --- a/lib/src/model/file/request/upload_file.dart +++ b/lib/src/model/file/request/upload_file.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:chat_gpt_sdk/src/model/gen_image/request/edit_file.dart'; +import 'package:chat_gpt_sdk/src/model/gen_image/request/file_info.dart'; import 'package:dio/dio.dart'; class UploadFile { @@ -8,7 +8,7 @@ class UploadFile { ///If the is set to "fine-tune", ///each line is a JSON record with "prompt" and "completion" /// fields representing your training examples.purpose. [file] - final EditFile file; + final FileInfo file; ///The intended purpose of the uploaded documents. ///Use "fine-tune" for Fine-tuning. diff --git a/lib/src/model/gen_image/request/edit_file.dart b/lib/src/model/gen_image/request/file_info.dart similarity index 96% rename from lib/src/model/gen_image/request/edit_file.dart rename to lib/src/model/gen_image/request/file_info.dart index 26bdc7a..e26e338 100644 --- a/lib/src/model/gen_image/request/edit_file.dart +++ b/lib/src/model/gen_image/request/file_info.dart @@ -5,11 +5,11 @@ import 'package:chat_gpt_sdk/src/model/gen_image/enum/image_size.dart'; import 'package:dio/dio.dart'; import 'package:http_parser/http_parser.dart'; -class EditFile { +class FileInfo { final String path; final String name; - EditFile(this.path, this.name); + FileInfo(this.path, this.name); @override String toString() => "[$path,$name]"; @@ -20,14 +20,14 @@ class EditImageRequest { /// and square. If mask is not provided, image must have transparency, /// which will be used as the mask.[image] /// file name is image - final EditFile image; + final FileInfo image; ///An additional image whose fully transparent areas /// (e.g. where alpha is zero) indicate where should be edited. /// Must be a valid PNG file, less than 4MB, and have /// the same dimensions as image. [mask] /// file name is mask - final EditFile? mask; + final FileInfo? mask; ///A text description of the desired image(s). /// The maximum length is 1000 characters.[prompt] diff --git a/lib/src/model/gen_image/request/variation.dart b/lib/src/model/gen_image/request/variation.dart index 503c9cf..71b1544 100644 --- a/lib/src/model/gen_image/request/variation.dart +++ b/lib/src/model/gen_image/request/variation.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:chat_gpt_sdk/src/model/gen_image/enum/format.dart'; import 'package:chat_gpt_sdk/src/model/gen_image/enum/image_size.dart'; -import 'package:chat_gpt_sdk/src/model/gen_image/request/edit_file.dart'; +import 'package:chat_gpt_sdk/src/model/gen_image/request/file_info.dart'; import 'package:dio/dio.dart'; import 'package:http_parser/http_parser.dart'; @@ -11,7 +11,7 @@ class Variation { /// and square. If mask is not provided, image must have transparency, /// which will be used as the mask.[image] /// file name is image - final EditFile image; + final FileInfo image; ///The number of images to generate. Must be between 1 and 10.[n] final int n; diff --git a/test/model/audio/request/audio_request_test.dart b/test/model/audio/request/audio_request_test.dart index d4bd8b8..6972c63 100644 --- a/test/model/audio/request/audio_request_test.dart +++ b/test/model/audio/request/audio_request_test.dart @@ -6,7 +6,7 @@ import 'package:test/test.dart'; void main() { group('audio request test', () { test('audio request test set edit file', () { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); expect(request.file.name, 'name'); expect(request.file.path, 'path'); @@ -14,7 +14,7 @@ void main() { }); test('audio request test set language', () { final request = - AudioRequest(file: EditFile("path", "name"), language: "en"); + AudioRequest(file: FileInfo("path", "name"), language: "en"); expect(request.file.name, 'name'); expect(request.file.path, 'path'); @@ -23,7 +23,7 @@ void main() { }); test('audio request test set format', () { final request = AudioRequest( - file: EditFile("path", "name"), + file: FileInfo("path", "name"), language: "en", responseFormat: AudioFormat.verboseJson, ); @@ -36,7 +36,7 @@ void main() { }); test('audio request test set temperature', () { final request = AudioRequest( - file: EditFile("path", "name"), + file: FileInfo("path", "name"), language: "en", responseFormat: AudioFormat.verboseJson, temperature: 1, diff --git a/test/model/file/request/upload_file_test.dart b/test/model/file/request/upload_file_test.dart index e73d099..484d8d3 100644 --- a/test/model/file/request/upload_file_test.dart +++ b/test/model/file/request/upload_file_test.dart @@ -5,7 +5,7 @@ import 'package:test/test.dart'; void main() { group('upload file test', () { test('upload file test get from', () { - final upload = UploadFile(file: EditFile("path", 'name')); + final upload = UploadFile(file: FileInfo("path", 'name')); expect(upload.getForm(), isA>()); }); diff --git a/test/model/gen_image/request/edit_file_test.dart b/test/model/gen_image/request/edit_file_test.dart index 9769648..0d59a28 100644 --- a/test/model/gen_image/request/edit_file_test.dart +++ b/test/model/gen_image/request/edit_file_test.dart @@ -5,7 +5,7 @@ import 'package:test/test.dart'; void main() { group('edit file test', () { test('edit file test', () async { - final e = EditFile('path', 'name'); + final e = FileInfo('path', 'name'); final edit = await EditImageRequest( image: e, prompt: 'prompt', @@ -21,7 +21,7 @@ void main() { }); test('edit file test', () { - final e = EditFile('path', 'name'); + final e = FileInfo('path', 'name'); e.toString(); final json = EditImageRequest( image: e, diff --git a/test/model/gen_image/request/variation_test.dart b/test/model/gen_image/request/variation_test.dart index bd74f04..123e03c 100644 --- a/test/model/gen_image/request/variation_test.dart +++ b/test/model/gen_image/request/variation_test.dart @@ -6,7 +6,7 @@ void main() { group('variation test', () { test('variation test from json', () async { final variation = await Variation( - image: EditFile('path', 'name'), + image: FileInfo('path', 'name'), size: ImageSize.size1024, responseFormat: Format.url, user: 'user', @@ -17,7 +17,7 @@ void main() { }); test('variation test to json', () { final json = Variation( - image: EditFile('path', 'name'), + image: FileInfo('path', 'name'), size: ImageSize.size1024, responseFormat: Format.url, user: 'user', diff --git a/test/openai_test.dart b/test/openai_test.dart index 460a99b..ce76041 100644 --- a/test/openai_test.dart +++ b/test/openai_test.dart @@ -90,14 +90,14 @@ void main() async { ); expect( () => ai.editor.editImage(EditImageRequest( - image: EditFile('path', 'name'), + image: FileInfo('path', 'name'), prompt: 'prompt', )), throwsException, ); expect( () => ai.editor.variation( - Variation(image: EditFile('path', 'name'), user: 'prompt'), + Variation(image: FileInfo('path', 'name'), user: 'prompt'), ), throwsException, ); @@ -137,15 +137,15 @@ void main() async { expect(() => ai.file.delete('fileId'), throwsException); expect(() => ai.file.retrieveContent('fileId'), throwsException); expect( - () => ai.file.uploadFile(UploadFile(file: EditFile('path', 'name'))), + () => ai.file.uploadFile(UploadFile(file: FileInfo('path', 'name'))), throwsException, ); expect( - () => ai.audio.translate(AudioRequest(file: EditFile('path', 'name'))), + () => ai.audio.translate(AudioRequest(file: FileInfo('path', 'name'))), throwsException, ); expect( - () => ai.audio.transcribes(AudioRequest(file: EditFile('path', 'name'))), + () => ai.audio.transcribes(AudioRequest(file: FileInfo('path', 'name'))), throwsException, ); expect( @@ -867,7 +867,7 @@ void main() async { group('chatGPT audio test', () { test('ChatGPT audio transcribes test with success case', () { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.transcribes(request)) .thenAnswer((realInvocation) async => AudioResponse("text")); @@ -877,7 +877,7 @@ void main() async { }); }); test('ChatGPT audio transcribes test cancel with success case', () { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.transcribes(request)) .thenAnswer((realInvocation) async => AudioResponse("text")); @@ -889,7 +889,7 @@ void main() async { test( 'ChatGPT audio transcribes test with unauthenticated error case', () async { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.transcribes(request)).thenThrow(OpenAIAuthError()); verifyNever(await audio.transcribes(request)); @@ -900,7 +900,7 @@ void main() async { }, ); test('ChatGPT audio transcribes test with rate limit error case', () async { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.transcribes(request)).thenThrow(OpenAIRateLimitError()); verifyNever(await audio.transcribes(request)); @@ -910,7 +910,7 @@ void main() async { ); }); test('ChatGPT audio transcribes test with rate limit error case', () async { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.transcribes(request)).thenThrow(OpenAIServerError()); verifyNever(await audio.transcribes(request)); @@ -921,7 +921,7 @@ void main() async { }); test('ChatGPT audio translate test cancel with success case', () { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.translate(request)) .thenAnswer((realInvocation) async => AudioResponse("text")); @@ -931,7 +931,7 @@ void main() async { }); }); test('ChatGPT audio translate test with success case', () { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.translate(request)) .thenAnswer((realInvocation) async => AudioResponse("text")); @@ -943,7 +943,7 @@ void main() async { test( 'ChatGPT audio translate test with unauthenticated error case', () async { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.translate(request)).thenThrow(OpenAIAuthError()); verifyNever(await audio.translate(request)); @@ -951,7 +951,7 @@ void main() async { }, ); test('ChatGPT audio translate test with rate limit error case', () async { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.translate(request)).thenThrow(OpenAIRateLimitError()); verifyNever(await audio.translate(request)); @@ -961,7 +961,7 @@ void main() async { ); }); test('ChatGPT audio translate test with rate limit error case', () async { - final request = AudioRequest(file: EditFile("path", "name")); + final request = AudioRequest(file: FileInfo("path", "name")); when(audio.translate(request)).thenThrow(OpenAIServerError()); verifyNever(await audio.translate(request)); @@ -972,7 +972,7 @@ void main() async { group('chatGPT edit test', () { test('chatGPT Edit image test with success case', () { final request = EditImageRequest( - image: EditFile("path", "name"), + image: FileInfo("path", "name"), prompt: "fix color", ); when(edit.editImage(request)).thenAnswer((realInvocation) async => @@ -985,7 +985,7 @@ void main() async { }); test('chatGPT Edit image test cancel with success case', () { final request = EditImageRequest( - image: EditFile("path", "name"), + image: FileInfo("path", "name"), prompt: "fix color", ); when(edit.editImage(request)).thenAnswer((realInvocation) async => @@ -998,7 +998,7 @@ void main() async { }); test('ChatGPT Edit image test with unauthenticated error case', () async { final request = - EditImageRequest(image: EditFile("path", "name"), prompt: "fix body"); + EditImageRequest(image: FileInfo("path", "name"), prompt: "fix body"); when(edit.editImage(request)).thenThrow(OpenAIAuthError()); verifyNever(await edit.editImage(request)); @@ -1006,7 +1006,7 @@ void main() async { }); test('ChatGPT Edit image test with rate limit error case', () async { final request = EditImageRequest( - image: EditFile("path", "name"), + image: FileInfo("path", "name"), prompt: "fix color body", ); when(edit.editImage(request)).thenThrow(OpenAIRateLimitError()); @@ -1019,7 +1019,7 @@ void main() async { }); test('ChatGPT Edit image test with rate limit error case', () async { final request = - EditImageRequest(image: EditFile("path", "name"), prompt: "fix"); + EditImageRequest(image: FileInfo("path", "name"), prompt: "fix"); when(edit.editImage(request)).thenThrow(OpenAIServerError()); verifyNever(await edit.editImage(request)); @@ -1112,7 +1112,7 @@ void main() async { }); test('chatGPT edit variation test with success case', () { - final request = Variation(image: EditFile("path file", 'file name')); + final request = Variation(image: FileInfo("path file", 'file name')); when(edit.variation(request)).thenAnswer((realInvocation) async => GenImgResponse(created: 1, data: [ImageData(url: "image url")])); @@ -1122,7 +1122,7 @@ void main() async { }); }); test('chatGPT edit variation test cancel with success case', () { - final request = Variation(image: EditFile("path file", 'file name')); + final request = Variation(image: FileInfo("path file", 'file name')); when(edit.variation(request)).thenAnswer((realInvocation) async => GenImgResponse(created: 1, data: [ImageData(url: "image url")])); @@ -1136,14 +1136,14 @@ void main() async { ); }); test('ChatGPT Edit prompt test with unauthenticated error case', () async { - final request = Variation(image: EditFile("path file", 'file name')); + final request = Variation(image: FileInfo("path file", 'file name')); when(edit.variation(request)).thenThrow(OpenAIAuthError()); verifyNever(await edit.variation(request)); expect(() => edit.variation(request), throwsA(isA())); }); test('ChatGPT Edit prompt test with rate limit error case', () async { - final request = Variation(image: EditFile("path file", 'file name')); + final request = Variation(image: FileInfo("path file", 'file name')); when(edit.variation(request)).thenThrow(OpenAIRateLimitError()); verifyNever(await edit.variation(request)); @@ -1153,7 +1153,7 @@ void main() async { ); }); test('ChatGPT Edit prompt test with rate limit error case', () async { - final request = Variation(image: EditFile("path file", 'file name')); + final request = Variation(image: FileInfo("path file", 'file name')); when(edit.variation(request)).thenThrow(OpenAIServerError()); verifyNever(await edit.variation(request)); diff --git a/test/openai_test.mocks.dart b/test/openai_test.mocks.dart index f7ee889..52ba34c 100644 --- a/test/openai_test.mocks.dart +++ b/test/openai_test.mocks.dart @@ -51,7 +51,7 @@ import 'package:chat_gpt_sdk/src/model/fine_tune/response/job/fine_tune_list.dar as _i19; import 'package:chat_gpt_sdk/src/model/fine_tune/response/job/fine_tune_model_job.dart' as _i18; -import 'package:chat_gpt_sdk/src/model/gen_image/request/edit_file.dart' +import 'package:chat_gpt_sdk/src/model/gen_image/request/file_info.dart' as _i36; import 'package:chat_gpt_sdk/src/model/gen_image/request/generate_image.dart' as _i32;