[ Fix ] fixed the non resulted n field of image variation method

This commit is contained in:
Anas Fikhi
2023-11-08 22:30:15 +01:00
parent fe721d5998
commit ccaab97c82
3 changed files with 22 additions and 5 deletions

View File

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:dart_openai/dart_openai.dart';
import 'env/env.dart';
@ -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.

View File

@ -280,6 +280,8 @@ abstract class OpenAINetworkingClient {
String respondData = "";
stream.where((event) => event.isNotEmpty).listen(
(value) {
print(value);
final data = value;
respondData += data;
@ -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);
@ -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();

View File

@ -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.
///
///
@ -146,6 +149,7 @@ interface class OpenAIImages implements OpenAIImagesBase {
///```
@override
Future<OpenAiImageEditModel> edit({
String? model,
required File image,
File? mask,
required String prompt,
@ -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,
@ -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.
///
///
@ -206,6 +215,7 @@ interface class OpenAIImages implements OpenAIImagesBase {
/// ```
@override
Future<OpenAIImageVariationModel> variation({
String? model,
required File image,
int? n,
OpenAIImageSize? size,
@ -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,