chatgpt_client 1.1.0 chatgpt_client: ^1.1.0 copied to clipboard
Access OpenAI ChatGPT Public API using Dart Language. Supports native Dart project and all Flutter target platforms (iOS, Android, Windows, Linux, Web)
import 'package:chatgpt_client/chatgpt_client.dart';
void main() async {
final client = ChatGPTClient(apiKey: "API_KEY");
final prompt = "what is observable object?";
/// Standard Response
print("Standard Response");
try {
final text = await client.sendMessage(prompt);
print(text);
} catch (exception) {
print(exception.toString());
}
/// Stream Response
print("Stream Response");
try {
var text = "";
final stream = client.sendMessageStream(prompt);
await for (final textChunk in stream) {
text += textChunk;
print(textChunk);
}
print(text);
} catch (exception) {
print(exception.toString());
}
client.clearHistoryList();
}