File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace GrokPHP \Laravel \Support ;
4+
5+ class GrokResponse implements \JsonSerializable
6+ {
7+ private array $ response ;
8+
9+ public function __construct (array $ response )
10+ {
11+ $ this ->response = $ response ;
12+ }
13+
14+ /**
15+ * Get the full API response.
16+ */
17+ public function full (): array
18+ {
19+ return $ this ->response ;
20+ }
21+
22+ /**
23+ * Get only the assistant's message content.
24+ */
25+ public function content (): string
26+ {
27+ return $ this ->response ['choices ' ][0 ]['message ' ]['content ' ] ?? 'No response received. ' ;
28+ }
29+
30+ /**
31+ * Get the usage statistics for the API response.
32+ */
33+ public function usage (): array
34+ {
35+ return $ this ->response ['usage ' ] ?? [];
36+ }
37+
38+ /**
39+ * Allow the GrokResponse object to be serialized to JSON.
40+ * @return array
41+ */
42+ public function jsonSerialize (): array
43+ {
44+ return $ this ->response ;
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments