ai_prompt_kit 0.1.1 copy "ai_prompt_kit: ^0.1.1" to clipboard
ai_prompt_kit: ^0.1.1 copied to clipboard

A Flutter-friendly AI helper package for calling LLM APIs using prompt templates and structured responses.

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.1

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 โค๏ธ #

Md. Hamid Hosen

Md. Hamid Hosen
Associate Software Engineer @P2M Soft


๐Ÿ“„ License #

MIT License

0
likes
150
points
72
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter-friendly AI helper package for calling LLM APIs using prompt templates and structured responses.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, http

More

Packages that depend on ai_prompt_kit