File tree Expand file tree Collapse file tree 12 files changed +65
-27
lines changed
main/kotlin/com/cjcrafter/openai Expand file tree Collapse file tree 12 files changed +65
-27
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import okhttp3.OkHttpClient
44import okhttp3.Request
55import okhttp3.RequestBody
66import okhttp3.RequestBody.Companion.toRequestBody
7+ import org.jetbrains.annotations.ApiStatus
78
89/* *
910 * The Azure OpenAI API client.
@@ -16,7 +17,7 @@ import okhttp3.RequestBody.Companion.toRequestBody
1617 * @property apiVersion The API version to use. Defaults to 2023-03-15-preview.
1718 * @property modelName The model name to use. This is the name of the model deployed to Azure.
1819 */
19- class AzureOpenAI @JvmOverloads constructor(
20+ class AzureOpenAI @ApiStatus. Internal constructor(
2021 apiKey : String ,
2122 organization : String? = null ,
2223 client : OkHttpClient = OkHttpClient (),
Original file line number Diff line number Diff line change @@ -3,9 +3,16 @@ package com.cjcrafter.openai.chat.tool
33import com.cjcrafter.openai.chat.ChatUser
44import com.fasterxml.jackson.annotation.JsonProperty
55
6+ /* *
7+ * Represents the "delta," or changes of a chat message. This is used by streams
8+ * stream 1 token at a time.
9+ *
10+ * @property role Who sent the message. Will always be [ChatUser.ASSISTANT] for the first message, then `null`
11+ * @property content 1 token of the message. Will always be `null` for tool calls
12+ * @property toolCalls Modifications to the tool calls. Will always be `null` when content is not `null`
13+ */
614data class ChatMessageDelta (
715 val role : ChatUser ? = null ,
816 val content : String? = null ,
917 @JsonProperty(" tool_calls" ) val toolCalls : List <ToolCallDelta >? = null ,
10- ) {
11- }
18+ )
Original file line number Diff line number Diff line change @@ -23,9 +23,7 @@ data class FunctionCall(
2323 var name : String ,
2424 var arguments : String ,
2525) {
26-
27- @ApiStatus.Internal
28- fun update (delta : FunctionCallDelta ) {
26+ internal fun update (delta : FunctionCallDelta ) {
2927 // The only field that updates is arguments
3028 arguments + = delta.arguments
3129 }
Original file line number Diff line number Diff line change 11package com.cjcrafter.openai.chat.tool
22
3- import org.jetbrains.annotations.ApiStatus
4-
3+ /* *
4+ * Represents the "delta," or changes of a function call. This is used by streams
5+ * to stream 1 token at a time.
6+ *
7+ * @property name The name of the function to call. Will always be `null` except for the first call.
8+ * @property arguments 1 token of the arguments. Well be delivered as a JSON string.
9+ */
510data class FunctionCallDelta (
611 val name : String? ,
712 val arguments : String ,
@@ -10,8 +15,7 @@ data class FunctionCallDelta(
1015 /* *
1116 * Returns an **incomplete** function call.
1217 */
13- @ApiStatus.Internal
14- fun toFunctionCall (): FunctionCall {
18+ internal fun toFunctionCall (): FunctionCall {
1519 return FunctionCall (
1620 name ? : throw IllegalStateException (" name must be set" ),
1721 arguments
Original file line number Diff line number Diff line change @@ -11,9 +11,9 @@ package com.cjcrafter.openai.chat.tool
1111 * @property properties The map of method parameters.
1212 */
1313data class FunctionParameters internal constructor(
14- val type : String = " object" ,
15- val properties : MutableMap <String , FunctionProperty > = mutableMapOf(),
16- val required : MutableSet <String > = mutableSetOf(),
14+ var type : String = " object" ,
15+ var properties : MutableMap <String , FunctionProperty > = mutableMapOf(),
16+ var required : MutableSet <String > = mutableSetOf(),
1717) {
1818 /* *
1919 * Require that the given parameter is used by ChatGPT.
Original file line number Diff line number Diff line change @@ -17,9 +17,9 @@ import com.cjcrafter.openai.util.RegexInternals
1717 * @property description A description of the function
1818 */
1919data class FunctionTool internal constructor(
20- @FunctionTag val name : String ,
21- val parameters : FunctionParameters ,
22- val description : String? = null ,
20+ @FunctionTag var name : String ,
21+ var parameters : FunctionParameters ,
22+ var description : String? = null ,
2323) : AbstractTool() {
2424
2525 init {
Original file line number Diff line number Diff line change @@ -10,6 +10,6 @@ package com.cjcrafter.openai.chat.tool
1010 * @property function The function. This is only used if [type] is [ToolType.FUNCTION].
1111 */
1212data class Tool (
13- val type : ToolType ,
14- val function : FunctionTool ,
13+ var type : ToolType ,
14+ var function : FunctionTool ,
1515)
Original file line number Diff line number Diff line change 11package com.cjcrafter.openai.chat.tool
22
3- import org.jetbrains.annotations.ApiStatus
4-
3+ /* *
4+ * Wraps a tool call by ChatGPT. You should check the [type] of the tool call,
5+ * and handle the request. For example, if the type is [ToolType.FUNCTION], you
6+ * should call the function and return the result.
7+ *
8+ * When making subsequent requests to chat completions, you should make sure to
9+ * pass the message that contained this tool call, and the result of the tool
10+ * call.
11+ *
12+ * @property id The id of this call. You should use this to construct a [com.cjcrafter.openai.chat.ChatUser.TOOL] message.
13+ * @property type The type of tool call. Currently, the only type is [ToolType.FUNCTION].
14+ * @property function The function call containing the function name and arguments.
15+ */
516data class ToolCall (
617 var id : String ,
718 var type : ToolType ,
819 var function : FunctionCall ,
920) {
10- @ApiStatus.Internal
1121 internal fun update (delta : ToolCallDelta ) {
1222 // The only field that updates is function
1323 if (delta.function != null )
Original file line number Diff line number Diff line change 11package com.cjcrafter.openai.chat.tool
22
3- import org.jetbrains.annotations.ApiStatus
4-
3+ /* *
4+ * Represents the "delta," or changes of a tool call. This is used by streams
5+ * to stream 1 token at a time.
6+ *
7+ * @property index The index of the tool call we are modifying.
8+ * @property id The tool call id used in replies. Will always be `null` except for the first call.
9+ * @property type The type of tool call. Will always be `null` except for the first call.
10+ * @property function The modifications to the function call.
11+ */
512data class ToolCallDelta (
613 val index : Int ,
714 val id : String? = null ,
815 val type : ToolType ? = null ,
916 val function : FunctionCallDelta ? = null ,
1017) {
11- @ApiStatus.Internal
12- fun toToolCall () = ToolCall (
18+ internal fun toToolCall () = ToolCall (
1319 id = id ? : throw IllegalStateException (" id must be set" ),
1420 type = type ? : throw IllegalStateException (" type must be set" ),
1521 function = function?.toFunctionCall() ? : throw IllegalStateException (" function must be set" ),
Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ package com.cjcrafter.openai.chat.tool
33import com.cjcrafter.openai.jackson.ToolChoiceDeserializer
44import com.cjcrafter.openai.jackson.ToolChoiceSerializer
55
6+ /* *
7+ * Represents the configuration for tool choice. Defaults to [Auto].
8+ */
69sealed class ToolChoice {
710
811 /* *
You can’t perform that action at this time.
0 commit comments