Venice's API doesn't support certain OpenAI-compatible parameters that Clawdbot sends by default: - `store`: Venice returns HTTP 400 with no body when this is present - `developer` role: Not supported by Venice's API This adds VENICE_COMPAT settings (supportsStore: false, supportsDeveloperRole: false) to all Venice model definitions, both from the static catalog and dynamically discovered models. Fixes issues reported in PR #1666 where users experienced silent failures (HTTP 400, no body) when using Venice models. Co-authored-by: jonisjongithub <jonisjongithub@users.noreply.github.com> Co-authored-by: Clawdbot <bot@clawd.bot>
51 lines
1.9 KiB
Swift
51 lines
1.9 KiB
Swift
@preconcurrency import AVFoundation
|
|
import Foundation
|
|
|
|
final class BufferConverter {
|
|
private final class Box<T>: @unchecked Sendable { var value: T; init(_ value: T) { self.value = value } }
|
|
enum ConverterError: Swift.Error {
|
|
case failedToCreateConverter
|
|
case failedToCreateConversionBuffer
|
|
case conversionFailed(NSError?)
|
|
}
|
|
|
|
private var converter: AVAudioConverter?
|
|
|
|
func convert(_ buffer: AVAudioPCMBuffer, to format: AVAudioFormat) throws -> AVAudioPCMBuffer {
|
|
let inputFormat = buffer.format
|
|
if inputFormat == format {
|
|
return buffer
|
|
}
|
|
if converter == nil || converter?.outputFormat != format {
|
|
converter = AVAudioConverter(from: inputFormat, to: format)
|
|
converter?.primeMethod = .none
|
|
}
|
|
guard let converter else { throw ConverterError.failedToCreateConverter }
|
|
|
|
let sampleRateRatio = converter.outputFormat.sampleRate / converter.inputFormat.sampleRate
|
|
let scaledInputFrameLength = Double(buffer.frameLength) * sampleRateRatio
|
|
let frameCapacity = AVAudioFrameCount(scaledInputFrameLength.rounded(.up))
|
|
guard let conversionBuffer = AVAudioPCMBuffer(pcmFormat: converter.outputFormat, frameCapacity: frameCapacity)
|
|
else {
|
|
throw ConverterError.failedToCreateConversionBuffer
|
|
}
|
|
|
|
var nsError: NSError?
|
|
let consumed = Box(false)
|
|
let inputBuffer = buffer
|
|
let status = converter.convert(to: conversionBuffer, error: &nsError) { _, statusPtr in
|
|
if consumed.value {
|
|
statusPtr.pointee = .noDataNow
|
|
return nil
|
|
}
|
|
consumed.value = true
|
|
statusPtr.pointee = .haveData
|
|
return inputBuffer
|
|
}
|
|
if status == .error {
|
|
throw ConverterError.conversionFailed(nsError)
|
|
}
|
|
return conversionBuffer
|
|
}
|
|
}
|