chatgpt_box 0.0.5
chatgpt_box: ^0.0.5 copied to clipboard
A chatgpt AI provider based on ai_box.
chatgpt_box #
An OpenAI (ChatGPT) provider based on ai_box.
Usage #
import 'package:ai_box/ai_box.dart';
import 'package:chatgpt_box/chatgpt_box.dart';
Future<void> main() async {
final ai = ChatGPT(apiKey: 'sk-...');
// One-shot text generation.
final answer = await ai.generateText(
model: 'gpt-5.4-mini',
message: 'Say hello in one short sentence.',
);
print(answer);
// Multi-turn chat.
final res = await ai.chat(
model: 'gpt-5.4-mini',
messages: [
LLMContent.system('You are concise.'),
LLMContent.user('What is the capital of Japan?'),
],
maxTokens: 32,
);
print(res.text);
print(res.usage); // token usage
}
Streaming #
True SSE streaming — text arrives incrementally and the final chunk carries the finish reason and token usage:
await for (final text in ai.generateTextStream(
model: 'gpt-5.4-mini',
message: 'Write a haiku about Dart.',
)) {
stdout.write(text);
}
Models and key validation #
final models = await ai.getModels();
final ok = await ai.validateKey();
Multimodal input (images, audio, files), tool calling, structured output
(JSON Schema) and the sealed LLMException error hierarchy are all provided
by ai_box — see its README for details.