File tree Expand file tree Collapse file tree
Tool/Sources/OpenAIService Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,7 +10,25 @@ protocol CompletionAPI {
1010
1111/// https://platform.openai.com/docs/api-reference/chat/create
1212struct CompletionResponseBody : Codable , Equatable {
13- typealias Message = CompletionRequestBody . Message
13+ struct Message : Codable , Equatable {
14+ /// The role of the message.
15+ var role : ChatMessage . Role
16+ /// The content of the message.
17+ var content : String ?
18+ /// When we want to reply to a function call with the result, we have to provide the
19+ /// name of the function call, and include the result in `content`.
20+ ///
21+ /// - important: It's required when the role is `function`.
22+ var name : String ?
23+ /// When the bot wants to call a function, it will reply with a function call in format:
24+ /// ```json
25+ /// {
26+ /// "name": "weather",
27+ /// "arguments": "{ \"location\": \"earth\" }"
28+ /// }
29+ /// ```
30+ var function_call : CompletionRequestBody . MessageFunctionCall ?
31+ }
1432
1533 struct Choice : Codable , Equatable {
1634 var message : Message
@@ -89,7 +107,12 @@ struct OpenAICompletionAPI: CompletionAPI {
89107 . otherError ( String ( data: result, encoding: . utf8) ?? " Unknown Error " )
90108 }
91109
92- return try JSONDecoder ( ) . decode ( CompletionResponseBody . self, from: result)
110+ do {
111+ return try JSONDecoder ( ) . decode ( CompletionResponseBody . self, from: result)
112+ } catch {
113+ dump ( error)
114+ fatalError ( )
115+ }
93116 }
94117}
95118
You can’t perform that action at this time.
0 commit comments