From d925c29c6442b2bbbb708e1fb15b61ae1f830a2c Mon Sep 17 00:00:00 2001 From: Dmitry Shipinev Date: Tue, 10 Sep 2024 12:55:18 +0700 Subject: [PATCH] Represent integer and floating-point values as string data to match JSON encoding behavior --- Sources/ExyteOpenAI/Networking/Provider.swift | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Sources/ExyteOpenAI/Networking/Provider.swift b/Sources/ExyteOpenAI/Networking/Provider.swift index cd57f24..37eca92 100644 --- a/Sources/ExyteOpenAI/Networking/Provider.swift +++ b/Sources/ExyteOpenAI/Networking/Provider.swift @@ -257,24 +257,18 @@ open class Provider { 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) } }