mirror of
https://github.com/zhigang1992/fal-swift.git
synced 2026-04-30 02:16:17 +08:00
chore: add build workflow (#1)
* chore: add build workflow * chore: test macos runtime * fix: swift version on build * fix: swift version 5.9 * chore: add swiftformat * fix: remove build sample app for now * chore: add license etc * chore: sample working version
This commit is contained in:
@@ -4,6 +4,25 @@ func buildUrl(fromId id: String, path: String? = nil) -> String {
|
||||
"https://\(id).gateway.alpha.fal.ai" + (path ?? "")
|
||||
}
|
||||
|
||||
/// The main client class that provides access to simple API model usage,
|
||||
/// as well as access to the `queue` and `storage` APIs.
|
||||
///
|
||||
/// Example:
|
||||
///
|
||||
/// ```swift
|
||||
/// import FalClient
|
||||
///
|
||||
/// let fal = FalClient.withCredentials("fal_key_id:fal_key_secret");
|
||||
///
|
||||
/// void main() async {
|
||||
/// // check https://fal.ai/models for the available models
|
||||
/// final result = await fal.subscribe(to: 'text-to-image', input: {
|
||||
/// 'prompt': 'a cute shih-tzu puppy',
|
||||
/// 'model_name': 'stabilityai/stable-diffusion-xl-base-1.0',
|
||||
/// });
|
||||
/// print(result);
|
||||
/// }
|
||||
/// ```
|
||||
public struct FalClient: Client {
|
||||
public let config: ClientConfig
|
||||
|
||||
@@ -49,10 +68,10 @@ public struct FalClient: Client {
|
||||
}
|
||||
return try await queue.response(id, of: requestId)
|
||||
}
|
||||
}
|
||||
|
||||
public static let shared: Client = Self(config: ClientConfig())
|
||||
|
||||
public static func withProxy(_ url: String) -> Client {
|
||||
return Self(config: ClientConfig(requestProxy: url))
|
||||
public extension FalClient {
|
||||
static func withProxy(_ url: String) -> FalClient {
|
||||
return FalClient(config: ClientConfig(requestProxy: url))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,7 @@ struct ContentView: View {
|
||||
print("Generate image...")
|
||||
isLoading = true
|
||||
do {
|
||||
let result = try await fal.subscribe("110602490-lora", input: [
|
||||
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
|
||||
"image_size": "square_hd",
|
||||
let result = try await fal.subscribe("110602490-fast-sdxl", input: [
|
||||
"prompt": PROMPT,
|
||||
], includeLogs: true) { update in
|
||||
print(update)
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import FalClient
|
||||
|
||||
let fal = FalClient.withProxy("http://localhost:3333/api/_fal/proxy")
|
||||
let fal = FalClient.withProxy("http://localhost:3333/api/fal/proxy")
|
||||
|
||||
Reference in New Issue
Block a user