File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,35 @@ function chatCompletion(): array
37
37
];
38
38
}
39
39
40
+ /**
41
+ * @return array<string, mixed>
42
+ */
43
+ function chatCompletionOpenRouter (): array
44
+ {
45
+ return [
46
+ 'id ' => 'gen-123 ' ,
47
+ 'object ' => 'chat.completion ' ,
48
+ 'created ' => 1744873707 ,
49
+ 'model ' => 'mistral/ministral-8b ' ,
50
+ 'choices ' => [
51
+ [
52
+ 'index ' => 0 ,
53
+ 'message ' => [
54
+ 'role ' => 'assistant ' ,
55
+ 'content ' => 'Hello! How can I assist you today? ' ,
56
+ ],
57
+ 'logprobs ' => null ,
58
+ 'finish_reason ' => 'stop ' ,
59
+ ],
60
+ ],
61
+ 'usage ' => [
62
+ 'prompt_tokens ' => 13 ,
63
+ 'completion_tokens ' => 20 ,
64
+ 'total_tokens ' => 33 ,
65
+ ],
66
+ ];
67
+ }
68
+
40
69
/**
41
70
* @return array<string, mixed>
42
71
*/
Original file line number Diff line number Diff line change 15
15
->completionTokensDetails ->toBeInstanceOf (CreateResponseUsageCompletionTokensDetails::class);
16
16
});
17
17
18
+ test ('from (OpenRouter) ' , function () {
19
+ $ result = CreateResponseUsage::from (chatCompletionOpenRouter ()['usage ' ]);
20
+
21
+ expect ($ result )
22
+ ->promptTokens ->toBe (13 )
23
+ ->completionTokens ->toBe (20 )
24
+ ->totalTokens ->toBe (33 )
25
+ ->promptTokensDetails ->toBeNull ()
26
+ ->completionTokensDetails ->toBeNull ();
27
+ });
28
+
18
29
test ('to array ' , function () {
19
30
$ result = CreateResponseUsage::from (chatCompletion ()['usage ' ]);
20
31
You can’t perform that action at this time.
0 commit comments