A simple iOS chat application built with SwiftUI that integrates with OpenAI's GPT-4 API using Server-Side Events for real-time streaming responses.
- 🎨 iMessage-style chat bubbles - Beautiful, rounded chat bubbles with proper alignment
- 📱 Native iOS interface - Clean, modern UI that feels native to iOS
- ⚡ Real-time streaming - Uses Server-Side Events for smooth, real-time GPT responses
- 🎯 Smart scrolling - Auto-scrolls to show new messages with smooth animations
- ⌨️ Keyboard-friendly - Responsive text input with proper keyboard handling
-
Get your OpenAI API Key
- Go to OpenAI Platform
- Create a new API key
- Copy the key
-
Configure the app
- Open
GPTClientApp/Config.swift
- Replace
"YOUR_API_KEY_HERE"
with your actual OpenAI API key:
static let openAIAPIKey = "sk-your-actual-api-key-here"
- Open
-
Build and Run
- Open the project in Xcode
- Select your target device or simulator
- Press
Cmd + R
to build and run
The app is structured with the following components:
ChatMessage
- Data model for chat messagesChatBubbleView
- SwiftUI view for individual chat bubblesOpenAIService
- Service class handling OpenAI API communication with SSEContentView
- Main chat interface with message list and input fieldConfig
- Configuration constants including API key
- iOS 14.0+
- Xcode 12.0+
- Valid OpenAI API key with GPT-4 access
- Launch the app
- Type your message in the text field at the bottom
- Tap the send button (paper plane icon)
- Watch as GPT-4 responds in real-time with streaming text
- Continue the conversation!
The app uses OpenAI's Chat Completions API with the following configuration:
- Model:
gpt-4
- Streaming: Enabled (Server-Side Events)
- Max tokens: 1500
Make sure to keep your API key secure and never commit it to version control. Consider using environment variables or secure keychain storage for production apps.