dart_openai 1.1.0 copy "dart_openai: ^1.1.0" to clipboard
dart_openai: ^1.1.0 copied to clipboard

Dart SDK for openAI Apis (GPT-3 & DALL-E), integrate easily the power of OpenAI's state-of-the-art AI models into their Dart applications.

Dart SDK for openAI Apis (GPT-3 & DALL-E) #

An open-source SDK that allows developers to easily integrate the power of OpenAI's state-of-the-art AI models into their Dart applications. This library provides simple and intuitive methods for making requests to OpenAI's various APIs, including the GPT-3 language model, DALL-E image generation, and more.

The package is designed to be lightweight and easy to use, so you can focus on building your application, rather than worrying about the complexities and error caused by dealing with HTTP requests.

Unofficial
OpenAI does not have any official Dart library.

Note:

Please note that this client SDK connects directly to openAI APIs using http requests, it doesn't provide any additional APIs than what exists here.

Code Progress #

Testing Progress #


Articles: #

Authentication #

API key #

We highly recommend loading your secret key at runtime from a .env file, you can use the dotenv package.

void main() {
 DotEnv env = DotEnv()..load([".env"]);
 OpenAI.apiKey = env['OPEN_AI_API_KEY'];
 // ..
}

Setting an organization #

 OpenAI.organization = "ORGANIZATION ID";

Learn More From Here.


Models #

List Models #

Lists the currently available models, and provides basic information about each one such as the owner and availability.

 final models = await OpenAI.instance.model.list();
 print(models.first.id);

Retrieve model #

Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

 final model = await OpenAI.instance.model.retrieve("MODEL ID");
 print(model.id)

Learn More From Here.


Completions #

Creates

Create completion #

 OpenAICompletionModel completion = await OpenAI.instance.completion.create(
   model: "text-davinci-003",
   prompt: "Dart is a ",
   temperature: 0.8,
 );

Learn More From Here.


Edits #

Create edit #

 OpenAIEditModel edit = await OpenAI.instance.edit.create(
   model: "text-davinci-edit-001",
   input: " Hi!, I am a bot!!!!,",
   instruction: "remove all ! the input ",
 );

Learn More From Here.


Images #

Create image #

 OpenAIImageModel image = await OpenAI.instance.image.create(
   prompt: "A dog",
   n: 1,
 );

Create image edit #

 final result = await OpenAI.instance.image.edit(
   image: File(/* image file path*/),
   mask: File(/* mask file path*/),
   prompt: "change color to green",
   n: 1,
 );

Create image variation #

OpenAIImageVariationModel variation = await OpenAI.instance.image.variation(
 image: File(/*YOUR IMAGE FILE PATH*/),
);

Learn More From Here.


Embeddings #

Create embeddings #

OpenAIEmbeddingsModel embeddings = await OpenAI.instance.embedding.create(
  model: "text-embedding-ada-002",
  input: "This is a text input just to test",
);;

Learn More From Here.


Files #

List files #

List<OpenAIFileModel> files = await OpenAI.instance.file.list();

Upload file #

OpenAIFileModel uploadedFile = await OpenAI.instance.file.upload(
 file: File("FILE PATH HERE"),
 purpose: "fine-tuning",
);

Delete file #

bool isFileDeleted = await OpenAI.instance.file.delete("FILE ID");

Retrieve file #

OpenAIFileModel file = await OpenAI.instance.file.retrieve("FILE ID");

Retrieve file content #

dynamic fileContent  = await OpenAI.instance.file.retrieveContent("FILE ID");

Learn More From Here.


Fine Tunes #

Create fine-tune #

OpenAIFineTuneModel fineTune = await OpenAI.instance.fineTune.create(
 trainingFile: "FILE ID",
);

List fine-tunes #

List<OpenAIFineTuneModel> fineTunes = await OpenAI.instance.fineTune.list();

Retrieve fine-tune #

OpenAIFineTuneModel fineTune = await OpenAI.instance.fineTune.retrieve("FINE TUNE ID");

Cancel fine-tune #

OpenAIFineTuneModel fineTune = await OpenAI.instance.fineTune.cancel("FINE TUNE ID");

List fine-tune events #

 List<OpenAIFineTuneEventModel> events = await OpenAI.instance.fineTune.listEvents("FINE TUNE ID");

Delete fine-tune #

 bool deleted = await OpenAI.instance.fineTune.delete("FINE TUNE ID");

Learn More From Here.


Moderations #

Create moderation #

OpenAIModerationModel moderationResult = await OpenAI.instance.moderation.create(
  input: "I want to kill him",
);

Learn More From Here.


Error Handling #

Any time an error happens from the OpenAI API ends (As Example: when you try to create an image variation from a non-image file ), a RequestFailedException will be thrown automatically inside your Flutter / Dart app, you can use a try-catch to catch that error, and make an action based on it:

try {

// This will throw an error.
 final errorVariation = await OpenAI.instance.image.variation(
  image: File(/*PATH OF NON-IMAGE FILE*/),
 );
} on RequestFailedException catch(e) {
 print(e.message);
 print(e.statusCode)
}
484
likes
0
pub points
97%
popularity

Publisher

verified publishergwhyyy.com

Dart SDK for openAI Apis (GPT-3 & DALL-E), integrate easily the power of OpenAI's state-of-the-art AI models into their Dart applications.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

collection, http, meta, path

More

Packages that depend on dart_openai