File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Sources/OpenAI/Public/Models Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,25 @@ public struct Chat: Codable, Equatable {
35
35
self . name = name
36
36
self . functionCall = functionCall
37
37
}
38
+
39
+ public func encode( to encoder: Encoder ) throws {
40
+ var container = encoder. container ( keyedBy: CodingKeys . self)
41
+ try container. encode ( role, forKey: . role)
42
+
43
+ if let name = name {
44
+ try container. encode ( name, forKey: . name)
45
+ }
46
+
47
+ if let functionCall = functionCall {
48
+ try container. encode ( functionCall, forKey: . functionCall)
49
+ }
50
+
51
+ // Should add 'nil' to 'content' property for function calling response
52
+ // See https://openai.com/blog/function-calling-and-other-api-updates
53
+ if content != nil || ( role == . assistant && functionCall != nil ) {
54
+ try container. encode ( content, forKey: . content)
55
+ }
56
+ }
38
57
}
39
58
40
59
public struct ChatFunctionCall : Codable , Equatable {
You can’t perform that action at this time.
0 commit comments