Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move methods in CompletionMessage to the companion object #3

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,16 +383,6 @@ sealed class CompletionMessage(val role: String) {
val name: String,
) : CompletionMessage("function")

fun system(content: String, name: String? = null) = System(content, name)
fun text(content: String) = User(UserMessageType.Text(content))
fun image(image: String) = User(UserMessageType.Array(imageContent = UserMessageContent.Image(UserMessageContent.Image.ImageObject(url = image))))
fun user(content: String?, image: String?, name: String? = null) = User(UserMessageType.Array(UserMessageContent.Text(content), UserMessageContent.Image(UserMessageContent.Image.ImageObject(url = image))), name)
fun assistant(content: String, name: String? = null, functionCall: CompletionFunctionCall? = null, toolCalls: List<CompletionToolCall>? = null) = Assistant(content, functionCall, name, toolCalls)
fun tool(content: String, toolCallId: String) = Tool(content, toolCallId)
@Deprecated("Deprecated in the Groq API", ReplaceWith("tool"))
@Suppress("DEPRECATION")
fun function(content: String, name: String) = Function(content, name)

class Serializer : KSerializer<CompletionMessage> {
override val descriptor = buildClassSerialDescriptor("GroqChatCompletionMessage") {
element<String>("role")
Expand Down Expand Up @@ -465,6 +455,24 @@ sealed class CompletionMessage(val role: String) {
error("Unreachable")
}
}

companion object {
fun system(content: String, name: String? = null) = System(content, name)

fun text(content: String) = User(UserMessageType.Text(content))

fun image(image: String) = User(UserMessageType.Array(imageContent = UserMessageContent.Image(UserMessageContent.Image.ImageObject(url = image))))

fun user(content: String?, image: String?, name: String? = null) = User(UserMessageType.Array(UserMessageContent.Text(content), UserMessageContent.Image(UserMessageContent.Image.ImageObject(url = image))), name)

fun assistant(content: String, name: String? = null, functionCall: CompletionFunctionCall? = null, toolCalls: List<CompletionToolCall>? = null) = Assistant(content, functionCall, name, toolCalls)

fun tool(content: String, toolCallId: String) = Tool(content, toolCallId)

@Deprecated("Deprecated in the Groq API", ReplaceWith("tool"))
@Suppress("DEPRECATION")
fun function(content: String, name: String) = Function(content, name)
}
}

/**
Expand Down Expand Up @@ -669,4 +677,4 @@ sealed class CompletionToolChoice(val name: String) {
data class CompletionTool(
val function: CompletionFunction? = null,
val type: String? = "function",
)
)
Loading