-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial support for message batches (#11)
- Loading branch information
Showing
11 changed files
with
142 additions
and
55 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
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
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,73 @@ | ||
package com.xemantic.anthropic | ||
|
||
import com.xemantic.anthropic.batch.ProcessingStatus | ||
import com.xemantic.anthropic.batch.RequestCounts | ||
import com.xemantic.anthropic.message.Content | ||
import com.xemantic.anthropic.message.Message | ||
import com.xemantic.anthropic.message.Role | ||
import com.xemantic.anthropic.message.StopReason | ||
import com.xemantic.anthropic.message.Usage | ||
import kotlinx.datetime.LocalDateTime | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonClassDiscriminator | ||
|
||
@Serializable | ||
@JsonClassDiscriminator("type") | ||
@OptIn(ExperimentalSerializationApi::class) | ||
sealed class Response( | ||
val type: String | ||
) | ||
|
||
@Serializable | ||
@SerialName("error") | ||
data class ErrorResponse( | ||
val error: Error | ||
) : Response(type = "error") | ||
|
||
@Serializable | ||
@SerialName("message") | ||
data class MessageResponse( | ||
val id: String, | ||
val role: Role, | ||
val content: List<Content>, // limited to Text and ToolUse | ||
val model: String, | ||
@SerialName("stop_reason") | ||
val stopReason: StopReason?, | ||
@SerialName("stop_sequence") | ||
val stopSequence: String?, | ||
val usage: Usage | ||
) : Response(type = "message") { | ||
|
||
fun asMessage(): Message = Message { | ||
role = Role.ASSISTANT | ||
content += this@MessageResponse.content | ||
} | ||
|
||
} | ||
|
||
@Serializable | ||
@SerialName("message_batch") | ||
data class MessageBatchResponse( | ||
val id: String, | ||
@SerialName("processing_status") | ||
val processingStatus: ProcessingStatus, | ||
@SerialName("request_counts") | ||
val requestCounts: RequestCounts, | ||
@SerialName("ended_at") | ||
val endedAt: LocalDateTime?, | ||
@SerialName("created_at") | ||
val createdAt: LocalDateTime, | ||
@SerialName("expires_at") | ||
val expiresAt: LocalDateTime, | ||
@SerialName("cancel_initiated_at") | ||
val cancelInitiatedAt: LocalDateTime?, | ||
@SerialName("results_url") | ||
val resultsUrl: String? | ||
) : Response(type = "message_batch") {} | ||
|
||
@Serializable | ||
data class Error( | ||
val type: String, val message: String | ||
) |
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,47 @@ | ||
package com.xemantic.anthropic.batch | ||
|
||
import com.xemantic.anthropic.message.Message | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class MessageBatchRequest( | ||
val requests: List<Request> | ||
) | ||
|
||
@Serializable | ||
data class Request( | ||
@SerialName("custom_id") | ||
val customId: String, | ||
val params: Params | ||
) { | ||
|
||
@Serializable | ||
data class Params( | ||
val model: String, | ||
val maxTokens: Int, | ||
val messages: List<Message> | ||
) | ||
|
||
} | ||
|
||
@Serializable | ||
data class RequestCounts( | ||
val processing: Int, | ||
val succeeded: Int, | ||
val errored: Int, | ||
val canceled: Int, | ||
val expired: Int | ||
) | ||
|
||
/** | ||
* Processing status of the Message Batch. | ||
*/ | ||
enum class ProcessingStatus { | ||
@SerialName("in_progress") | ||
IN_PROGRESS, | ||
@SerialName("canceling") | ||
CANCELING, | ||
@SerialName("ended") | ||
ENDED | ||
} |
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
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
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