Skip to content

Commit

Permalink
Represent integer and floating-point values as string data to match J…
Browse files Browse the repository at this point in the history
…SON encoding behavior
  • Loading branch information
shipinev committed Sep 10, 2024
1 parent f179fde commit d925c29
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions Sources/ExyteOpenAI/Networking/Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,24 +257,18 @@ open class Provider<T: EndpointConfiguration> {
throw OpenAIError.multipartEncoding(encodingError: .dataEncodingFailed)
}
bodyData = textData
case .floatingPoint(let float):
case .floatingPoint(let value):
mimeType = $0.mimeType ?? MimeType.unknownBinary
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
do {
let numberData = try encoder.encode(float)
if let numberData = "\(value)".data(using: .utf8) {
bodyData = numberData
} catch {
} else {
throw OpenAIError.multipartEncoding(encodingError: .dataEncodingFailed)
}
case .integer(let integer):
case .integer(let value):
mimeType = $0.mimeType ?? MimeType.unknownBinary
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
do {
let numberData = try encoder.encode(integer)
if let numberData = "\(value)".data(using: .utf8) {
bodyData = numberData
} catch {
} else {
throw OpenAIError.multipartEncoding(encodingError: .dataEncodingFailed)
}
}
Expand Down

0 comments on commit d925c29

Please sign in to comment.