Skip to content

Commit 4deb851

Browse files
committed
chore: perplexity flutter mdx refine
1 parent 5a67d11 commit 4deb851

File tree

1 file changed

+32
-166
lines changed

1 file changed

+32
-166
lines changed

docs/showcase/perplexity-flutter.mdx

Lines changed: 32 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ keywords: [Perplexity, Flutter, Dart, SDK, API, streaming, chat-completions, son
99

1010
Comprehensive toolkit for integrating Perplexity's AI capabilities into Dart and Flutter applications. Includes a lightweight core API client (`perplexity_dart`) and Flutter widgets (`perplexity_flutter`) with BLoC state management.
1111

12-
## Features
12+
## What It Does
1313

1414
- **Type-safe API Client** - Fully typed models with compile-time safety
1515
- **Streaming & Non-streaming** - Real-time chat completions with streaming support
@@ -20,177 +20,43 @@ Comprehensive toolkit for integrating Perplexity's AI capabilities into Dart and
2020
- **Cross-platform** - iOS, Android, Web, Desktop support
2121
- **Future-proof** - Custom model string support for new Perplexity releases
2222

23-
## Prerequisites
24-
25-
- Dart SDK 2.17.0+
26-
- Flutter SDK 3.0.0+ (for Flutter features)
27-
- [Perplexity API Key](https://www.perplexity.ai/settings/api)
28-
29-
## Installation
30-
31-
```bash
32-
# For Dart projects
33-
dart pub add perplexity_dart
34-
35-
# For Flutter projects
36-
flutter pub add perplexity_flutter
37-
```
38-
39-
## Usage
40-
41-
### Flutter Widgets (Quick Start)
42-
43-
```dart
44-
import 'package:flutter/material.dart';
45-
import 'package:perplexity_flutter/perplexity_flutter.dart';
46-
47-
void main() => runApp(MaterialApp(
48-
home: ChatWrapperWidget(
49-
apiKey: 'your-api-key',
50-
model: PerplexityModel.sonarPro,
51-
child: Scaffold(
52-
appBar: AppBar(title: Text('AI Chat')),
53-
body: Column(children: [
54-
Expanded(child: PerplexityChatView()),
55-
PerplexityChatInput(),
56-
]),
57-
),
58-
),
59-
));
60-
```
61-
62-
### Core API Client
63-
64-
```dart
65-
import 'package:perplexity_dart/perplexity_dart.dart';
66-
67-
final client = PerplexityClient(apiKey: 'your-api-key');
68-
69-
// Simple chat
70-
final response = await client.sendMessage(
71-
requestModel: ChatRequestModel(
72-
model: PerplexityModel.sonarPro,
73-
messages: [
74-
StandardMessageModel(role: MessageRole.user, content: 'Hello AI'),
75-
],
76-
),
77-
);
78-
print('Response: ${response.content}');
79-
80-
// Streaming
81-
final stream = client.streamChat(requestModel: ChatRequestModel(
82-
model: PerplexityModel.sonar,
83-
messages: messages,
84-
stream: true,
85-
));
86-
87-
await for (final chunk in stream) {
88-
print('Chunk: $chunk');
89-
}
90-
```
91-
92-
### Image Analysis
93-
94-
```dart
95-
// Single image
96-
final request = ChatRequestModel.defaultImageRequest(
97-
urlList: ['https://example.com/image.jpg'],
98-
imagePrompt: 'Describe this image',
99-
model: PerplexityModel.sonarPro,
100-
);
101-
102-
// Multiple images
103-
final multiRequest = ChatRequestModel.defaultImageRequest(
104-
urlList: [
105-
'https://example.com/photo1.jpg',
106-
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...'
107-
],
108-
imagePrompt: 'Compare these images',
109-
);
110-
111-
final response = await client.sendMessage(requestModel: request);
112-
```
113-
114-
### Advanced Configuration
115-
116-
```dart
117-
final requestModel = ChatRequestModel(
118-
model: PerplexityModel.sonar,
119-
messages: messages,
120-
temperature: 0.7, // Creativity (0.0-2.0)
121-
topP: 0.9, // Nucleus sampling
122-
searchDomainFilter: ['nature.com'], // Limit sources
123-
returnRelatedQuestions: true, // Follow-up suggestions
124-
searchRecencyFilter: 'month', // Time filter
125-
maxTokens: 1000,
126-
);
127-
```
128-
129-
## Code Explanation
130-
131-
### Architecture
23+
## How It Uses Perplexity
24+
25+
**Core API Integration:**
26+
- Type-safe client with all Perplexity models (Sonar, Sonar Pro, Deep Research, Reasoning)
27+
- Streaming and non-streaming chat completions
28+
- Multimodal processing with flexible MessagePart system for text + images
29+
30+
**Flutter Widget Layer:**
31+
- `ChatWrapperWidget` for BLoC state management
32+
- `PerplexityChatView` for real-time message display
33+
- `PerplexityChatInput` for user interaction handling
34+
35+
## For Flutter Developers
36+
37+
Built specifically for the Flutter community to accelerate AI integration:
38+
39+
- **Rapid Prototyping** - Get AI chat functionality running in minutes, not hours
40+
- **Production Ready** - Type-safe models, proper error handling, and state management
41+
- **Community Driven** - Open source packages with active maintenance and contributions welcome
42+
- **Flutter-First Design** - Native BLoC integration, platform-optimized widgets, cross-platform support
43+
44+
## Architecture
13245

13346
**Two-layer design:**
134-
1. **Core (`perplexity_dart`)** - Pure Dart API client
135-
2. **UI (`perplexity_flutter`)** - Flutter widgets + BLoC state management
136-
137-
### Multimodal Processing
138-
139-
Uses flexible message parts for combining text and images:
140-
141-
```dart
142-
final message = ImageMessageModel(
143-
role: MessageRole.user,
144-
content: [
145-
TextPart(text: 'Analyze these images'),
146-
ImagePart(url: 'https://example.com/image1.jpg'),
147-
ImagePart(url: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgA...'),
148-
],
149-
);
150-
```
151-
152-
### Available Models
153-
154-
```dart
155-
PerplexityModel.sonar // 128K tokens - Fast queries
156-
PerplexityModel.sonarPro // 200K tokens - Enhanced
157-
PerplexityModel.sonarDeepResearch // 128K tokens - Research
158-
PerplexityModel.sonarReasoning // 128K tokens - Complex reasoning
159-
PerplexityModel.sonarReasoningPro // 128K tokens - Advanced reasoning
160-
```
161-
162-
### Error Handling
163-
164-
```dart
165-
try {
166-
final response = await client.sendMessage(requestModel: request);
167-
} on PerplexityException catch (e) {
168-
print('API Error: ${e.message} (${e.statusCode})');
169-
} catch (e) {
170-
print('Error: $e');
171-
}
172-
```
173-
174-
## Links
47+
- **Core (`perplexity_dart`)** - Pure Dart API client for all platforms
48+
- **UI (`perplexity_flutter`)** - Flutter widgets + BLoC state management
49+
50+
Uses flexible MessagePart system for multimodal content combining text and images.
51+
52+
## Key Links
17553

17654
**Packages:**
17755
- [perplexity_dart on pub.dev](https://pub.dev/packages/perplexity_dart) | [GitHub](https://github.com/vishnu32510/perplexity_dart)
17856
- [perplexity_flutter on pub.dev](https://pub.dev/packages/perplexity_flutter) | [GitHub](https://github.com/vishnu32510/perplexity_flutter)
17957

180-
**Resources:**
181-
- [Flutter Examples](https://github.com/vishnu32510/perplexity_dart/tree/main/example_flutter_app)
58+
**Examples:**
59+
- [Flutter Example App](https://github.com/vishnu32510/perplexity_dart/tree/main/example_flutter_app)
18260
- [Dart Examples](https://github.com/vishnu32510/perplexity_dart/tree/main/example)
183-
- [Perplexity API Docs](https://docs.perplexity.ai/)
184-
185-
**Contributing:** Issues and PRs welcome on both [perplexity_dart](https://github.com/vishnu32510/perplexity_dart/issues) and [perplexity_flutter](https://github.com/vishnu32510/perplexity_flutter/issues) repositories.
186-
187-
## Limitations
188-
189-
- **API Rate Limits** - Implement rate limiting for production use
190-
- **Image Formats** - Base64, data URI, HTTPS URLs supported; local files need conversion
191-
- **Context Windows** - 128K-200K token limits per model
192-
- **API Key Security** - Store securely; avoid hardcoding in client apps
193-
- **Streaming Dependencies** - Requires WebSocket support on target platforms
194-
- **Flutter Web** - Limited file operations in web environments
19561

196-
**Production Tips:** Implement API key rotation, retry logic, caching strategies, usage monitoring, and proper error boundaries.
62+
**Contributing:** Issues and PRs welcome on both repositories.

0 commit comments

Comments
 (0)