-
-
Notifications
You must be signed in to change notification settings - Fork 232
Open
Description
Test Code
test('chat stream', () async {
OpenAI.baseUrl = "https://api.openai.com";
OpenAI.apiKey = "sk-**********";
var createStream =
OpenAI.instance.chat.createStream(model: "gpt-3.5-turbo", messages: [
OpenAIChatCompletionChoiceMessageModel(
role: OpenAIChatMessageRole.user,
content: [
OpenAIChatCompletionChoiceMessageContentItemModel.text("Hi!")
])
]);
final completer = Completer<bool>();
// Count the number of calls
var count = 0;
// Merge results
var assistant = "";
createStream.listen((event) {
count++;
final content = event.choices.first.delta.content;
if (content != null) {
assistant = assistant + content.first!.text!;
}
}, onDone: () {
completer.complete(true);
print(assistant);
print(count);
});
await completer.future;
});Logs
Hello! How can I assist you today?Hello! How can I assist you today?Hello! How can I assist you today?Hello! How can I assist you today?Hello! How can I assist you today?Hello! How can I help you today?Hello! How can I assist you today?Hello! How can I assist you today?Hello! How can I assist you today?Hello! How can I assist you today?Hello! How can I help you today?
121
If my processing method is incorrect, how can I correctly obtain unique values?
Metadata
Metadata
Assignees
Labels
No labels