chatResponses
suspend fun chatResponses(request: OpenAIResponsesRequest, onCanceled: (cancelResult: OpenAIResponsesResponse?) -> Unit? = null): OpenAIResponsesResponse
suspend fun chatResponses(model: String, block: OpenAIResponsesRequestBuilder.() -> Unit): OpenAIResponsesResponse
Samples
val response = client.chatResponses("gpt-6-astra") {
inputText("Write a short bedtime story about a unicorn.")
}
println(response.outputText)Content copied to clipboard
val response = client.chatResponses("gpt-6-astra") {
inputItems {
easyInputMessage(Role.User) {
text("what is in this file?")
fileUrl("https://www.berkshirehathaway.com/letters/2024ltr.pdf", detail = OpenAIDetail.Auto)
}
}
}
println(response.outputText)Content copied to clipboard
@Serializable
data class TestWeatherToolArgs(
@ToolParam(description = "Name of the city for which you want the weather forecast")
val city: String,
)
val testWeatherTool = openAIFunctionTool<TestWeatherToolArgs, String>(
name = "get_weather",
description = "Get weather for the city",
) { args ->
"Current weather in ${args.city} is ${listOf("Sunny", "Rainy").random()}, ${(-20..20).random()} Celsius"
}
val response = client.chatResponses("gpt-6-astra") {
registerTools {
tool(testWeatherTool)
}
toolExecutionConfig { toolName ->
println("Executing $toolName")
}
inputText("Where is weather like in London?")
}
println(response.outputText)Content copied to clipboard