ai_prompt_kit ๐Ÿค–โœจ

A Flutter-friendly AI helper package for calling LLM / AI APIs using prompt templates, clean abstractions, and safe response handling.

This package is designed to make AI integration in Flutter simple, readable, and production-ready.


โœจ Features

  • ๐Ÿ”Œ OpenAI-compatible REST API support\
  • ๐Ÿง  PromptTemplate system (variable-based prompts)\
  • ๐ŸŒ Multi-language support via AiLanguage
  • ๐Ÿ”Ž Auto language detection\
  • ๐Ÿ“Š Token usage tracking\
  • โš ๏ธ Graceful error handling (no crashes)\
  • ๐ŸŽฏ UI-agnostic\
  • ๐Ÿš€ Production-ready example app

๐Ÿ“ฆ Installation

Add to your pubspec.yaml:

dependencies:
  ai_prompt_kit: ^0.1.0

Then run:

flutter pub get

๐Ÿš€ Quick Start

1๏ธโƒฃ Initialize the AI Client

final aiClient = AiClient(
  AiConfig(
    apiKey: "YOUR_API_KEY",
    baseUrl: "https://api.openai.com/v1",
  ),
);

โš ๏ธ Never hardcode API keys in production apps.
Use environment variables or a backend proxy.


๐Ÿง  Using PromptTemplate

final prompt = PromptTemplate(
  template: "Summarize the following text:\n{text}",
  variables: {
    "text": "Flutter packages help developers share reusable components.",
  },
  language: AiLanguage.chinese,
);

final response = await aiClient.run(prompt);

if (response.hasError) {
  print(response.error);
} else {
  print(response.text);
  print("Tokens used: ${response.tokens}");
}

๐ŸŒ Language Control

Force response language:

language: AiLanguage.bengali
language: AiLanguage.chinese
language: AiLanguage.arabic

Enable automatic detection:

await aiClient.complete(
  prompt: userInput,
  autoDetectLanguage: true,
);

๐Ÿ“Š AI Response Model

class AiResponse {
  final String text;
  final int? tokens;
  final String? error;

  bool get hasError => error != null;
}

โš ๏ธ Error Handling

Handled scenarios:

  • Missing API key\
  • Invalid API key (401)\
  • Network failures\
  • Invalid AI response\
  • Unexpected API errors

๐Ÿ” Security Best Practice

Recommended architecture:

Flutter App โ†’ Your Backend โ†’ OpenAI

Instead of:

Flutter App โ†’ OpenAI directly


๐Ÿ›ฃ๏ธ Roadmap

  • ๐ŸŒŠ Streaming responses\
  • ๐Ÿงพ Structured JSON output mode\
  • ๐Ÿง  System + User role messaging\
  • ๐Ÿ”„ Multi-provider support\
  • ๐Ÿ“ฆ Built-in AI presets

๐Ÿ‘จโ€๐Ÿ’ป Project Maintainer โค๏ธ

<p align="center">

<a href="https://github.com/hamidhosen42">{=html} <img src="https://github.com/hamidhosen42.png" width="140" alt="Md. Hamid Hosen"/>{=html} </a>{=html}

</p>
<p align="center">

<a href="https://github.com/hamidhosen42">{=html} <strong>{=html}Md. Hamid Hosen</strong>{=html} </a>{=html}

</p>
<p align="center">

AI Engineer โ€ข Flutter Developer โ€ข LLM Systems Researcher

</p>

๐Ÿ“„ License

MIT License