chatgpt_client 0.0.7 chatgpt_client: ^0.0.7 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) It provides streamed and normal response when as [...]
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();
}