Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Client.createTraining method #62

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Replicate/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,14 @@ public class Client {
/// so make sure it can be safely called more than once.
public func createTraining<Input: Codable>(
_ type: Training<Input>.Type = AnyTraining.self,
model: Model.ID,
version: Model.Version.ID,
destination: Model.ID,
input: Input,
webhook: Webhook? = nil
) async throws -> Training<Input>
{
var params: [String: Value] = [
"version": "\(version)",
"destination": "\(destination)",
"input": try Value(input)
]
Expand All @@ -434,7 +434,7 @@ public class Client {
params["webhook_events_filter"] = .array(webhook.events.map { "\($0.rawValue)" })
}

return try await fetch(.post, "trainings", params: params)
return try await fetch(.post, "models/\(model)/versions/\(version)/trainings", params: params)
}

@available(*, deprecated, renamed: "listTrainings(_:cursor:)")
Expand Down
39 changes: 0 additions & 39 deletions Sources/Replicate/Trainable.swift

This file was deleted.

3 changes: 2 additions & 1 deletion Tests/ReplicateTests/ClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ final class ClientTests: XCTestCase {
}

func testCreateTraining() async throws {
let base: Model.ID = "example/base"
let version: Model.Version.ID = "4a056052b8b98f6db8d011a450abbcd09a408ec9280c29f22d3538af1099646a"
let destination: Model.ID = "my/fork"
let training = try await client.createTraining(version: version, destination: destination, input: ["data": "..."])
let training = try await client.createTraining(model: base, version: version, destination: destination, input: ["data": "..."])
XCTAssertEqual(training.id, "zz4ibbonubfz7carwiefibzgga")
XCTAssertEqual(training.versionID, version)
XCTAssertEqual(training.status, .starting)
Expand Down
2 changes: 1 addition & 1 deletion Tests/ReplicateTests/Helpers/MockURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ class MockURLProtocol: URLProtocol {
]
}
"""#
case ("POST", "https://api.replicate.com/v1/trainings"?):
case ("POST", "https://api.replicate.com/v1/models/example/base/versions/4a056052b8b98f6db8d011a450abbcd09a408ec9280c29f22d3538af1099646a/trainings"?):
statusCode = 201

json = #"""
Expand Down