dart_openai 1.0.4 dart_openai: ^1.0.4 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.
Progress #
- ❌ ChatGPT ( as soon as possible when it's released )
- ✅ Authentication
- ✅ Models
- ✅ Completions
- ✅ With
Stream
responses
- ✅ With
- ✅ Edits
- ✅ Images
- ✅ Embeddings
- ✅ Files
- ✅ Fine-tunes
- ❌ With events
Stream
responses
- ❌ With events
- ✅ Moderation
Testing Progress #
- ✅ Authentication
- ✅ Models
- ✅ Completions
- ✅ Edits
- ✅ Images
- ✅ Embeddings
- ✅ Files
- ❌ Fine-tunes
- ✅ Moderation
Authentication #
API key #
We highly recommend loading your secret key at runtime using an .env
file, you can use the dotenv package.
void main() {
OpenAI.apiKey = dotenv.env["OPEN_AI_API_KEY"]!;
// ..
}
Setting an organization #
OpenAI.organization = "ORGANIZATION ID";
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.one("MODEL ID");
print(model.id)
Completions #
Create completion #
OpenAICompletionModel completion = await OpenAI.instance.completion.create(
model: "text-davinci-003",
prompt: "Dart is a ",
temperature: 0.8,
);
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 ",
);
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*/),
);
Embeddings #
Create embeddings #
OpenAIEmbeddingsModel embeddings = await OpenAI.instance.embedding.create(
model: "text-embedding-ada-002",
input: "This is a text input just to test",
);;
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");
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");
Moderations #
Create moderation #
OpenAIModerationModel moderationResult = await OpenAI.instance.moderation.create(
input: "I want to kill him",
);