Automatic Device Fallbacks
Ensure reliable AI operations with FreeToken's intelligent fallback system that automatically handles device limitations and failures.
Overview
FreeToken's automatic fallback system ensures your AI features work reliably across all devices and conditions. When a device can't handle local AI processing due to memory constraints, model incompatibility, or other limitations, FreeToken automatically falls back to cloud processing without interrupting the user experience.
How It Works
If the device is not capable of running AI models locally due to hardware limitations, FreeToken detects this and seamlessly switches to the equivalent cloud-based AI model. This ensures that users always have access to AI features, regardless of their device's capabilities.
⚠️ Caution: Run Location Settings
If you explicitly set the runLocation to .local when running AI, FreeToken will not perform automatic fallbacks to cloud processing. In such cases, if the local device cannot handle the AI processing, an error will be thrown. To leverage automatic fallbacks, set the run location to .automatic.
Run Message Thread
import FreeToken
// Assumes FreeToken is properly configured
// Automatically chooses location of run.
FreeToken.shared.runMessageThread(
id: "example-thread-id",
runLocation: .automatic, // Defaults to .automatic if omitted
success: { result in
print("AI Response: \(result.content)")
},
error: { error in
print("Error running message thread: \(error.localizedDescription)")
}
)
Generate Completion
When generating completions, use the method generateCompletion over generateLocalCompletion to enable automatic fallbacks.
import FreeToken
// Assumes FreeToken is properly configured
// Automatically chooses location of run.
FreeToken.shared.generateCompletion(
prompt: "Explain the theory of relativity in simple terms.",
success: { result in
print("AI Response: \(result.response)")
},
error: { error in
print("Error generating completion: \(error.localizedDescription)")
}
)