@@ -142,22 +142,23 @@ export function* createMessageStream(request: MessagesRequest): Generator<string
142
142
}
143
143
}
144
144
yield SSEMessageFormatter ( 'message_start' , startChunk ) ;
145
+ // Get test case
146
+ const testCase = model . testCases [ 0 ] ;
145
147
146
148
// Send the first chunk
147
- outputTokens += calculateTokens ( model . testCases [ 0 ] . response ) ;
148
149
const firstChunk : ContentBlockStartEvent = {
149
150
type : 'content_block_start' ,
150
151
index : 0 ,
151
152
content_block : {
152
153
type : 'text' ,
153
- text : model . testCases [ 0 ] . response
154
+ text : ""
154
155
}
155
156
}
156
157
yield SSEMessageFormatter ( 'content_block_start' , firstChunk ) ;
157
158
158
159
//If there are predefined streaming chunks, use them
159
- if ( model . testCases [ 0 ] . streamChunks && model . testCases [ 0 ] . streamChunks . length > 0 ) {
160
- for ( const chunk of model . testCases [ 0 ] . streamChunks ) {
160
+ if ( testCase . streamChunks && testCase . streamChunks . length > 0 ) {
161
+ for ( const chunk of testCase . streamChunks ) {
161
162
outputTokens += calculateTokens ( chunk ) ;
162
163
const streamChunk : ContentBlockDeltaEvent = {
163
164
type : 'content_block_delta' ,
@@ -169,7 +170,23 @@ export function* createMessageStream(request: MessagesRequest): Generator<string
169
170
}
170
171
yield SSEMessageFormatter ( 'content_block_delta' , streamChunk ) ;
171
172
}
172
- }
173
+ } else {
174
+ // Split the response into chunks
175
+ const words = testCase . response . split ( " " ) ;
176
+ for ( let i = 0 ; i < words . length ; i += 2 ) {
177
+ const chunkText = words . slice ( i , i + 2 ) . join ( " " ) + ( i + 2 < words . length ? " " : "" ) ;
178
+ outputTokens += calculateTokens ( chunkText ) ;
179
+ const streamChunk : ContentBlockDeltaEvent = {
180
+ type : 'content_block_delta' ,
181
+ index : 0 ,
182
+ delta : {
183
+ type : 'text_delta' ,
184
+ text : chunkText
185
+ }
186
+ }
187
+ yield SSEMessageFormatter ( 'content_block_delta' , streamChunk ) ;
188
+ }
189
+ }
173
190
174
191
//send message delta
175
192
const messageDelta : MessageDeltaEvent = {
0 commit comments