@@ -16,7 +16,7 @@ import (
16
16
17
17
func TestEventReader_InvalidType (t * testing.T ) {
18
18
data := []string {
19
- "invaliddata: {\u0022 name \u0022 : \u0022 chatcmpl -7Z4kUpXX6HN85cWY28IXM4EwemLU3\u0022 , \u0022 object \u0022 : \u0022 chat .completion.chunk\u0022 , \u0022 created \u0022 :1688594090,\u0022 model \u0022 : \u0022 gpt -4-0613\u0022 , \u0022 choices \u0022 :[{\u0022 index \u0022 :0,\u0022 delta \u0022 :{\u0022 role \u0022 : \u0022 assistant \u0022 , \u0022 content \u0022 : \u0022 \u0022 },\u0022 finish_reason \u0022 :null}]}\n \n " ,
19
+ "invaliddata: {\" name \" : \" chatcmpl -7Z4kUpXX6HN85cWY28IXM4EwemLU3\" , \" object \" : \" chat .completion.chunk\" , \" created \" :1688594090,\" model \" : \" gpt -4-0613\" , \" choices \" :[{\" index \" :0,\" delta \" :{\" role \" : \" assistant \" , \" content \" : \" \" },\" finish_reason \" :null}]}\n \n " ,
20
20
}
21
21
22
22
text := strings .NewReader (strings .Join (data , "\n " ))
@@ -55,3 +55,23 @@ func TestEventReader_StreamIsClosedBeforeDone(t *testing.T) {
55
55
require .Empty (t , evt )
56
56
require .EqualError (t , err , "incomplete stream" )
57
57
}
58
+
59
+ func TestEventReader_SpacesAroundAreas (t * testing.T ) {
60
+ buff := strings .NewReader (
61
+ // spaces between data
62
+ "data: {\" name\" :\" chatcmpl-7Z4kUpXX6HN85cWY28IXM4EwemLU3\" ,\" object\" :\" chat.completion.chunk\" ,\" created\" :1688594090,\" model\" :\" gpt-4-0613\" ,\" choices\" :[{\" index\" :0,\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" with-spaces\" },\" finish_reason\" :null}]}\n " +
63
+ // no spaces
64
+ "data:{\" name\" :\" chatcmpl-7Z4kUpXX6HN85cWY28IXM4EwemLU3\" ,\" object\" :\" chat.completion.chunk\" ,\" created\" :1688594090,\" model\" :\" gpt-4-0613\" ,\" choices\" :[{\" index\" :0,\" delta\" :{\" role\" :\" assistant\" ,\" content\" :\" without-spaces\" },\" finish_reason\" :null}]}\n " ,
65
+ )
66
+
67
+ eventReader := newEventReader [ChatCompletions ](io .NopCloser (buff ))
68
+
69
+ evt , err := eventReader .Read ()
70
+ require .NoError (t , err )
71
+ require .Equal (t , "with-spaces" , * evt .Choices [0 ].Delta .Content )
72
+
73
+ evt , err = eventReader .Read ()
74
+ require .NoError (t , err )
75
+ require .NotEmpty (t , evt )
76
+ require .Equal (t , "without-spaces" , * evt .Choices [0 ].Delta .Content )
77
+ }
0 commit comments