Skip to content

Commit

Permalink
Merge pull request #13 from leoafarias/main
Browse files Browse the repository at this point in the history
Fixes chat completion stream losing first event data
  • Loading branch information
anasfik authored Mar 21, 2023
2 parents f8289d2 + 921693d commit 99f003e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/src/core/networking/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import 'dart:convert';
import 'dart:io';

import 'package:dart_openai/openai.dart';
import 'package:http/http.dart' as http;
import 'package:dart_openai/src/core/builder/headers.dart';
import 'package:dart_openai/src/core/utils/logger.dart';
import 'package:http/http.dart' as http;

import '../exceptions/request_failure.dart';

Expand Down Expand Up @@ -192,9 +192,14 @@ class OpenAINetworkingClient {
client.send(request).then(
(respond) {
OpenAILogger.log("Starting to reading stream response");
respond.stream.listen(

final stream = respond.stream
.transform(utf8.decoder)
.transform(const LineSplitter());

stream.listen(
(value) {
final String data = utf8.decode(value);
final data = value;

final List<String> dataLines = data
.split("\n")
Expand Down

0 comments on commit 99f003e

Please sign in to comment.