mirror of
https://github.com/hanzoai/swift-sdk.git
synced 2026-10-30 18:20:19 +00:00
This repo existed twice: the forge carried a client regenerated against cloud 70b374b9, github carried one against 54ddf3d6 — its ancestor — plus the examples, hanzo.yml and .gitignore the forge line never had. Neither was a superset, so neither could simply overwrite the other. Merged: the newer generation, and everything only the other line had. The flows had rotted against it exactly as the gate exists to prevent, because the regeneration and the examples were on opposite lines: the newer document tags those operations under AiAPI, and drops /v1/keys entirely. models calls AiAPI, hello calls ToolsAPI.getTools — typed, and still the call that refuses without a credential. hanzo.yml now gates the tree that carries both, so the next such move breaks in CI rather than in a reader's editor.
31 lines
1.0 KiB
Swift
31 lines
1.0 KiB
Swift
// models — the model catalogue, with no credential at all.
|
|
//
|
|
// swift run --package-path examples models
|
|
//
|
|
// GET /v1/models is one of four operations the document marks `security: []`,
|
|
// so this runs against api.hanzo.ai with nothing configured. The document
|
|
// states that route's address and not its shape, so the generated method
|
|
// returns nothing and the bytes come off the request builder's Response.
|
|
|
|
import Foundation
|
|
import Flow
|
|
import Hanzo
|
|
|
|
Flow.configure(authenticated: false)
|
|
|
|
do {
|
|
let response = try await AiAPI.getModelsWithRequestBuilder().execute()
|
|
let body = response.bodyData ?? Data()
|
|
let root = (try? JSONSerialization.jsonObject(with: body)) as? [String: Any]
|
|
let models = root?["data"] as? [[String: Any]] ?? []
|
|
|
|
print("HTTP \(response.statusCode) from \(Flow.base)")
|
|
print("\(models.count) models")
|
|
for model in models.prefix(5) {
|
|
print(" \(model["id"] ?? "?")")
|
|
}
|
|
} catch {
|
|
// Typed throws: `error` is an ErrorResponse here, and nothing else can be.
|
|
Flow.fail(error)
|
|
}
|