Skip to content

Commit 8f3266f

Browse files
committed
chore: update audio & images interfaces, examples and client
1 parent 5b574f5 commit 8f3266f

20 files changed

+332
-169
lines changed

endpoints_todo.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ This document tracks the implementation status of all OpenAI API endpoints in th
224224
- [x] **Get Conversation Items** - ✅ Implemented (Custom)
225225
- [x] **Get Conversation Item** - ✅ Implemented (Custom)
226226

227+
### Videos API (Custom)
228+
- [~] None
229+
227230
### Evals API (Custom - Stub Implementation)
228231
- [~] **Create Eval** - ⚠️ Stub Implementation (Throws UnimplementedError)
229232
- [~] **List Evals** - ⚠️ Stub Implementation (Throws UnimplementedError)

example/lib/conversation_get_item_example.dart

Lines changed: 0 additions & 49 deletions
This file was deleted.

example/lib/create_audio_speech.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,27 @@ import 'package:example/env/env.dart';
66
void main() async {
77
OpenAI.apiKey = Env.apiKey;
88

9+
final outputDir = Directory('speechOutput');
10+
11+
final exists = await outputDir.exists();
12+
13+
final input = "I should've been strong";
14+
final model = "tts-1";
15+
final voice = OpenAIAudioVoice.fable;
16+
17+
final fileName = [
18+
model,
19+
DateTime.now().millisecond.toString(),
20+
].join('_');
21+
922
// The speech request.
1023
File speechFile = await OpenAI.instance.audio.createSpeech(
11-
model: "tts-1",
12-
input: "it is what it is.",
13-
voice: OpenAIAudioVoice.nova,
14-
responseFormat: OpenAIAudioSpeechResponseFormat.opus,
15-
outputDirectory: await Directory("speechOutput").create(),
16-
outputFileName: DateTime.now().microsecondsSinceEpoch.toString(),
24+
model: model,
25+
input: input,
26+
voice: voice,
27+
responseFormat: OpenAIAudioSpeechResponseFormat.mp3,
28+
outputDirectory: exists ? outputDir : await outputDir.create(),
29+
outputFileName: fileName,
1730
);
1831

1932
// The file result.

example/lib/create_audio_transcription.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@ Future<void> main() async {
1111
// Set the OpenAI API key from the .env file.
1212
OpenAI.apiKey = Env.apiKey;
1313

14+
final textAudioFile =
15+
"https://www.cbvoiceovers.com/wp-content/uploads/2017/05/Commercial-showreel.mp3";
16+
1417
// create the audio transcription.
1518
final transcription = await OpenAI.instance.audio.createTranscription(
16-
file: await getFileFromUrl(
17-
'https://www.cbvoiceovers.com/wp-content/uploads/2017/05/Commercial-showreel.mp3',
18-
),
1919
model: "whisper-1",
20+
file: await getFileFromUrl(textAudioFile),
21+
include: ["logprobs"],
2022
responseFormat: OpenAIAudioResponseFormat.verbose_json,
21-
timestampGranularities: [OpenAIAudioTimestampGranularity.segment],
23+
language: "en",
24+
prompt: "transcribe this audio with 0.5x speed",
2225
);
2326

24-
// print the transcription.
25-
print(transcription.text);
26-
print(transcription.segments?.map((e) => e.end));
27+
if (transcription is OpenAITranscriptionModel) {
28+
print(transcription.logprobs);
29+
print(transcription.text);
30+
print(transcription.usage);
31+
} else if (transcription is OpenAITranscriptionVerboseModel) {
32+
// print the transcription.
33+
print(transcription.text);
34+
print(transcription.segments?.map((e) => e.end));
35+
}
2736
}
2837

2938
Future<File> getFileFromUrl(String networkUrl) async {

example/lib/create_audio_translation.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ Future<void> main() async {
1212
OpenAI.apiKey = Env.apiKey;
1313

1414
// create the audio transcription.
15-
final translation = await OpenAI.instance.audio.createTranslation(
15+
final translationText = await OpenAI.instance.audio.createTranslation(
1616
file: await getFileFromUrl(
1717
'https://www.cbvoiceovers.com/wp-content/uploads/2017/05/Commercial-showreel.mp3',
1818
fileExtension: "mp3"),
1919
model: "whisper-1",
20+
prompt: "use different english words",
2021
responseFormat: OpenAIAudioResponseFormat.json,
2122
);
2223

2324
// print the translation.
24-
print(translation.text);
25+
print(translationText);
2526
}
2627

2728
Future<File> getFileFromUrl(

example/lib/image_creation.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:dart_openai/dart_openai.dart';
2+
import 'package:example/env/env.dart';
3+
4+
void main() async {
5+
// Set the OpenAI API key from the .env file.
6+
OpenAI.apiKey = Env.apiKey;
7+
8+
// Creates the Image
9+
final images = await OpenAI.instance.image.create(
10+
model: "dall-e-3",
11+
prompt: "image of a cat in a spaceship",
12+
n: 1,
13+
responseFormat: OpenAIImageResponseFormat.url,
14+
size: OpenAIImageSize.size1024,
15+
quality: OpenAIImageQuality.standard,
16+
style: OpenAIImageStyle.vivid,
17+
);
18+
19+
final url = images.data.firstOrNull?.url;
20+
21+
print(url);
22+
}

example/lib/image_edit_example.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import 'package:example/env/env.dart';
66
void main() async {
77
OpenAI.apiKey = Env.apiKey;
88

9-
OpenAIImageModel imageEdits = await OpenAI.instance.image.edit(
9+
final imageEdits = await OpenAI.instance.image.edit(
1010
prompt: 'mask the image with color red',
11-
image: File("IMAGE PATH HERE"),
12-
mask: File("MASK PATH HERE"),
11+
image: File("../whatsapp.png"),
1312
n: 1,
1413
size: OpenAIImageSize.size1024,
1514
responseFormat: OpenAIImageResponseFormat.b64Json,

example/lib/list_all_files.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Future<void> main() async {
77
OpenAI.apiKey = Env.apiKey;
88

99
// List all files.
10-
List<OpenAIFileModel> files = await OpenAI.instance.file.list();
10+
final files = await OpenAI.instance.file.list();
1111

1212
// Print the files.
1313
print(files);

lib/src/core/base/audio/interfaces.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ abstract class CreateInterface {
2626
Directory? outputDirectory,
2727
});
2828

29-
Future<OpenAIAudioModel> createTranscription({
29+
Future<OpenAITranscriptionGeneralModel> createTranscription({
3030
required File file,
3131
required String model,
3232
String? prompt,
@@ -37,7 +37,7 @@ abstract class CreateInterface {
3737
OpenAIAudioChunkingConfig? chunkingStrategy,
3838
});
3939

40-
Future<OpenAIAudioModel> createTranslation({
40+
Future<String> createTranslation({
4141
required File file,
4242
required String model,
4343
String? prompt,

lib/src/core/base/images/base.dart

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:dart_openai/src/core/base/entity/interfaces/enpoint.dart';
22

3-
import '../../enum.dart';
43
import 'interfaces/create.dart';
54
import 'interfaces/edit.dart';
65
import 'interfaces/variations.dart';
@@ -11,57 +10,3 @@ abstract class OpenAIImagesBase
1110
CreateInterface,
1211
EditInterface,
1312
VariationInterface {}
14-
15-
extension SizeToStingExtension on OpenAIImageSize {
16-
String get value {
17-
switch (this) {
18-
case OpenAIImageSize.size256:
19-
return "256x256";
20-
case OpenAIImageSize.size512:
21-
return "512x512";
22-
case OpenAIImageSize.size1024:
23-
return "1024x1024";
24-
case OpenAIImageSize.size1792Horizontal:
25-
return "1792x1024";
26-
case OpenAIImageSize.size1792Vertical:
27-
return "1024x1792";
28-
}
29-
}
30-
}
31-
32-
extension StyleToStingExtension on OpenAIImageStyle {
33-
String get value {
34-
return name;
35-
36-
// ! pretty sure this will be needed in the future in case of adding more styles that can't be got from the `name` field.
37-
// switch (this) {
38-
// case OpenAIImageStyle.vivid:
39-
// return "vivid";
40-
// case OpenAIImageStyle.natural:
41-
// return "natural";
42-
// }
43-
}
44-
}
45-
46-
extension QualityToStingExtension on OpenAIImageQuality {
47-
String get value {
48-
return name;
49-
50-
// ! pretty sure this will be needed in the future in case of adding more qualities that can't be got from the `name` field.
51-
// switch (this) {
52-
// case OpenAIImageQuality.hd:
53-
// return "hd";
54-
// }
55-
}
56-
}
57-
58-
extension ResponseFormatToStingExtension on OpenAIImageResponseFormat {
59-
String get value {
60-
switch (this) {
61-
case OpenAIImageResponseFormat.url:
62-
return "url";
63-
case OpenAIImageResponseFormat.b64Json:
64-
return "b64_json";
65-
}
66-
}
67-
}

0 commit comments

Comments
 (0)