File tree Expand file tree Collapse file tree 3 files changed +57
-2
lines changed Expand file tree Collapse file tree 3 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 22
33namespace GrokPHP \Laravel \Facades ;
44
5+ use GrokPHP \Client \Clients \Vision ;
56use Illuminate \Support \Facades \Facade ;
67
78/**
8- * @method static array chat(array $messages, \GrokPHP\Client\Config\ChatOptions $options)
9+ * @method static array chat(array $messages, ?\GrokPHP\Client\Config\ChatOptions $options = null)
10+ * @method static Vision vision()
911 */
1012class GrokAI extends Facade
1113{
1214 protected static function getFacadeAccessor (): string
1315 {
14- return ' grok-ai ' ;
16+ return \ GrokPHP \ Laravel \ Services \GrokAI::class ;
1517 }
1618}
Original file line number Diff line number Diff line change 33namespace GrokPHP \Laravel \Providers ;
44
55use GrokPHP \Laravel \Commands \InstallGrokCommand ;
6+ use GrokPHP \Laravel \Services \GrokAI ;
67use Illuminate \Support \ServiceProvider ;
78use GrokPHP \Client \Clients \GrokClient ;
89use GrokPHP \Client \Config \GrokConfig ;
@@ -26,6 +27,10 @@ public function register(): void
2627 return new GrokClient ($ app ->make (GrokConfig::class));
2728 });
2829
30+ $ this ->app ->singleton (GrokAI::class, function ($ app ) {
31+ return new GrokAI ($ app ->make (GrokClient::class));
32+ });
33+
2934 $ this ->app ->alias (GrokClient::class, 'grok-ai ' );
3035 }
3136
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace GrokPHP \Laravel \Services ;
4+
5+ use GrokPHP \Client \Clients \GrokClient ;
6+ use GrokPHP \Client \Config \ChatOptions ;
7+ use GrokPHP \Client \Enums \Model ;
8+ use GrokPHP \Client \Exceptions \GrokException ;
9+ use GrokPHP \Laravel \Support \GrokResponse ;
10+
11+ class GrokAI
12+ {
13+ protected GrokClient $ client ;
14+
15+ public function __construct (GrokClient $ client )
16+ {
17+ $ this ->client = $ client ;
18+ }
19+
20+ /**
21+ * Send a chat completion request to Grok API.
22+ * @param array $messages
23+ * @param ChatOptions|null $options
24+ * @return GrokResponse
25+ * @throws GrokException
26+ */
27+ public function chat (array $ messages , ?ChatOptions $ options = null ): GrokResponse
28+ {
29+ $ options = $ options ?? new ChatOptions (
30+ model: Model::GROK_2 ,
31+ temperature: 0.7 ,
32+ stream: false
33+ );
34+
35+ $ response = $ this ->client ->chat ($ messages , $ options );
36+
37+ return new GrokResponse ($ response );
38+ }
39+
40+ /**
41+ * Analyze an image using Grok Vision models.
42+ * @return GrokVision
43+ */
44+ public function vision (): GrokVision
45+ {
46+ return new GrokVision ($ this ->client );
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments