-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Incorporates the generator as a module * Fixes `ChatCompletionRequestMessage` model
- Loading branch information
1 parent
5d4eef1
commit 11c9eba
Showing
208 changed files
with
238 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
generator/openai-api.yml | ||
generator/config/openai-api.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
154 changes: 154 additions & 0 deletions
154
...onMain/kotlin/com/xebia/functional/openai/models/ext/chat/ChatCompletionRequestMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package com.xebia.functional.openai.apis.com.xebia.functional.openai.models.ext.chat | ||
|
||
import com.xebia.functional.openai.models.ChatCompletionMessageToolCall | ||
import com.xebia.functional.openai.models.ChatCompletionRequestAssistantMessageFunctionCall | ||
import kotlinx.serialization.Required | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
sealed interface ChatCompletionRequestMessage { | ||
|
||
/** | ||
* @param content The contents of the system message. | ||
* @param role The role of the messages author, in this case `system`. | ||
*/ | ||
@Serializable | ||
data class ChatCompletionRequestSystemMessage( | ||
|
||
/* The contents of the system message. */ | ||
@SerialName(value = "content") @Required val content: String?, | ||
|
||
/* The role of the messages author, in this case `system`. */ | ||
@SerialName(value = "role") @Required val role: ChatCompletionRequestSystemMessage.Role | ||
) : ChatCompletionRequestMessage { | ||
|
||
/** | ||
* The role of the messages author, in this case `system`. | ||
* | ||
* Values: system | ||
*/ | ||
@Serializable | ||
enum class Role(val value: String) { | ||
@SerialName(value = "system") system("system") | ||
} | ||
} | ||
|
||
/** | ||
* @param content | ||
* @param role The role of the messages author, in this case `user`. | ||
*/ | ||
@Serializable | ||
data class ChatCompletionRequestUserMessage( | ||
@SerialName(value = "content") | ||
@Required | ||
val content: | ||
com.xebia.functional.openai.models.ext.chat.ChatCompletionRequestUserMessageContent?, | ||
|
||
/* The role of the messages author, in this case `user`. */ | ||
@SerialName(value = "role") @Required val role: ChatCompletionRequestUserMessage.Role | ||
) : ChatCompletionRequestMessage { | ||
|
||
/** | ||
* The role of the messages author, in this case `user`. | ||
* | ||
* Values: user | ||
*/ | ||
@Serializable | ||
enum class Role(val value: String) { | ||
@SerialName(value = "user") user("user") | ||
} | ||
} | ||
|
||
/** | ||
* @param content The contents of the assistant message. | ||
* @param role The role of the messages author, in this case `assistant`. | ||
* @param toolCalls The tool calls generated by the model, such as function calls. | ||
* @param functionCall | ||
*/ | ||
@Serializable | ||
data class ChatCompletionRequestAssistantMessage( | ||
|
||
/* The contents of the assistant message. */ | ||
@SerialName(value = "content") @Required val content: String?, | ||
|
||
/* The role of the messages author, in this case `assistant`. */ | ||
@SerialName(value = "role") @Required val role: ChatCompletionRequestAssistantMessage.Role, | ||
|
||
/* The tool calls generated by the model, such as function calls. */ | ||
@SerialName(value = "tool_calls") val toolCalls: List<ChatCompletionMessageToolCall>? = null, | ||
@Deprecated(message = "This property is deprecated.") | ||
@SerialName(value = "function_call") | ||
val functionCall: ChatCompletionRequestAssistantMessageFunctionCall? = null | ||
) { | ||
|
||
/** | ||
* The role of the messages author, in this case `assistant`. | ||
* | ||
* Values: assistant | ||
*/ | ||
@Serializable | ||
enum class Role(val value: String) { | ||
@SerialName(value = "assistant") assistant("assistant") | ||
} | ||
} | ||
|
||
/** | ||
* @param role The role of the messages author, in this case `tool`. | ||
* @param content The contents of the tool message. | ||
* @param toolCallId Tool call that this message is responding to. | ||
*/ | ||
@Serializable | ||
data class ChatCompletionRequestToolMessage( | ||
|
||
/* The role of the messages author, in this case `tool`. */ | ||
@SerialName(value = "role") @Required val role: ChatCompletionRequestToolMessage.Role, | ||
|
||
/* The contents of the tool message. */ | ||
@SerialName(value = "content") @Required val content: String?, | ||
|
||
/* Tool call that this message is responding to. */ | ||
@SerialName(value = "tool_call_id") @Required val toolCallId: String | ||
) { | ||
|
||
/** | ||
* The role of the messages author, in this case `tool`. | ||
* | ||
* Values: tool | ||
*/ | ||
@Serializable | ||
enum class Role(val value: String) { | ||
@SerialName(value = "tool") tool("tool") | ||
} | ||
} | ||
|
||
/** | ||
* @param role The role of the messages author, in this case `function`. | ||
* @param content The return value from the function call, to return to the model. | ||
* @param name The name of the function to call. | ||
*/ | ||
@Serializable | ||
@Deprecated(message = "This schema is deprecated.") | ||
data class ChatCompletionRequestFunctionMessage( | ||
|
||
/* The role of the messages author, in this case `function`. */ | ||
@SerialName(value = "role") @Required val role: ChatCompletionRequestFunctionMessage.Role, | ||
|
||
/* The return value from the function call, to return to the model. */ | ||
@SerialName(value = "content") @Required val content: kotlin.String?, | ||
|
||
/* The name of the function to call. */ | ||
@SerialName(value = "name") @Required val name: kotlin.String | ||
) { | ||
|
||
/** | ||
* The role of the messages author, in this case `function`. | ||
* | ||
* Values: function | ||
*/ | ||
@Serializable | ||
enum class Role(val value: kotlin.String) { | ||
@SerialName(value = "function") function("function") | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
@file:Suppress("DSL_SCOPE_VIOLATION") | ||
|
||
plugins { | ||
java | ||
alias(libs.plugins.spotless) | ||
} | ||
|
||
dependencies { | ||
implementation("org.openapitools:openapi-generator-cli:7.0.1") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
} | ||
|
||
task("openaiClientGenerate", JavaExec::class) { | ||
group = "GenerateTasks" | ||
mainClass = "org.openapitools.codegen.OpenAPIGenerator" | ||
args = listOf( | ||
"generate", | ||
"-i", | ||
"config/openai-api.yaml", | ||
"-g", | ||
"ai.xef.openai.generator.KMMGeneratorConfig", | ||
"-o", | ||
"../client", | ||
"--skip-validate-spec", | ||
"-c", | ||
"config/openai-config.json", | ||
) | ||
classpath = sourceSets["main"].runtimeClasspath | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
openai-client/generator/src/main/java/ai/xef/openai/generator/KMMGeneratorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ai.xef.openai.generator; | ||
|
||
import org.openapitools.codegen.languages.KotlinClientCodegen; | ||
|
||
public class KMMGeneratorConfig extends KotlinClientCodegen { | ||
|
||
public KMMGeneratorConfig() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public String toEnumVarName(String value, String datatype) { | ||
String varName; | ||
if ("length".equals(value)) { | ||
varName = value + "Type"; | ||
} else { | ||
varName = value; | ||
} | ||
return super.toEnumVarName(varName, datatype); | ||
} | ||
} |
Oops, something went wrong.