ai_prompt_kit 0.1.1
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\
- ๐ง
PromptTemplatesystem (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
Associate Software Engineer @P2M Soft
๐ License #
MIT License
