-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathCreateStreamedResponseDelta.php
More file actions
104 lines (79 loc) · 3.45 KB
/
CreateStreamedResponseDelta.php
File metadata and controls
104 lines (79 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
use OpenAI\Responses\Chat\CreateStreamedResponseDelta;
use OpenAI\Responses\Chat\CreateStreamedResponseFunctionCall;
use OpenAI\Responses\Chat\CreateStreamedResponseToolCall;
test('from first chunk', function () {
$result = CreateStreamedResponseDelta::from(chatCompletionStreamFirstChunk()['choices'][0]['delta']);
expect($result)
->role->toBe('assistant')
->content->toBeNull();
});
test('from content chunk', function () {
$result = CreateStreamedResponseDelta::from(chatCompletionStreamContentChunk()['choices'][0]['delta']);
expect($result)
->role->toBeNull()
->content->toBe('Hello')
->reasoningContent->toBeNull()
->functionCall->toBeNull();
});
test('from reasoning content chunk', function () {
$delta = [
'reasoning_content' => 'Let me think about this...',
];
$result = CreateStreamedResponseDelta::from($delta);
expect($result)
->role->toBeNull()
->content->toBeNull()
->reasoningContent->toBe('Let me think about this...')
->functionCall->toBeNull();
});
test('from function call chunk', function () {
$result = CreateStreamedResponseDelta::from(chatCompletionStreamFunctionCallChunk()['choices'][0]['delta']);
expect($result)
->role->toBeNull()
->content->toBeNull()
->functionCall->toBeInstanceOf(CreateStreamedResponseFunctionCall::class);
});
test('from tool calls chunk', function () {
$result = CreateStreamedResponseDelta::from(chatCompletionStreamToolCallsChunk()['choices'][0]['delta']);
expect($result)
->role->toBeNull()
->content->toBeNull()
->toolCalls->toBeArray()
->toolCalls->toHaveCount(1)
->toolCalls->each->toBeInstanceOf(CreateStreamedResponseToolCall::class);
});
test('to array from first chunk', function () {
$result = CreateStreamedResponseDelta::from(chatCompletionStreamFirstChunk()['choices'][0]['delta']);
expect($result->toArray())
->toBe(chatCompletionStreamFirstChunk()['choices'][0]['delta']);
});
test('to array for a content chunk', function () {
$result = CreateStreamedResponseDelta::from(chatCompletionStreamContentChunk()['choices'][0]['delta']);
expect($result->toArray())
->toBe(chatCompletionStreamContentChunk()['choices'][0]['delta']);
});
test('to array for a function call chunk', function () {
$result = CreateStreamedResponseDelta::from(chatCompletionStreamFunctionCallChunk()['choices'][0]['delta']);
expect($result->toArray())
->toBe(chatCompletionStreamFunctionCallChunk()['choices'][0]['delta']);
});
test('to array for a tool calls chunk', function () {
$result = CreateStreamedResponseDelta::from(chatCompletionStreamToolCallsChunk()['choices'][0]['delta']);
expect($result->toArray())
->toBe(chatCompletionStreamToolCallsChunk()['choices'][0]['delta']);
});
test('to array for a tool calls chunk without tool id', function () {
$data = chatCompletionStreamToolCallsChunk()['choices'][0]['delta'];
unset($data['tool_calls'][0]['id']);
$result = CreateStreamedResponseDelta::from($data);
expect($result->toArray())
->toBe($data);
});
test('to array for a tool calls chunk without function name', function () {
$data = chatCompletionStreamToolCallsChunk()['choices'][0]['delta'];
unset($data['tool_calls'][0]['function']['name']);
$result = CreateStreamedResponseDelta::from($data);
expect($result->toArray())
->toBe($data);
});