Skip to content

Commit cbd9c47

Browse files
authored
fix(chat): refactor and fix Tool (#304)
- fix(chat): move `description` to `FunctionTool` - fix(chat): make `FunctionTool#Parameters` nullable - fix(finetuning): nullable `ErrorInfo#message` and `ErrorInfo#code`
1 parent 2969354 commit cbd9c47

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

openai-core/src/commonMain/kotlin/com.aallam.openai.api/chat/Tool.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ public data class Tool(
1515
*/
1616
@SerialName("type") val type: ToolType,
1717

18-
/**
19-
* Tool description.
20-
*/
21-
@SerialName("description") val description: String? = null,
22-
2318
/**
2419
* A description of what the function does, used by the model to choose when and how to call the function.
2520
*/
@@ -38,8 +33,7 @@ public data class Tool(
3833
public fun function(name: String, description: String? = null, parameters: Parameters): Tool =
3934
Tool(
4035
type = ToolType.Function,
41-
description = description,
42-
function = FunctionTool(name = name, parameters = parameters)
36+
function = FunctionTool(name = name, description = description, parameters = parameters)
4337
)
4438
}
4539
}
@@ -56,12 +50,17 @@ public data class FunctionTool(
5650
@SerialName("name") val name: String,
5751

5852
/**
59-
* The parameters the function accepts, described as a JSON Schema object.
60-
* See the [guide](https://github.com/aallam/openai-kotlin/blob/main/guides/ChatToolCalls.md) for examples,
61-
* and the [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for documentation about
53+
* The parameters the functions accept, described as a JSON Schema object.
54+
* See the [guide](https://platform.openai.com/docs/guides/text-generation/function-calling) for examples,
55+
* and the [JSON Schema reference](https://json-schema.org/understanding-json-schema) for documentation about
6256
* the format.
6357
*
64-
* To describe a function that accepts no parameters, provide [Parameters.Empty]`.
58+
* Omitting `parameters` defines a function with an empty parameter list.
59+
*/
60+
@SerialName("parameters") val parameters: Parameters? = null,
61+
62+
/**
63+
* A description of what the function does, used by the model to choose when and how to call the function.
6564
*/
66-
@SerialName("parameters") val parameters: Parameters
65+
@SerialName("description") public val description: String? = null
6766
)

openai-core/src/commonMain/kotlin/com.aallam.openai.api/finetuning/ErrorInfo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ public data class ErrorInfo(
1111
/**
1212
* A human-readable error message.
1313
*/
14-
val message: String,
14+
val message: String? = null,
1515

1616
/**
1717
* A machine-readable error code.
1818
*/
19-
val code: String,
19+
val code: String? = null,
2020

2121
/**
2222
* The parameter that was invalid (e.g., `training_file`, `validation_file`), or null if not parameter-specific.

0 commit comments

Comments
 (0)