Skip to content
This repository was archived by the owner on Jan 24, 2026. It is now read-only.

Commit 77b7c7c

Browse files
committed
feat: Add extraBody field to ChatCompletionRequest, for Claude/OpenAI compatible
1 parent 47aecf8 commit 77b7c7c

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/main/kotlin/io/github/stream29/proxy/client/OpenAi.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ data class OpenAiConfig(
2222
val baseUrl: String,
2323
val apiKey: String,
2424
val modelList: List<String>,
25+
val extraRequest: (ChatCompletionRequest) -> ChatCompletionRequest = { it },
2526
) : ApiProvider {
2627
override suspend fun getModelNameList(): List<String> = modelList
2728
override suspend fun generateLStream(request: LChatCompletionRequest): Flow<LChatCompletionResponseChunk> {
28-
return chatCompletionsRecording(request.asOpenAiRequest()).map { it.asLChatCompletionResponseChunk() }
29+
return chatCompletionsRecording(extraRequest(request.asOpenAiRequest())).map { it.asLChatCompletionResponseChunk() }
2930
}
3031

3132
override suspend fun generateOStream(request: OChatRequest): Flow<OChatResponseChunk> {
32-
return chatCompletionsRecording(request.asOpenAiRequest()).map { it.asOChatResponseChunk() }
33+
return chatCompletionsRecording(extraRequest(request.asOpenAiRequest())).map { it.asOChatResponseChunk() }
3334
}
3435

3536
override fun close() {}

src/main/kotlin/io/github/stream29/proxy/relocate/com.aallam.openai.api/chat/ChatCompletionRequest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.github.stream29.proxy.relocate.com.aallam.openai.api.BetaOpenAI
66
import io.github.stream29.proxy.relocate.com.aallam.openai.api.model.ModelId
77
import kotlinx.serialization.SerialName
88
import kotlinx.serialization.Serializable
9+
import kotlinx.serialization.json.JsonElement
910

1011
/**
1112
* Creates a completion for the chat message.
@@ -183,6 +184,9 @@ data class ChatCompletionRequest(
183184
* Options for streaming response. Only used when in streaming mode.
184185
*/
185186
@SerialName("stream_options") val streamOptions: StreamOptions? = null,
186-
val stream: Boolean = true
187+
val stream: Boolean = true,
188+
189+
@SerialName("extra_body")
190+
val extraBody: JsonElement? = null,
187191
)
188192

0 commit comments

Comments
 (0)