Chat Basics Chat Basics

Core OpenAI integration

Interactive form to generate AI responses with customizable prompts, system messages, and model parameters.
Foundation demo from the Scrimba course.

← Back to Home

Interactive Demo

The main question or instruction for the AI
Sets the behavior and context for the AI assistant
Maximum response length
Creativity level (0-2)

Code Example

// OpenAI Chat Completion Integration
val openAI = OpenAI(apiKey = "your-openai-api-key")

val response = openAI.createChatCompletion(
    prompt = "Explain machine learning",
    systemMessage = "You are a helpful assistant",
    model = "gpt-3.5-turbo",
    maxTokens = 300,
    temperature = 0.7
)

println("Response: ${response.text()}")
println("Usage: ${response.usage()}")

openAI.close()