Skip to content

Commit 7606c2e

Browse files
committed
added API method
1 parent 23635ab commit 7606c2e

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ You can find input format for models at [the model page](https://replicate.com/s
7272
public func getCollections(collection_slug : String) async throws -> CollectionOfModels
7373
```
7474
```swift
75+
/// Get a model
7576
/// - Parameters:
7677
/// - owner: Model owner
7778
/// - name: Model name
7879
public func getModel(owner: String, name: String) async throws -> Model
7980
```
8081

8182
```swift
83+
/// Create prediction
8284
/// - Parameters:
8385
/// - versionId: Version id
8486
/// - input: Input data
@@ -94,6 +96,18 @@ You can find input format for models at [the model page](https://replicate.com/s
9496

9597
```
9698

99+
```swift
100+
/// Get prediction
101+
/// Returns the same response as the create a prediction operation
102+
/// status will be one of ``Prediction.Status``
103+
/// In the case of success, output will be an object containing the output of the model. Any files will be represented as URLs. You'll need to pass the Authorization header to request them.
104+
/// - Parameter id: Prediction id
105+
/// - Returns: Prediction
106+
public func getPrediction<Output: Decodable>(
107+
by id : String
108+
) async throws -> Prediction<Output>
109+
```
110+
97111
![The concept](https://github.com/The-Igor/replicate-kit-swift/blob/main/img/image_03.png)
98112

99113

Sources/replicate-kit-swift/ReplicateAPI.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,24 @@ public struct ReplicateAPI{
131131
return prediction
132132
}
133133
}
134+
135+
/// Returns the same response as the create a prediction operation
136+
/// status will be one of ``Prediction.Status``
137+
/// In the case of success, output will be an object containing the output of the model. Any files will be represented as URLs. You'll need to pass the Authorization header to request them.
138+
/// - Parameter id: Prediction id
139+
/// - Returns: Prediction
140+
public func getPrediction<Output: Decodable>(
141+
by id : String
142+
) async throws -> Prediction<Output>{
143+
144+
let rule = [Http.Validate.status(.range(200..<500))]
145+
let result : Http.Response<Prediction<Output>> = try await client.get(
146+
path: "predictions/\(id)",
147+
validate: rule
148+
)
149+
150+
return result.value
151+
}
134152

135153
// MARK: - Private
136154

@@ -171,24 +189,6 @@ public struct ReplicateAPI{
171189
throw ReplicateAPI.Errors.timeout
172190
}
173191

174-
/// Returns the same response as the create a prediction operation
175-
/// status will be one of ``Prediction.Status``
176-
/// In the case of success, output will be an object containing the output of the model. Any files will be represented as URLs. You'll need to pass the Authorization header to request them.
177-
/// - Parameter id: Prediction id
178-
/// - Returns: Prediction
179-
private func getPrediction<Output: Decodable>(
180-
by id : String
181-
) async throws -> Prediction<Output>{
182-
183-
let rule = [Http.Validate.status(.range(200..<500))]
184-
let result : Http.Response<Prediction<Output>> = try await client.get(
185-
path: "predictions/\(id)",
186-
validate: rule
187-
)
188-
189-
return result.value
190-
}
191-
192192
/// Calling this operation starts a new prediction for the version and inputs you provide. As models can take several seconds or more to run, the output will not be available immediately. To get the final result of the prediction you should either provide a webhook URL for us to call when the results are ready, or poll the get a prediction endpoint until it has one of the terminated statuses.
193193
/// - Parameter body: Request body
194194
/// - Returns: Created prediction

0 commit comments

Comments
 (0)