Skip to content

Commit

Permalink
fix: app path (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
drochetti authored Jan 21, 2024
1 parent caf1e86 commit 2d28371
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Nimble.git",
"state" : {
"revision" : "d616f15123bfb36db1b1075153f73cf40605b39d",
"version" : "13.0.0"
"revision" : "c1f3dd66222d5e7a1a20afc237f7e7bc432c564f",
"version" : "13.2.0"
}
},
{
"identity" : "quick",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Quick.git",
"state" : {
"revision" : "ef9aaf3f634b3a1ab6f54f1173fe2400b36e7cb8",
"version" : "7.3.0"
"revision" : "3dd0b6791850f99e56518467317a9eec53462c66",
"version" : "7.3.1"
}
},
{
Expand Down
3 changes: 3 additions & 0 deletions Sources/FalClient/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public protocol Client {

func subscribe(
to app: String,
path: String?,
input: Payload?,
pollInterval: DispatchTimeInterval,
timeout: DispatchTimeInterval,
Expand Down Expand Up @@ -82,13 +83,15 @@ public extension Client {
/// - onQueueUpdate: A callback to be called when the queue status is updated.
func subscribe(
to app: String,
path: String? = nil,
input: Payload? = nil,
pollInterval: DispatchTimeInterval = .seconds(1),
timeout: DispatchTimeInterval = .minutes(3),
includeLogs: Bool = false,
onQueueUpdate: OnQueueUpdate? = nil
) async throws -> Payload {
try await subscribe(to: app,
path: path,
input: input,
pollInterval: pollInterval,
timeout: timeout,
Expand Down
3 changes: 2 additions & 1 deletion Sources/FalClient/FalClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ public struct FalClient: Client {

public func subscribe(
to app: String,
path: String?,
input: Payload?,
pollInterval: DispatchTimeInterval,
timeout: DispatchTimeInterval,
includeLogs: Bool,
onQueueUpdate: OnQueueUpdate?
) async throws -> Payload {
let requestId = try await queue.submit(app, input: input)
let requestId = try await queue.submit(app, path: path, input: input)
let start = Int(Date().timeIntervalSince1970 * 1000)
var elapsed = 0
var isCompleted = false
Expand Down
10 changes: 5 additions & 5 deletions Sources/FalClient/Queue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public protocol Queue {
/// Submits a request to the given [id], an optional [path]. This method
/// uses the [queue] API to initiate the request. Next you need to rely on
/// [status] and [result] to poll for the result.
func submit(_ id: String, input: Payload?, webhookUrl: String?) async throws -> String
func submit(_ id: String, path: String?, input: Payload?, webhookUrl: String?) async throws -> String

/// Checks the queue for the status of the request with the given [requestId].
/// See [QueueStatus] for the different statuses.
Expand All @@ -24,8 +24,8 @@ public protocol Queue {
}

public extension Queue {
func submit(_ id: String, input: Payload? = nil, webhookUrl: String? = nil) async throws -> String {
try await submit(id, input: input, webhookUrl: webhookUrl)
func submit(_ id: String, path: String? = nil, input: Payload? = nil, webhookUrl: String? = nil) async throws -> String {
try await submit(id, path: path, input: input, webhookUrl: webhookUrl)
}

func status(_ id: String, of requestId: String, includeLogs: Bool = false) async throws -> QueueStatus {
Expand Down Expand Up @@ -64,8 +64,8 @@ public struct QueueClient: Queue {
return try .create(fromJSON: data)
}

public func submit(_ id: String, input: Payload?, webhookUrl _: String?) async throws -> String {
let result = try await runOnQueue(id, input: input, options: .withMethod(.post))
public func submit(_ id: String, path: String?, input: Payload?, webhookUrl _: String?) async throws -> String {
let result = try await runOnQueue(id, input: input, options: .route(path ?? "", withMethod: .post))
guard case let .string(requestId) = result["request_id"] else {
throw FalError.invalidResultFormat
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ContentView: View {
isLoading = true
do {
let result = try await fal.subscribe(
to: "110602490-fast-sdxl",
to: "fal-ai/fast-sdxl",
input: [
"prompt": .string(PROMPT),
],
Expand Down

0 comments on commit 2d28371

Please sign in to comment.