Skip to content

Commit

Permalink
feat: update generate image request
Browse files Browse the repository at this point in the history
  • Loading branch information
redevrx committed Mar 6, 2024
1 parent 896d462 commit 8faa6ee
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,5 @@
- Fix bugs
- Update Assistant Model
- Add Support Tools to Json
- Update Generate Image Request

2 changes: 1 addition & 1 deletion example/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ final heroNav = BoxDecoration(
spreadRadius: .5)
]);

const kToken = "your-token";
const kToken = "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";

This comment has been minimized.

Copy link
@nomtats

nomtats Apr 28, 2024

Contributor

Hi @redevrx, I just wanted to leave a note in case you exposed this token by mistake.

This comment has been minimized.

Copy link
@redevrx

redevrx via email Apr 28, 2024

Author Owner
16 changes: 15 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ class _TranslateScreenState extends State<TranslateScreen> {
await openAI.onChatCompletion(request: request);
}

void generateImage() async {
final request = GenerateImage(
"snake eating cat",
1,
model: DallE3(),
size: ImageSize.size1024,
responseFormat: Format.url,
quality: "hd"
);
final response = await openAI.generateImage(request);

debugPrint('${response?.data?.map((e) => e?.toJson())}');
}

@override
void initState() {
openAI = OpenAI.instance.build(
Expand Down Expand Up @@ -181,7 +195,7 @@ class _TranslateScreenState extends State<TranslateScreen> {
icon: Icons.translate,
iconSize: 18.0,
radius: 46.0,
onClick: _translateEngToThai,
onClick: generateImage,
),
),
],
Expand Down
9 changes: 8 additions & 1 deletion lib/src/model/gen_image/request/generate_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class GenerateImage {
final String user;

final GenerateImageModel model;
final String? quality;
final String? style;

GenerateImage(
this.prompt,
Expand All @@ -27,6 +29,8 @@ class GenerateImage {
this.size = ImageSize.size1024,
this.responseFormat = Format.url,
this.user = "",
this.quality,
this.style,
}) : assert(1 <= n && n <= 10, 'n must be between 1 and 10.');

Map<String, dynamic> toJson() => Map.of({
Expand All @@ -36,5 +40,8 @@ class GenerateImage {
"size": size?.size,
"response_format": responseFormat?.getName(),
"user": user,
});
"quality": quality,
"style": style,
})
..removeWhere((key, value) => value == null);
}

0 comments on commit 8faa6ee

Please sign in to comment.