For a more interactive experience, you can stream responses:
Copy
try await client.makeStreamingModelCall( using: .openAI(.gpt4o), messages: [ Message(role: .user, content: "Write a short story about a robot learning to paint") ], onUpdate: { partialResponse in // Update your UI with each chunk of the response print(partialResponse.text, terminator: "") }, onComplete: { finalResponse in // Handle the complete response print("\nFinal response received!") })
// When making a direct calllet response = try await client.makeModelCall( using: .openAI(.gpt4o, temperature: 0.7), // Higher for more creative, lower for more deterministic messages: messages)// Or when configuring the clientlet client = CompilerClient( appID: UUID(uuidString: "YOUR_COMPILER_APP_ID")!, configuration: CompilerClient.Configuration( streamingChat: .anthropic(.claudeSonnet, temperature: 0.7) ))
Set the behavior of the model with system messages:
Copy
let response = try await client.makeModelCall( using: .openAI(.gpt4o), messages: [ Message(role: .system, content: "You are a helpful assistant that specializes in explaining complex topics in simple terms."), Message(role: .user, content: "Explain how blockchain works") ])
You can update the client’s configuration at any time:
Copy
// Update the streaming chat configurationawait client.updateStreamingChat { config in // Switch to a different model config = .anthropic(.claudeHaiku)}// Create an immutable streaming session with current configurationlet streamingSession = await client.makeStreamingSession()
public enum OpenAIModel: String, Codable { case gpt4o = "chatgpt-4o-latest" case gpt4oMini = "gpt-4o-mini" case o1 = "o1" case o1Mini = "o1-mini" case o3Mini = "o3-mini"}
public enum AnthropicModel: String, Codable { case claudeSonnet = "claude-3-5-sonnet-latest" case claudeHaiku = "claude-3-5-haiku-latest" case claudeOpus = "claude-3-5-opus-latest"}
public enum GeminiModel: String, Codable { case flash = "gemini-2.0-flash" case flashLitePreview = "gemini-2.0-flash-lite-preview-02-05" case flash15 = "gemini-1.5-flash" case flash15_8b = "gemini-1.5-flash-8b" case pro15 = "gemini-1.5-pro" case textEmbedding = "text-embedding-004"}