Skip to content

Commit 9cf5f84

Browse files
committed
fix(OpenAI): adjust tests for 'keepalive'
1 parent f1d95bd commit 9cf5f84

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

tests/Fixtures/Chat.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,14 @@ function chatCompletionStreamPing()
738738
return fopen(__DIR__.'/Streams/ChatCompletionPing.txt', 'r');
739739
}
740740

741+
/**
742+
* @return resource
743+
*/
744+
function chatCompletionStreamKeepAlive()
745+
{
746+
return fopen(__DIR__.'/Streams/ChatCompletionKeepAlive.txt', 'r');
747+
}
748+
741749
/**
742750
* @return resource
743751
*/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
data: {"id":"msg_0111RgCFCqN68mJbev6Rq1cz","choices":[{"index":0,"delta":{"role":"assistant"}}],"created":1744469024,"model":"claude-3-7-sonnet-20250219","object":"chat.completion.chunk"}
2+
data: {"type": "keepalive"}
3+
data: {"id":"msg_0111RgCFCqN68mJbev6Rq1cz","choices":[{"index":0,"delta":{"content":"Hello!"}}],"created":1744469024,"model":"claude-3-7-sonnet-20250219","object":"chat.completion.chunk"}
4+
data: [DONE]

tests/Resources/Chat.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,29 @@
128128
}
129129
});
130130

131+
test('handles keepalive messages in stream', function () {
132+
$response = new Response(
133+
headers: metaHeaders(),
134+
body: new Stream(chatCompletionStreamKeepAlive()),
135+
);
136+
137+
$client = mockStreamClient('POST', 'chat/completions', [
138+
'model' => 'gpt-3.5-turbo',
139+
'messages' => ['role' => 'user', 'content' => 'Hello!'],
140+
'stream' => true,
141+
], $response);
142+
143+
$stream = $client->chat()->createStreamed([
144+
'model' => 'gpt-3.5-turbo',
145+
'messages' => ['role' => 'user', 'content' => 'Hello!'],
146+
]);
147+
148+
foreach ($stream as $response) {
149+
expect($response)
150+
->toBeInstanceOf(CreateStreamedResponse::class);
151+
}
152+
});
153+
131154
test('handles error messages in stream', function () {
132155
$response = new Response(
133156
body: new Stream(chatCompletionStreamError())

0 commit comments

Comments
 (0)