A macOS SwiftUI application demonstrating how to build chatbot interfaces that connect to vLLM inference servers, and Llama Stack, using multiple HTTP client approaches. This sample project showcases best practices for integrating various Swift HTTP libraries that support both OpenAI-compatible and Llama-Stack APIs.
- Features
- Architecture
- Requirements
- Installation
- Usage
- API Implementations
- Documentation
- Testing
- Contributing
- Acknowledgments
- π Multiple HTTP Client Implementations: Compare 5 different approaches to API integration
- π Real-time Streaming: Live chat responses with @Observable pattern
- πΎ Persistent Server Configuration: SwiftData-based server management
- π― Modern SwiftUI: Native macOS interface with NavigationSplitView
- π Complete Documentation: DocC documentation with examples
- π§ͺ Comprehensive Testing: Unit and UI tests for all components
- π‘ TipKit Integration: User guidance and onboarding
vLLM accepts inference requests using these REST API endpoints:
- OpenAI-compatible API: Standard Chat Completions format
Llama Stack accepts inference requests using these REST API endpoints:
- OpenAI-compatible API: Standard Chat Completions format
- Llama-Stack API: Native Llama-Stack protocol
- LlamaStackChatViewModel - Official Llama-Stack Swift client
- SwiftOpenAIChatViewModel - SwiftOpenAI library
- MacPawOpenAIChatViewModel - MacPaw/OpenAI library
- AlamoFireChatViewModel - Alamofire HTTP client
- FoundationChatViewModel - Native URLSession
- Xcode: Version 16.3 or later (Mac App Store or Apple Developer)
- macOS: 15.0 (Sequoia) or later
- Apple Developer Account: Optional for device deployment
-
Llama-Stack Server: For native Llama-Stack API testing.
- Setup guide: Llama-Stack Documentation
- vLLM integration: vLLM with Llama-Stack
-
OpenAI-Compatible Server: For Chat Completions API testing
- vLLM: Open source inference server (Documentation)
- Llama Stack: Offers OpenAI-compatible Chat Completions endpoint. Llama-Stack Documentation
- Local Options: LM Studio, AnythingLLM, Ollama
- Cloud Options: Use an OpenAI-compatible Chat Completions endpoint of your choice.
git clone https://github.com/RichNasz/vLLMSwiftApp.git
cd vLLMSwiftAppOpen the project in Xcode:
- Navigate to the cloned folder in Finder and double-click
vLLMSwiftApp.xcodeproj - Or in Xcode: File β Open and select the project file
- In Xcode: Integrate β Clone...
- Enter repository URL:
https://github.com/RichNasz/vLLMSwiftApp.git - Select the
mainbranch and click Clone - Choose destination directory and click Clone
-
Enable OpenAPIGenerator Extension
- When prompted during first build, select "Trust & Enable"
- Required for SDK code generation
-
Configure Developer Account
- Xcode β Settings β Accounts
- Add your Apple Developer account (free account sufficient)
- Clean Build Folder: Product β Clean Build Folder (β+Shift+K)
- Build Project: Product β Build (β+B)
- Run Application: Product β Run (β+R)
- Launch the application
- Navigate to Server List in the sidebar
- Click + to add a new server
- Configure server details:
- Name: Unique identifier
- Base URL: Your vLLM server endpoint
- API Type: OpenAI or Llama-Stack
- API Key: Optional authentication
- Model: Model identifier
- Select a chat implementation from the sidebar
- Choose your configured server
- Start chatting with real-time streaming responses
- File:
LlamaStackChatViewModel.swift - Library: Official Llama-Stack Swift client
- Best For: Native Llama-Stack protocol integration
- File:
SwiftOpenAIChatViewModel.swift - Library: SwiftOpenAI (4.1.1)
- Best For: Comprehensive OpenAI API support
- File:
MacPawOpenAIChatViewModel.swift - Library: MacPaw/OpenAI (main branch)
- Best For: Lightweight OpenAI integration
- File:
AlamoFireChatViewModel.swift - Library: Alamofire (5.10.2)
- Best For: Custom HTTP client implementations
- File:
FoundationChatViewModel.swift - Library: Native URLSession
- Best For: No external dependencies
Product β Build Documentation in Xcode
Help β Developer Documentation in Xcode
The project includes comprehensive DocC documentation covering:
- Architecture overview
- API integration patterns
- Code examples and best practices
Product β Test (β+U) in Xcode
- Unit Tests: ViewModel functionality and API integration
- UI Tests: Navigation and interface interactions
- Test Files: Located in
vLLMSwiftAppTests/
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow existing SwiftUI and MVVM patterns
- Add DocC documentation for new public APIs
- Include unit tests for new functionality
- Maintain consistency with existing code style
This project builds upon excellent open source libraries and frameworks:
- Llama-Stack - Meta's comprehensive inference stack
- Alamofire - Elegant HTTP networking in Swift
- SwiftOpenAI - Swift package for OpenAI API
- MacPaw/OpenAI - Swift client for OpenAI and Azure OpenAI
- vLLM - High-throughput LLM inference engine
This project is available under the MIT License. See the LICENSE file for more information.
Note: This is sample code for educational and demonstration purposes. Ensure proper security practices when deploying to production environments.