@@ -38,10 +38,7 @@ public function completions(array $data, array $options)
38
38
if ($ tmp === '' || $ tmp [strlen ($ tmp ) - 1 ] !== "\n" ) {
39
39
return null ;
40
40
}
41
- if (preg_match ('/qwen-/ ' , $ tmp )) {
42
- str_replace ('data: ' ,'data: ' , $ tmp );
43
- }
44
- preg_match_all ('/data: (\{.+?\})\n/ ' , $ tmp , $ matches );
41
+ preg_match_all ('/data: *?(\{.+?\})[ \r]*?\n/ ' , $ tmp , $ matches );
45
42
$ tmp = '' ;
46
43
foreach ($ matches [1 ]?:[] as $ match ) {
47
44
if ($ json = json_decode ($ match , true )) {
@@ -101,13 +98,14 @@ public static function formatResponse($buffer)
101
98
$ contentFilterOffsets = null ;
102
99
$ toolCalls = [];
103
100
foreach ($ chunks as $ chunk ) {
101
+ $ chunk = trim ($ chunk );
104
102
if ($ chunk === "" ) {
105
103
continue ;
106
104
}
107
- if (preg_match ( ' /qwen-/ ' , $ chunk) ) {
108
- $ chunk = trim ( substr ($ chunk , 5 ) );
105
+ if (strpos ( $ chunk, ' data:{ ' ) === 0 ) {
106
+ $ chunk = substr ($ chunk , 5 );
109
107
} else {
110
- $ chunk = trim ( substr ($ chunk , 6 ) );
108
+ $ chunk = substr ($ chunk , 6 );
111
109
}
112
110
if ($ chunk === "" || $ chunk === "[DONE] " ) {
113
111
continue ;
0 commit comments