Skip to content

Commit 2b43fe5

Browse files
Update FunctionCallDetails to use Any for arguments and adjust JSON encoding/decoding
1 parent e6442b4 commit 2b43fe5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/Grok-API-SDK/Models/FunctionCall.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ public struct ToolCall: Codable, Sendable {
8080

8181
public struct FunctionCallDetails: Codable, Sendable {
8282
public let name: String
83-
public let arguments: [String: String]
83+
public let arguments: [String: Any]
8484

8585
// Custom decoding to handle JSON string for arguments
8686
public init(from decoder: Decoder) throws {
8787
let container = try decoder.container(keyedBy: CodingKeys.self)
8888
name = try container.decode(String.self, forKey: .name)
8989
let argumentsString = try container.decode(String.self, forKey: .arguments)
9090
if let data = argumentsString.data(using: .utf8),
91-
let argumentsDict = try? JSONDecoder().decode([String: String].self, from: data) {
91+
let argumentsDict = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
9292
arguments = argumentsDict
9393
} else {
9494
arguments = [:]
@@ -99,7 +99,7 @@ public struct FunctionCallDetails: Codable, Sendable {
9999
public func encode(to encoder: Encoder) throws {
100100
var container = encoder.container(keyedBy: CodingKeys.self)
101101
try container.encode(name, forKey: .name)
102-
let argumentsData = try JSONEncoder().encode(arguments)
102+
let argumentsData = try JSONSerialization.data(withJSONObject: arguments, options: [])
103103
let argumentsString = String(data: argumentsData, encoding: .utf8) ?? "{}"
104104
try container.encode(argumentsString, forKey: .arguments)
105105
}

0 commit comments

Comments
 (0)