File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -107,9 +107,9 @@ public isolated client class OpenAiProvider {
107107 }
108108 chat : ChatCompletionResponseMessage ? message = choices [0 ].message ;
109109 ai : ChatAssistantMessage chatAssistantMessage = {role : ai :ASSISTANT , content : message ?.content };
110- chat : ChatCompletionFunctionCall ? function_call = message ?.function_call ;
111- if function_call is chat : ChatCompletionFunctionCall {
112- chatAssistantMessage .toolCalls = [{ name : function_call . name , arguments : function_call . arguments } ];
110+ chat : ChatCompletionFunctionCall ? functionCall = message ?.function_call ;
111+ if functionCall is chat : ChatCompletionFunctionCall {
112+ chatAssistantMessage .toolCalls = [check self . mapToFunctionCall ( functionCall ) ];
113113 }
114114 return chatAssistantMessage ;
115115 }
@@ -134,4 +134,15 @@ public isolated client class OpenAiProvider {
134134 }
135135 return chatCompletionRequestMessages ;
136136 }
137+
138+ private isolated function mapToFunctionCall(chat : ChatCompletionFunctionCall functionCall )
139+ returns ai : FunctionCall | ai :LlmError {
140+ do {
141+ json jsonArgs = check functionCall .arguments .fromJsonString ();
142+ map < json > ? arguments = check jsonArgs .cloneWithType ();
143+ return {name : functionCall .name , arguments };
144+ } on fail error e {
145+ return error ai : LlmError (" Invalid or malformed arguments received in function call response." , e );
146+ }
147+ }
137148}
You can’t perform that action at this time.
0 commit comments