Support OpenAI-compatible inference endpoints
This commit is contained in:
@@ -107,7 +107,8 @@ enum Router {
|
||||
|
||||
static func stream(
|
||||
primary: @escaping Producer,
|
||||
fallback: Producer?
|
||||
fallback: Producer?,
|
||||
primaryName: String = "Ollama"
|
||||
) -> AsyncThrowingStream<Delta, Error> {
|
||||
streaming { continuation in
|
||||
var committed = false
|
||||
@@ -135,7 +136,7 @@ enum Router {
|
||||
} catch let fallbackError {
|
||||
try Task.checkCancellation()
|
||||
if fallbackError is CancellationError { throw fallbackError }
|
||||
throw StudioError("Ollama: \(error.localizedDescription) MLX: \(fallbackError.localizedDescription)")
|
||||
throw StudioError("\(primaryName): \(error.localizedDescription) MLX: \(fallbackError.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,7 +233,7 @@ struct GenerationSettings: Codable {
|
||||
(try? JSONDecoder().decode(Self.self, from: data)) ?? Self()
|
||||
}
|
||||
|
||||
func parameters(mlxOnly: Bool) throws -> GenerationParameters {
|
||||
func parameters(mlxOnly: Bool, compatible: Bool = false) throws -> GenerationParameters {
|
||||
func number(_ value: String, _ title: String, _ range: ClosedRange<Double>) throws -> Double? {
|
||||
let text = value.trimmingCharacters(in: .whitespaces)
|
||||
guard !text.isEmpty else { return nil }
|
||||
@@ -262,15 +263,17 @@ struct GenerationSettings: Codable {
|
||||
throw StudioError("Use up to 32 stop sequences, each up to 512 bytes.")
|
||||
}
|
||||
if !mlxOnly {
|
||||
result.frequencyPenalty = try number(frequencyPenalty, "Frequency penalty", -2...2)
|
||||
result.presencePenalty = try number(presencePenalty, "Presence penalty", -2...2)
|
||||
result.json = json
|
||||
}
|
||||
if !mlxOnly && !compatible {
|
||||
result.topK = try integer(topK, "Top K", 0...1_048_576)
|
||||
result.minP = try number(minP, "Min P", 0...1)
|
||||
result.context = try integer(context, "Context length", 1...1_048_576)
|
||||
result.seed = try integer(seed, "Seed", 0...Int(Int32.max))
|
||||
result.frequencyPenalty = try number(frequencyPenalty, "Frequency penalty", -2...2)
|
||||
result.presencePenalty = try number(presencePenalty, "Presence penalty", -2...2)
|
||||
let duration = keepAlive.trimmingCharacters(in: .whitespaces)
|
||||
result.keepAlive = duration.isEmpty ? nil : duration
|
||||
result.json = json
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user