smartchat_flutter 0.0.5
A Flutter package to easily integrate OpenAI's GPT-based chat functionality into your apps.
It looks like there might be a formatting issue when copying and pasting. Here's a cleaned-up version without the formatting issues:
SmartChat Flutter
smartchat_flutter is a highly customizable and easy-to-use Flutter package that enables developers to integrate a smart chat interface powered by OpenAI's GPT models into their Flutter applications. The package provides a ready-made chat UI and handles interaction with the GPT API, allowing you to create intelligent conversational agents with minimal effort.
Features
- Customizable Chat Interface: Style the chat bubbles, app bar, and input field to match your app’s theme.
- Real-time Streaming: Stream messages from the AI in real-time, simulating natural typing behavior.
- Auto Scrolling: The chat interface automatically scrolls with new messages for a seamless user experience.
- Easy Integration: Integrate GPT-based chat into your app with minimal code.
- Supports GPT-3.5-turbo: Designed to work with OpenAI’s GPT-3.5-turbo model by default, with support for other models.
- Flexible Chatbots: Create adaptable chatbots for various applications by setting specific system prompts.
Installation
Add smartchat_flutter to your pubspec.yaml:
dependencies:
smartchat_flutter: ^0.0.4
Usage
To get started with smartchat_flutter, use the following example code:
import 'package:flutter/material.dart';
import 'package:smartchat_flutter/smartchat_flutter.dart';
import 'package:smartchat_flutter/services/chatgpt_service.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyChatScreen(),
);
}
}
class MyChatScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final chatGPTService = ChatGPTService(
apiKey: 'your-openai-api-key',
systemPrompt: 'You are a helpful assistant that provides information about diet, food, workout, and its nutritional facts. Focus your responses on these topics. Do not provide any other information.',
temperature: 0.5, // Custom temperature setting
maxTokens: 1500, // Custom max tokens
model: 'gpt-4', // Specify a different model if needed
);
return SmartChatScreen(
chatGPTService: chatGPTService,
appBarTitle: 'Health Chatbot',
textFieldHint: 'Ask your question...',
userBubbleDecoration: BoxDecoration(
color: Colors.blueAccent, // Custom user bubble color
borderRadius: BorderRadius.all(Radius.circular(12)),
),
botBubbleDecoration: BoxDecoration(
color: Colors.grey[300], // Custom bot bubble color
borderRadius: BorderRadius.all(Radius.circular(12)),
),
);
}
}
Demo
API Documentation
ChatGPTService
-
ChatGPTService: Manages interaction with the OpenAI GPT model.Constructor:
ChatGPTService({required String apiKey, required String systemPrompt, double temperature = 0.5, int maxTokens = 1500, String model = 'gpt-4'})
Methods:
Stream<String> streamMessages(String message): Streams responses from the GPT model in real-time.
SmartChatScreen
-
SmartChatScreen: A widget that provides a chat interface integrated with GPT.Constructor:
SmartChatScreen({required ChatGPTService chatGPTService, String appBarTitle = 'Chat', String textFieldHint = 'Ask something...', BoxDecoration userBubbleDecoration = const BoxDecoration(), BoxDecoration botBubbleDecoration = const BoxDecoration()})
Parameters:
chatGPTService: An instance ofChatGPTService.appBarTitle: Title for the AppBar.textFieldHint: Hint text for the text field.userBubbleDecoration: Decoration for user messages.botBubbleDecoration: Decoration for bot messages.
Configuration
Configure the ChatGPTService with your OpenAI API key and customize the chat behavior by adjusting parameters like systemPrompt, temperature, maxTokens, and model.
Contributing
To contribute to this project, fork the repository and create a pull request with your changes. Please ensure your code adheres to the project's coding standards and includes appropriate tests.