Skip to content

Commit daa99cb

Browse files
RobertCraigiestainless-app[bot]
authored andcommitted
fix(functions): add accidentally removed arguments method
1 parent bd94a0b commit daa99cb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

openai-java-core/src/main/kotlin/com/openai/models/chat/completions/ChatCompletionMessageFunctionToolCall.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import com.openai.core.JsonField
1111
import com.openai.core.JsonMissing
1212
import com.openai.core.JsonValue
1313
import com.openai.core.checkRequired
14+
import com.openai.core.responseTypeFromJson
1415
import com.openai.errors.OpenAIInvalidDataException
1516
import java.util.Collections
1617
import java.util.Objects
@@ -262,6 +263,22 @@ private constructor(
262263
*/
263264
fun arguments(): String = arguments.getRequired("arguments")
264265

266+
/**
267+
* Gets the arguments to the function call, converting the values from the model in JSON
268+
* format to an instance of a class that holds those values. The class must previously have
269+
* been used to define the JSON schema for the function definition's parameters, so that the
270+
* JSON corresponds to structure of the given class.
271+
*
272+
* @throws OpenAIInvalidDataException If the JSON data is missing, `null`, or cannot be
273+
* parsed to an instance of the [functionParametersType] class. This might occur if the
274+
* class is not the same as the class that was originally used to define the arguments, or
275+
* if the data from the AI model is invalid or incomplete (e.g., truncated).
276+
* @see ChatCompletionCreateParams.Builder.addTool
277+
* @see arguments
278+
*/
279+
fun <T> arguments(functionParametersType: Class<T>): T =
280+
responseTypeFromJson(arguments(), functionParametersType)
281+
265282
/**
266283
* The name of the function to call.
267284
*

0 commit comments

Comments
 (0)