From 59d0a5ca10e6e33046398a55029298040b24e0f2 Mon Sep 17 00:00:00 2001 From: Daniel Rochetti Date: Sun, 5 Nov 2023 18:51:59 -0800 Subject: [PATCH] chore: reorg package exports (#3) * chore: reorg package exports * chore: move model types from main * chore: update changelog --- CHANGELOG.md | 9 +++ README.md | 17 +++--- example/lib/main.dart | 56 +++++-------------- example/lib/types.dart | 33 +++++++++++ lib/fal_client.dart | 5 ++ lib/runtime/version.dart | 1 - lib/{ => src}/client.dart | 2 - lib/{ => src}/config.dart | 0 lib/{ => src}/exception.dart | 0 lib/{ => src}/http.dart | 0 lib/{ => src}/queue.dart | 0 lib/{ => src}/runtime/platform.dart | 0 lib/{ => src}/runtime/platform/base.dart | 0 lib/{ => src}/runtime/platform/html.dart | 0 lib/{ => src}/runtime/platform/interface.dart | 0 lib/{ => src}/runtime/platform/io.dart | 0 lib/src/runtime/version.dart | 3 + lib/{ => src}/storage.dart | 0 pubspec.yaml | 2 +- 19 files changed, 75 insertions(+), 53 deletions(-) create mode 100644 example/lib/types.dart create mode 100644 lib/fal_client.dart delete mode 100644 lib/runtime/version.dart rename lib/{ => src}/client.dart (99%) rename lib/{ => src}/config.dart (100%) rename lib/{ => src}/exception.dart (100%) rename lib/{ => src}/http.dart (100%) rename lib/{ => src}/queue.dart (100%) rename lib/{ => src}/runtime/platform.dart (100%) rename lib/{ => src}/runtime/platform/base.dart (100%) rename lib/{ => src}/runtime/platform/html.dart (100%) rename lib/{ => src}/runtime/platform/interface.dart (100%) rename lib/{ => src}/runtime/platform/io.dart (100%) create mode 100644 lib/src/runtime/version.dart rename lib/{ => src}/storage.dart (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index a503320..be4680e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v0.2.1 + +### What's Changed +* chore: reorg package exports by @drochetti in https://github.com/fal-ai/serverless-client-dart/pull/3 + +**Full Changelog**: https://github.com/fal-ai/serverless-client-dart/compare/v0.2.0...v0.2.1 + +--- + ## v0.2.0 ### What's Changed diff --git a/README.md b/README.md index d0f654a..b15321d 100644 --- a/README.md +++ b/README.md @@ -28,25 +28,28 @@ This client library is crafted as a lightweight layer atop platform standards li 2. Setup the client instance: ```dart - import 'package:fal_client/client.dart'; + import "package:fal_client/client.dart"; - final fal = FalClient.withCredentials('FAL_KEY_ID:FAL_KEY_SECRET'); + final fal = FalClient.withCredentials("FAL_KEY_ID:FAL_KEY_SECRET"); ``` 3. Now use `fal.subcribe` to dispatch requests to the model API: ```dart - final result = await fal.subscribe('text-to-image', input: { - 'prompt': 'a cute shih-tzu puppy', - 'model_name': 'stabilityai/stable-diffusion-xl-base-1.0', - }); + final result = await fal.subscribe('110602490-lora', + input: { + 'prompt': 'a cute shih-tzu puppy', + 'model_name': 'stabilityai/stable-diffusion-xl-base-1.0', + 'image_size': 'square_hd' + }, + onQueueUpdate: (update) => {print(update)} + ); ``` **Notes:** - Replace `text-to-image` with a valid model id. Check [fal.ai/models](https://fal.ai/models) for all available models. - The result type is a `Map` and the entries depend on the API output schema. -- Types in Python are mapped to their corresponding types in Dart (e.g. `str` -> `String`). ## Roadmap diff --git a/example/lib/main.dart b/example/lib/main.dart index afd41d8..c06252a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,12 +1,14 @@ -import 'package:fal_client/client.dart'; +import 'package:fal_client/fal_client.dart'; import 'package:flutter/material.dart'; +import 'types.dart'; + // You can use the proxyUrl to protect your credentials in production. -// final fal = FalClient.withProxy("http://localhost:3333/api/fal/proxy"); +// final fal = FalClient.withProxy('http://localhost:3333/api/_fal/proxy'); // You can also use the credentials locally for development, but make sure // you protected your credentials behind a proxy in production. -final fal = FalClient.withCredentials("fal_key_id:fal_key_secret"); +final fal = FalClient.withCredentials('FAL_KEY_ID:FAL_KEY_SECRET'); void main() { runApp(const MyApp()); @@ -29,38 +31,6 @@ class MyApp extends StatelessWidget { } } -class TextToImageResult { - final List images; - final int seed; - - TextToImageResult({required this.images, required this.seed}); - - factory TextToImageResult.fromMap(Map json) { - return TextToImageResult( - images: (json['images'] as List) - .map((e) => ImageRef.fromMap(e as Map)) - .toList(), - seed: json['seed'], - ); - } -} - -class ImageRef { - final String url; - final int height; - final int width; - - ImageRef({required this.url, required this.height, required this.width}); - - factory ImageRef.fromMap(Map json) { - return ImageRef( - url: json['url'], - height: json['height'], - width: json['width'], - ); - } -} - class TextoToImageScreen extends StatefulWidget { const TextoToImageScreen({super.key, required this.title}); @@ -71,7 +41,7 @@ class TextoToImageScreen extends StatefulWidget { // This class is the configuration for the state. It holds the values (in this // case the title) provided by the parent (in this case the App widget) and // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". + // always marked 'final'. final String title; @@ -82,7 +52,7 @@ class TextoToImageScreen extends StatefulWidget { class _TextoToImageScreenState extends State { bool _isLoading = false; final _promptController = - TextEditingController(text: "a cute shih-tzu puppy"); + TextEditingController(text: 'a cute shih-tzu puppy'); ImageRef? _image; void _generateImage() async { @@ -90,11 +60,13 @@ class _TextoToImageScreenState extends State { _isLoading = true; _image = null; }); - final result = await fal.subscribe("110602490-lora", input: { - "prompt": _promptController.text, - "model_name": "stabilityai/stable-diffusion-xl-base-1.0", - "image_size": "square_hd" - }); + final result = await fal.subscribe(textToImageId, + input: { + 'prompt': _promptController.text, + 'model_name': 'stabilityai/stable-diffusion-xl-base-1.0', + 'image_size': 'square_hd' + }, + onQueueUpdate: (update) => {print(update)}); setState(() { _isLoading = false; _image = TextToImageResult.fromMap(result).images[0]; diff --git a/example/lib/types.dart b/example/lib/types.dart new file mode 100644 index 0000000..9e6e66d --- /dev/null +++ b/example/lib/types.dart @@ -0,0 +1,33 @@ +class TextToImageResult { + final List images; + final int seed; + + TextToImageResult({required this.images, required this.seed}); + + factory TextToImageResult.fromMap(Map json) { + return TextToImageResult( + images: (json['images'] as List) + .map((e) => ImageRef.fromMap(e as Map)) + .toList(), + seed: (json['seed'] * 1).round(), + ); + } +} + +class ImageRef { + final String url; + final int height; + final int width; + + ImageRef({required this.url, required this.height, required this.width}); + + factory ImageRef.fromMap(Map json) { + return ImageRef( + url: json['url'], + height: (json['height'] * 1).round(), + width: (json['width'] * 1).round(), + ); + } +} + +const textToImageId = '110602490-lora'; diff --git a/lib/fal_client.dart b/lib/fal_client.dart new file mode 100644 index 0000000..5e45e3e --- /dev/null +++ b/lib/fal_client.dart @@ -0,0 +1,5 @@ +export 'src/client.dart'; +export 'src/config.dart'; +export 'src/exception.dart'; +export 'src/queue.dart'; +export 'src/storage.dart'; diff --git a/lib/runtime/version.dart b/lib/runtime/version.dart deleted file mode 100644 index d7a6010..0000000 --- a/lib/runtime/version.dart +++ /dev/null @@ -1 +0,0 @@ -const packageVersion = '0.2.0'; diff --git a/lib/client.dart b/lib/src/client.dart similarity index 99% rename from lib/client.dart rename to lib/src/client.dart index 6425588..7bbe879 100644 --- a/lib/client.dart +++ b/lib/src/client.dart @@ -1,5 +1,3 @@ -library fal_client; - import './config.dart'; import './exception.dart'; import './http.dart'; diff --git a/lib/config.dart b/lib/src/config.dart similarity index 100% rename from lib/config.dart rename to lib/src/config.dart diff --git a/lib/exception.dart b/lib/src/exception.dart similarity index 100% rename from lib/exception.dart rename to lib/src/exception.dart diff --git a/lib/http.dart b/lib/src/http.dart similarity index 100% rename from lib/http.dart rename to lib/src/http.dart diff --git a/lib/queue.dart b/lib/src/queue.dart similarity index 100% rename from lib/queue.dart rename to lib/src/queue.dart diff --git a/lib/runtime/platform.dart b/lib/src/runtime/platform.dart similarity index 100% rename from lib/runtime/platform.dart rename to lib/src/runtime/platform.dart diff --git a/lib/runtime/platform/base.dart b/lib/src/runtime/platform/base.dart similarity index 100% rename from lib/runtime/platform/base.dart rename to lib/src/runtime/platform/base.dart diff --git a/lib/runtime/platform/html.dart b/lib/src/runtime/platform/html.dart similarity index 100% rename from lib/runtime/platform/html.dart rename to lib/src/runtime/platform/html.dart diff --git a/lib/runtime/platform/interface.dart b/lib/src/runtime/platform/interface.dart similarity index 100% rename from lib/runtime/platform/interface.dart rename to lib/src/runtime/platform/interface.dart diff --git a/lib/runtime/platform/io.dart b/lib/src/runtime/platform/io.dart similarity index 100% rename from lib/runtime/platform/io.dart rename to lib/src/runtime/platform/io.dart diff --git a/lib/src/runtime/version.dart b/lib/src/runtime/version.dart new file mode 100644 index 0000000..902964a --- /dev/null +++ b/lib/src/runtime/version.dart @@ -0,0 +1,3 @@ +// Note: temporary solution, should be replaced with something +// else that resolves the package version at build-time or runtime. +const packageVersion = '0.2.1'; diff --git a/lib/storage.dart b/lib/src/storage.dart similarity index 100% rename from lib/storage.dart rename to lib/src/storage.dart diff --git a/pubspec.yaml b/pubspec.yaml index f031cae..91f12d4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: fal_client description: > The Dart client library for fal.ai model APIs. You can use it to call multiple AI models on your Dart and Flutter apps. -version: 0.2.0 +version: 0.2.1 homepage: https://fal.ai repository: https://github.com/fal-ai/serverless-client-dart issue_tracker: https://github.com/fal-ai/serverless-client-dart/issues?q=is%3Aissue+is%3Aopen