updateTool method
Updates a completion choice with tool metadata when a tool was selected.
Implementation
void updateTool(Completion response) {
if (response.choices.firstOrNull?.finishReason == 'tool_calls') {
final dynamic toolName =
response.choices.firstOrNull?.inlineWidget?.keys.firstOrNull;
if (toolName == null) {
return;
}
final Map<String, dynamic>? tool = tools?.firstWhereOrNull(
(element) => element['function']['name'] == toolName);
if (tool == null) {
return;
}
response.choices.first.tool = tool;
final MessageType? newMessageType = MessageType.values.firstWhereOrNull(
(element) => element.name.toString() == tool['function']['toolType']);
if (newMessageType == null) {
return;
}
response.choices.first.messageType = newMessageType;
}
}