openAIChatCompletionRequest
fun openAIChatCompletionRequest(model: String, block: OpenAIChatCompletionRequestBuilder.() -> Unit): OpenAIChatCompletionRequest
Builds an OpenAIChatCompletionRequest using a DSL-style builder.
Return
A fully-formed OpenAIChatCompletionRequest.
Parameters
model
The model identifier (e.g. "gpt-5.6-sol").
block
Lambda for configuring optional request settings.
Throws
if model is missing.
if no messages.
Samples
// Initial conversation history.
val messages: List<OpenAIMessageParam> = openAIMessageParams {
system("You are a helpful assistant.")
user("What's the weather like in London?")
}
// Tool definition with strict schema adherence.
val getWeatherTool = OpenAiChatCompletionFunctionTool(
type = "function",
function = OpenAIFunctionDefinition(
name = "get_weather",
description = "Gets the current weather for a city",
parameters = buildJsonObject {
put("type", "object")
putJsonObject("properties") {
putJsonObject("city") { put("type", "string") }
}
putJsonArray("required") { add("city") }
},
strict = true
)
)
// Build a fully configured request with the DSL.
return openAIChatCompletionRequest(model = "gpt-5.6-sol") {
temperature = 0.7
topP = 1.0
maxCompletionTokens = 1024
seed = 42L
stop = OpenAIStop.OpenAIList(listOf("\n\n", "###"))
presencePenalty = 0.1
frequencyPenalty = 0.1
logprobs = true
topLogprobs = 5
parallelToolCalls = true
toolChoice = OpenAIToolChoice.Auto
responseFormat = OpenAIResponseFormat.JsonObject
verbosity = OpenAIVerbosity.LOW
serviceTier = OpenAIServiceTier.Auto
store = false
safetyIdentifier = "user-123"
metadata = openAIMetadata {
"project" to "kory"
"env" to "examples"
}
streamOptions = OpenAIStreamOptions(includeUsage = true)
messages(messages)
tool(getWeatherTool)
}Content copied to clipboard
return openAIChatCompletionRequest(model = "gpt-5.6-sol") {
messages {
system("You are a helpful assistant.")
user("What's the weather like in London?")
}
}Content copied to clipboard