Easybeam Swift SDK is a powerful and flexible library for integrating Easybeam AI functionality into your iOS applications. This SDK provides seamless access to Easybeam's AI-powered chat and workflow capabilities, supporting both streaming and non-streaming interactions.
- Portal and Workflow Integration: Easily interact with Easybeam portals and workflows.
- Streaming Support: Real-time streaming of AI responses for interactive experiences.
- Non-Streaming Requests: Traditional request-response pattern for simpler interactions.
- Flexible Configuration: Customize the SDK behavior to fit your application needs.
- Error Handling: Robust error handling for reliable integration.
- Review Submission: Built-in functionality to submit user reviews.
You can add Easybeam Swift SDK to an Xcode project by adding it as a package dependency.
- From the File menu, select Add Packages...
- Enter "https://github.com/easybeamai/easybeam-swift" into the package repository URL text field
- Click Add Package
First, import the package and create an instance of EasyBeam:
import easybeam_swift
let config = EasyBeamConfig(token: "your_api_token_here")
let easybeam = EasyBeam(config: config)
To start a streaming interaction with a portal:
let stream = easybeam.streamPortal(
portalId: "your_portal_id",
filledVariables: ["key": "value"],
messages: [
ChatMessage(
content: "Hello, AI!",
role: .user,
createdAt: ChatMessage.getCurrentTimestamp(),
id: "1"
)
]
)
for try await response in stream {
print("New message: \(response.newMessage.content)")
}
For a simple request-response interaction:
do {
let response = try await easybeam.getPortal(
portalId: "your_portal_id",
filledVariables: ["key": "value"],
messages: [
ChatMessage(
content: "Hello, AI!",
role: .user,
createdAt: ChatMessage.getCurrentTimestamp(),
id: "1"
)
]
)
print("AI response: \(response.newMessage.content)")
} catch {
print("Error: \(error)")
}
To submit a review for a chat interaction:
do {
try await easybeam.review(
chatId: "your_chat_id",
userId: "user123",
reviewScore: 5,
reviewText: "Great experience!"
)
print("Review submitted successfully")
} catch {
print("Error submitting review: \(error)")
}
You can inject a custom URLSession for more control over network requests:
let customSession = URLSession(configuration: .default)
easybeam.injectUrlSession(customSession)
The SDK provides detailed error messages through the EasyBeamError
enum. Always use proper error handling with do-catch blocks or handle errors in your async sequences.
- Ensure you have a valid Easybeam API token before using the SDK.
- The SDK uses
AsyncSequence
for streaming, which requires iOS 15.0 or later. - For production applications, consider implementing proper token management and security practices.
Contributions to the Easybeam Swift SDK are welcome! Please refer to the contributing guidelines for more information.
This project is licensed under the MIT License - see the LICENSE file for details.
For support, please contact hello@easybeam.ai or visit our documentation.