Skip to content

Commit

Permalink
[ Add ] added more examples to reproduce in the example/ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Feb 10, 2023
1 parent 023aa9f commit 4475e84
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 5 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# 1.2.3

- Exposed image size and url enums to be used externally

# 1.2.1

- formatted some dart files

# 1.2.0

- Added more detailed documentation that reflects OpenAI's.
- Added more helper methods, enums for making it more easy to manipulate properties and decrease error chances
- More Examples, explanations for README.md.
- Code Improvments.

# 1.1.2

- Added more detailed documentation that reflects OpenAI's.
Expand Down
Binary file added example/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions example/lib/completion_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:dart_openai/openai.dart';
import 'package:dotenv/dotenv.dart';

Future<void> main() async {
// Load the .env file
DotEnv env = DotEnv()..load([".env"]);

// Set the OpenAI API key from the .env file.
OpenAI.apiKey = env['OPEN_AI_API_KEY']!;

// Creates The Completion
OpenAICompletionModel completion = await OpenAI.instance.completion.create(
model: "text-davinci-003",
prompt: 'Flutter is ',
maxTokens: 100,
temperature: 0.8,
);

// Prints the completion text.
print(completion.choices.first.text);
}
25 changes: 25 additions & 0 deletions example/lib/edit_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:dart_openai/openai.dart';
import 'package:dotenv/dotenv.dart';

Future<void> main() async {
// Load the .env file
DotEnv env = DotEnv()..load([".env"]);

// Set the OpenAI API key from the .env file.
OpenAI.apiKey = env['OPEN_AI_API_KEY']!;

// Creates the Edit
OpenAIEditModel edit = await OpenAI.instance.edit.create(
model: "text-davinci-edit-001",
input:
"Flutter is a cross-platform UI toolkit that is designed to allow code reuse across operating systems such as iOS and Android, while also allowing applications to interface directly with underlying platform services.",
instruction: "summarize the input to 50 tokens at maximum",
temperature: 0.8,
n: 4,
);

// Prints the choices.
for (int index = 0; index < edit.choices.length; index++) {
print(edit.choices[index].text);
}
}
23 changes: 23 additions & 0 deletions example/lib/image_variation_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'dart:io';

import 'package:dart_openai/openai.dart';
import 'package:dotenv/dotenv.dart';

Future<void> main() async {
// Load the .env file
DotEnv env = DotEnv()..load([".env"]);

// Set the OpenAI API key from the .env file.
OpenAI.apiKey = env['OPEN_AI_API_KEY']!;

// Creates the Image Variation
OpenAIImageVariationModel variation = await OpenAI.instance.image.variation(
image: File("example.png"),
n: 1,
size: OpenAIImageSize.size256,
responseFormat: OpenAIResponseFormat.b64Json,
);

// Prints the result.
print(variation.data.first.url);
}
18 changes: 18 additions & 0 deletions example/lib/moderation_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:dart_openai/openai.dart';
import 'package:dotenv/dotenv.dart';

Future<void> main() async {
// Load the .env file
DotEnv env = DotEnv()..load([".env"]);

// Set the OpenAI API key from the .env file.
OpenAI.apiKey = env['OPEN_AI_API_KEY']!;

// Creates the moderation.
OpenAIModerationModel moderation = await OpenAI.instance.moderation.create(
input: 'I hate you, I will kill you',
);

// prints the result
print(moderation.results.first.categories);
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ packages:
name: dart_openai
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.7"
version: "1.2.3"
dotenv:
dependency: "direct main"
description:
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ environment:
dependencies:
path: ^1.8.0
dotenv: any
dart_openai: ^1.0.7
dart_openai: 1.2.3

dev_dependencies:
lints: ^2.0.0
test: ^1.16.0
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dart_openai
description: 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.
version: 1.1.2
version: 1.2.3
homepage: https://github.com/anasfik/openai
repository: https://github.com/anasfik/openai
documentation: https://github.com/anasfik/openai/blob/main/README.md
Expand All @@ -15,4 +15,4 @@ dev_dependencies:
dependencies:
http: ^0.13.5
meta: ^1.8.0
collection: ^1.17.1
collection: ^1.17.0

0 comments on commit 4475e84

Please sign in to comment.