new features
This commit is contained in:
+51
-2
@@ -4,14 +4,16 @@ struct Ollama: InferenceProvider {
|
||||
struct Model: Decodable, Identifiable, Sendable {
|
||||
let name: String
|
||||
let size: Int64?
|
||||
let details: Metadata?
|
||||
var id: String { name }
|
||||
|
||||
enum CodingKeys: String, CodingKey { case name, model, size }
|
||||
enum CodingKeys: String, CodingKey { case name, model, size, details }
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let values = try decoder.container(keyedBy: CodingKeys.self)
|
||||
name = try values.decodeIfPresent(String.self, forKey: .name) ?? values.decode(String.self, forKey: .model)
|
||||
size = try values.decodeIfPresent(Int64.self, forKey: .size)
|
||||
size = try? values.decode(Int64.self, forKey: .size)
|
||||
details = try? values.decode(Metadata.self, forKey: .details)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,8 +106,48 @@ struct Ollama: InferenceProvider {
|
||||
let model: String
|
||||
}
|
||||
|
||||
struct Metadata: Decodable, Sendable {
|
||||
let format: String?
|
||||
let family: String?
|
||||
let parameters: String?
|
||||
let quantization: String?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case format, family
|
||||
case parameters = "parameter_size"
|
||||
case quantization = "quantization_level"
|
||||
}
|
||||
}
|
||||
|
||||
struct ModelDetails: Decodable {
|
||||
let capabilities: [String]?
|
||||
let details: Metadata?
|
||||
let architecture: String?
|
||||
let contextLength: Int?
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case capabilities, details
|
||||
case modelInfo = "model_info"
|
||||
}
|
||||
|
||||
private struct InfoKey: CodingKey {
|
||||
var stringValue: String
|
||||
var intValue: Int? { nil }
|
||||
init(stringValue: String) { self.stringValue = stringValue }
|
||||
init?(intValue: Int) { return nil }
|
||||
}
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let values = try decoder.container(keyedBy: CodingKeys.self)
|
||||
capabilities = try values.decodeIfPresent([String].self, forKey: .capabilities)
|
||||
details = try? values.decode(Metadata.self, forKey: .details)
|
||||
let info = try? values.nestedContainer(keyedBy: InfoKey.self, forKey: .modelInfo)
|
||||
let architecture = try? info?.decode(String.self, forKey: InfoKey(stringValue: "general.architecture"))
|
||||
self.architecture = architecture
|
||||
contextLength = architecture.flatMap {
|
||||
try? info?.decode(Int.self, forKey: InfoKey(stringValue: $0 + ".context_length"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class NoRedirects: NSObject, URLSessionTaskDelegate, Sendable {
|
||||
@@ -160,6 +202,13 @@ struct Ollama: InferenceProvider {
|
||||
return try JSONDecoder().decode(ModelDetails.self, from: data)
|
||||
}
|
||||
|
||||
func copy(_ source: String, to destination: String) async throws {
|
||||
struct CopyBody: Encodable { let source: String; let destination: String }
|
||||
let request = try request("copy", body: CopyBody(source: source, destination: destination))
|
||||
let (_, result) = try await Self.session.data(for: request)
|
||||
try Self.validate(result)
|
||||
}
|
||||
|
||||
func delete(_ model: String) async throws {
|
||||
let (_, result) = try await Self.session.data(for: request("delete", method: "DELETE", body: ModelBody(model: model)))
|
||||
try Self.validate(result)
|
||||
|
||||
Reference in New Issue
Block a user