forked from openai-php/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateResponseMessage.php
More file actions
102 lines (79 loc) · 3.48 KB
/
CreateResponseMessage.php
File metadata and controls
102 lines (79 loc) · 3.48 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
<?php
use OpenAI\Responses\Chat\CreateResponseChoiceAnnotations;
use OpenAI\Responses\Chat\CreateResponseFunctionCall;
use OpenAI\Responses\Chat\CreateResponseMessage;
use OpenAI\Responses\Chat\CreateResponseToolCall;
test('from', function () {
$result = CreateResponseMessage::from(chatCompletion()['choices'][0]['message']);
expect($result)
->role->toBe('assistant')
->content->toBe("\n\nHello there, how may I assist you today?")
->annotations->toBeArray()
->functionCall->toBeNull();
});
test('from function response', function () {
$result = CreateResponseMessage::from(chatCompletionWithFunction()['choices'][0]['message']);
expect($result)
->role->toBe('assistant')
->content->toBeNull()
->annotations->toBeArray()
->functionCall->toBeInstanceOf(CreateResponseFunctionCall::class);
});
test('from tool calls response', function () {
$result = CreateResponseMessage::from(chatCompletionWithToolCalls()['choices'][0]['message']);
expect($result)
->role->toBe('assistant')
->content->toBeNull()
->toolCalls->toBeArray()
->toolCalls->toHaveCount(1)
->toolCalls->each->toBeInstanceOf(CreateResponseToolCall::class);
});
test('from annotations response', function () {
$result = CreateResponseMessage::from(chatCompletionWithAnnotations()['choices'][0]['message']);
expect($result)
->role->toBe('assistant')
->content->toBe('Hello World')
->annotations->toBeArray()
->annotations->toHaveCount(1)
->annotations->each->toBeInstanceOf(CreateResponseChoiceAnnotations::class);
});
test('from function response without content', function () {
$result = CreateResponseMessage::from(chatCompletionMessageWithFunctionAndNoContent());
expect($result)
->role->toBe('assistant')
->content->toBeNull()
->functionCall->toBeInstanceOf(CreateResponseFunctionCall::class);
});
test('from reasoning', function () {
$result = CreateResponseMessage::from(chatCompletionReasoningContent()['choices'][0]['message']);
expect($result)
->role->toBe('assistant')
->reasoningContent->toBe('Hello world')
->annotations->toBeArray()
->functionCall->toBeNull();
});
test('to array', function () {
$result = CreateResponseMessage::from(chatCompletionReasoningContent()['choices'][0]['message']);
expect($result->toArray())
->toBe(chatCompletionReasoningContent()['choices'][0]['message']);
});
test('to array from reasoning', function () {
$result = CreateResponseMessage::from(chatCompletion()['choices'][0]['message']);
expect($result->toArray())
->toBe(chatCompletion()['choices'][0]['message']);
});
test('to array from function response', function () {
$result = CreateResponseMessage::from(chatCompletionWithFunction()['choices'][0]['message']);
expect($result->toArray())
->toBe(chatCompletionWithFunction()['choices'][0]['message']);
});
test('to array from tool calls response', function () {
$result = CreateResponseMessage::from(chatCompletionWithToolCalls()['choices'][0]['message']);
expect($result->toArray())
->toBe(chatCompletionWithToolCalls()['choices'][0]['message']);
});
test('to array from annotations response', function () {
$result = CreateResponseMessage::from(chatCompletionWithAnnotations()['choices'][0]['message']);
expect($result->toArray())
->toBe(chatCompletionWithAnnotations()['choices'][0]['message']);
});