Skip to content

Sanaullah49/ai_kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Kit

pub package License: MIT

Build AI-powered Flutter apps in minutes, not days.

AI Kit is the missing AI integration layer for Flutter. Drop in a complete chat UI, connect any AI provider, and ship AI features with 3 lines of code.

πŸ“Έ Screenshots

Light Theme Chat Β Β  Dark Theme Chat Β Β  Custom Themed Chat

Multi-Provider Support

✨ Features

  • πŸ”Œ Multi-provider β€” OpenAI, Gemini, Claude (swap with one line)
  • πŸ’¬ Complete Chat UI β€” Streaming responses, typing indicators, theming
  • 🎨 Fully customizable β€” Themes, custom bubbles, custom input
  • πŸ”„ Auto retry & failover β€” Automatic retries, multi-provider failover
  • πŸ’° Usage tracking β€” Token counts and cost estimation
  • πŸ’Ύ Conversation memory β€” Buffer, sliding window, or persistent storage
  • πŸ“ Smart text field β€” AI-powered autocomplete suggestions
  • πŸ–ΌοΈ Multi-modal β€” Send images with messages
  • πŸ› οΈ Function calling β€” Let AI call your Dart functions
  • 🌐 All platforms β€” Android, iOS, Web, macOS, Windows, Linux

πŸš€ Quick Start

Installation

dependencies:
  ai_kit: ^0.1.0

3 Lines to AI Chat

import 'package:ai_kit/ai_kit.dart';

// 1. Initialize with your provider
AIKit.init(providers: [OpenAIProvider(apiKey: 'sk-...')]);

// 2. Drop in the chat widget
AIChatView(systemPrompt: 'You are a helpful assistant')

// That's it! Full streaming chat UI. πŸŽ‰

πŸ“– Usage

Simple Question & Answer

final aiKit = AIKit.init(
  providers: [OpenAIProvider(apiKey: 'your-key')],
);

final answer = await aiKit.ask('What is Flutter?');
print(answer);

Full Chat Screen

Scaffold(
  appBar: AppBar(title: Text('AI Chat')),
  body: AIChatView(
    systemPrompt: 'You are a friendly coding assistant.',
    suggestions: [
      'Explain async/await',
      'Write a REST API client',
      'Debug my code',
    ],
    showUsage: true,
    theme: AIChatTheme.dark(),
    onResponse: (response) {
      print('Tokens: ${response.usage?.totalTokens}');
    },
  ),
)

Multi-Provider with Failover

AIKit.init(
  providers: [
    OpenAIProvider(apiKey: 'sk-...'),
    GeminiProvider(apiKey: 'AI...'),
    ClaudeProvider(apiKey: 'sk-ant-...'),
  ],
  defaultProvider: 'OpenAI',
);

// Automatically tries next provider if one fails
final response = await AIKit.instance.chatWithFailover(
  [AIMessage.user('Hello!')],
);

Streaming

await for (final response in AIKit.instance.chatStream([
  AIMessage.system('You are a poet.'),
  AIMessage.user('Write a haiku about Flutter'),
])) {
  print(response.text); // Updates incrementally
}

Switch Providers

// Creative writing with Claude
await AIKit.instance.ask('Write a poem', provider: 'Claude');

// Code with GPT
await AIKit.instance.ask('Write a sort function', provider: 'OpenAI');

// Free tier with Gemini
await AIKit.instance.ask('Summarize this', provider: 'Gemini');

Smart AI Text Field

AITextField(
  label: 'Email Subject',
  hint: 'Start typing for AI suggestions...',
  maxSuggestions: 3,
  onSuggestionSelected: (text) => print('Selected: $text'),
)

Custom Theme

AIChatView(
  theme: AIChatTheme(
    primaryColor: Colors.purple,
    backgroundColor: Color(0xFF1A1A2E),
    userBubbleColor: Colors.purple,
    aiBubbleColor: Color(0xFF2D2D4E),
    userTextColor: Colors.white,
    aiTextColor: Colors.white,
    textColor: Colors.white,
    secondaryTextColor: Colors.white54,
    inputBackgroundColor: Color(0xFF0F3460),
    inputBorderColor: Color(0xFF533483),
    errorColor: Colors.redAccent,
    showTimestamp: true,
    showProviderLabel: true,
  ),
)

Conversation Memory

// Simple buffer
final memory = BufferMemory(maxMessages: 50);

// Token-aware window
final memory = SlidingWindowMemory(
  maxTokens: 4000,
  systemMessage: AIMessage.system('Be helpful'),
);

// Persistent (survives app restart)
final memory = PersistentMemory(conversationId: 'main_chat');
await memory.load();

πŸ—οΈ Supported Providers

Provider Class Models
OpenAI OpenAIProvider GPT-4o, GPT-4o-mini, GPT-4-turbo, o1
Google Gemini GeminiProvider Gemini 2.0 Flash, 1.5 Pro, 1.5 Flash
Anthropic Claude ClaudeProvider Claude Sonnet 4, Opus 4, 3.5 Haiku

Using Azure OpenAI or Custom Endpoints

OpenAIProvider(
  apiKey: 'your-key',
  baseUrl: 'https://your-resource.openai.azure.com/openai/deployments/your-model',
  customHeaders: {'api-key': 'your-azure-key'},
)

πŸ“Š Usage Tracking

print(AIKit.instance.totalRequests);  // 42
print(AIKit.instance.totalTokens);    // 15230
print(AIKit.instance.totalCost);      // 0.0234
print(AIKit.instance.usageStats);     // Full summary map

β˜• Support

If this package saves you time, consider buying me a coffee!

Buy Me A Coffee

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

MIT License - see LICENSE for details.


Made with ❀️ for the Flutter community

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors