Skip to content

Commit

Permalink
[ Fix ] fixed the non resulted n field of image variation method
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Nov 8, 2023
1 parent fe721d5 commit ccaab97
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 6 additions & 3 deletions example/lib/image_variation_example.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:dart_openai/dart_openai.dart';

import 'env/env.dart';
Expand All @@ -7,9 +9,10 @@ Future<void> main() async {
OpenAI.apiKey = Env.apiKey;

// Creates the Image Variation
final variation = await OpenAI.instance.image.create(
prompt: "Tree with blue butterflies wings",
n: 2,
final variation = await OpenAI.instance.image.variation(
model: "dall-e-2",
image: File("dart.png"),
n: 4,
);

// Prints the result.
Expand Down
5 changes: 4 additions & 1 deletion lib/src/core/networking/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ abstract class OpenAINetworkingClient {
String respondData = "";
stream.where((event) => event.isNotEmpty).listen(
(value) {
print(value);

final data = value;
respondData += data;

Expand Down Expand Up @@ -407,7 +409,7 @@ abstract class OpenAINetworkingClient {
required String to,
required T Function(Map<String, dynamic>) onSuccess,
// ignore: avoid-unused-parameters
required Map<String, dynamic> body,
required Map<String, String> body,
required File image,
}) async {
OpenAILogger.logStartRequest(to);
Expand All @@ -420,6 +422,7 @@ abstract class OpenAINetworkingClient {

final imageFile = await http.MultipartFile.fromPath("image", image.path);

request.fields.addAll(body);
request.files.add(imageFile);

final http.StreamedResponse response = await request.send();
Expand Down
13 changes: 12 additions & 1 deletion lib/src/instance/images/images.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ interface class OpenAIImages implements OpenAIImagesBase {

/// Creates an edited or extended image given an original image and a prompt.
///
/// [model] is the model to use for generating the image.
///
///
/// [image] to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, image must have transparency, which will be used as the mask.
///
///
Expand Down Expand Up @@ -146,6 +149,7 @@ interface class OpenAIImages implements OpenAIImagesBase {
///```
@override
Future<OpenAiImageEditModel> edit({
String? model,
required File image,
File? mask,
required String prompt,
Expand All @@ -155,10 +159,12 @@ interface class OpenAIImages implements OpenAIImagesBase {
String? user,
}) async {
final String edit = "/edits";

return await OpenAINetworkingClient.imageEditForm<OpenAiImageEditModel>(
image: image,
mask: mask,
body: {
if (model != null) "model": model,
"prompt": prompt,
if (n != null) "n": n.toString(),
if (size != null) "size": size.value,
Expand All @@ -175,6 +181,9 @@ interface class OpenAIImages implements OpenAIImagesBase {
/// Creates a variation of a given image.
///
///
/// [model] is the model to use for generating the image.
///
///
/// [image] to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
///
///
Expand Down Expand Up @@ -206,6 +215,7 @@ interface class OpenAIImages implements OpenAIImagesBase {
/// ```
@override
Future<OpenAIImageVariationModel> variation({
String? model,
required File image,
int? n,
OpenAIImageSize? size,
Expand All @@ -218,7 +228,8 @@ interface class OpenAIImages implements OpenAIImagesBase {
OpenAIImageVariationModel>(
image: image,
body: {
if (n != null) "n": n,
if (model != null) "model": model,
if (n != null) "n": n.toString(),
if (size != null) "size": size.value,
if (responseFormat != null) "response_format": responseFormat.value,
if (user != null) "user": user,
Expand Down

0 comments on commit ccaab97

Please sign in to comment.