ai_prompt_kit 0.0.1 copy "ai_prompt_kit: ^0.0.1" to clipboard
ai_prompt_kit: ^0.0.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-style REST API support
  • 🧠 PromptTemplate system (variable-based prompts)
  • πŸ“¦ Clean AI client abstraction
  • ⚠️ Graceful error handling (no crashes)
  • 🎯 UI-agnostic (works with any Flutter app)
  • πŸš€ pub.dev–ready example app

πŸ“¦ Installation #

Add this to your pubspec.yaml:

dependencies:
  ai_prompt_kit: ^0.0.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",
  ),
);

⚠️ Do not hardcode API keys in packages.
Pass the key from your app or environment.


2️⃣ Simple Prompt Completion #

final response = await aiClient.complete(
  prompt: "Explain Flutter packages in simple words",
);

if (response.hasError) {
  print(response.error);
} else {
  print(response.text);
}

🧠 PromptTemplate (Key Feature) #

PromptTemplate allows you to create reusable prompts using variables instead of string concatenation.

Example: Summarization Prompt #

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

final response = await aiClient.run(prompt);

if (response.hasError) {
  print(response.error);
} else {
  print(response.text);
}

βœ”οΈ Why use PromptTemplate? #

  • Cleaner prompt construction
  • Easy variable replacement
  • Reusable & maintainable prompts
  • Ideal for production AI systems

πŸ“Š AI Response Model #

All AI calls return an AiResponse object.

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

  bool get hasError => error != null;
}

⚠️ Error Handling (No Crashes) #

Handled cases:

  • Missing API key
  • Invalid API key (401)
  • Network failures
  • Invalid or empty AI responses

Example error message:

API key not configured. Please provide a valid API key.

πŸ§ͺ Example App #

This package includes a full Flutter example demonstrating:

  • PromptTemplate usage
  • AI request lifecycle
  • Loading state handling
  • Error-safe UI

Run the example:

cd example
flutter run

πŸ” API Key Management #

For security reasons:

  • ❌ Do not commit API keys to GitHub
  • ❌ Do not hardcode API keys in packages
  • βœ… Provide API keys from the application layer
  • .env usage is optional (not required)

πŸ›£οΈ Roadmap #

  • Streaming AI responses
  • Structured JSON output
  • Multiple LLM provider support
  • Built-in prompt presets

🀝 Contributing #

Contributions are welcome!
Feel free to open issues or submit pull requests.


πŸ“„ License #

MIT License

0
likes
0
points
72
downloads

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

unknown (license)

Dependencies

flutter, http

More

Packages that depend on ai_prompt_kit