public struct LLMGenerationResult: Sendable { public let text: String // Generated text public let thinkingContent: String? // Reasoning tokens (for thinking models) public let inputTokens: Int // Prompt tokens public let tokensUsed: Int // Total output tokens public let modelUsed: String // Model ID public let latencyMs: TimeInterval // Total generation time public let framework: String? // Backend framework used public let tokensPerSecond: Double // Generation speed public let timeToFirstTokenMs: Double? // Time to first token public let thinkingTokens: Int? // Reasoning token count public let responseTokens: Int // Response token count}
let result = try await RunAnywhere.generate( "Write a creative story about a robot", options: LLMGenerationOptions( maxTokens: 500, temperature: 1.2, // More creative topP: 0.9, stopSequences: ["THE END"] ))
let result = try await RunAnywhere.generate( "What should I cook tonight?", options: LLMGenerationOptions( maxTokens: 200, systemPrompt: "You are a professional chef. Suggest creative recipes with detailed instructions." ))
Some models output their reasoning process. Extract it with thinkingContent:
let result = try await RunAnywhere.generate( "Solve: If a train travels 60 mph for 2 hours, how far does it go?", options: LLMGenerationOptions(maxTokens: 300))// The main responseprint("Answer: \(result.text)")// The model's reasoning (if available)if let thinking = result.thinkingContent { print("Reasoning: \(thinking)")}// Token breakdownif let thinkingTokens = result.thinkingTokens { print("Thinking tokens: \(thinkingTokens)")}print("Response tokens: \(result.responseTokens)")
do { let result = try await RunAnywhere.generate(prompt, options: options) print(result.text)} catch let error as SDKError { switch error.code { case .notInitialized: print("SDK not initialized") case .modelNotFound: print("Model not loaded") case .generationFailed: print("Generation failed: \(error.message)") case .contextTooLong: print("Prompt too long for model's context window") default: print("Error: \(error.localizedDescription)") }}