@@ -71,6 +71,10 @@ protected function createDriver($driver): LLM // @pest-ignore-type
7171 ? $ driver ->value
7272 : $ driver ;
7373
74+ if ($ driver === 'cache ' ) {
75+ throw new InvalidArgumentException ('Invalid driver - cache keyword is reserved for internal use. ' );
76+ }
77+
7478 if (isset ($ this ->customCreators [$ driver ])) {
7579 return $ this ->callCustomCreator ($ config );
7680 }
@@ -131,26 +135,17 @@ public function createOpenAIResponsesDriver(array $config, string $name): OpenAI
131135 */
132136 public function createAnthropicDriver (array $ config , string $ name ): AnthropicChat
133137 {
134- // $client = Anthropic::factory()
135- // ->withApiKey(Arr::get($config, 'options.api_key') ?? '')
136- // ->withHttpHeader('anthropic-version', Arr::get($config, 'options.version', '2023-06-01'));
137-
138- // foreach (Arr::get($config, 'options.headers', []) as $key => $value) {
139- // $client->withHttpHeader($key, $value);
140- // }
141-
142- // foreach (Arr::get($config, 'options.query_params', []) as $key => $value) {
143- // $client->withQueryParam($key, $value);
144- // }
145-
146- // if ($baseUri = Arr::get($config, 'options.base_uri')) {
147- // $client->withBaseUri($baseUri);
148- // }
138+ $ cacheEnabled = $ this ->config ->get ('cortex.llm.cache.enabled ' , false );
139+ $ cacheStore = $ cacheEnabled
140+ ? $ this ->container ->make ('cache ' )->store ($ this ->config ->get ('cortex.llm.cache.store ' ))
141+ : null ;
149142
150143 $ client = new Anthropic (
151- Arr::get ($ config , 'options.api_key ' ) ?? '' ,
152- Arr::get ($ config , 'options.base_uri ' ),
153- Arr::get ($ config , 'options.version ' ),
144+ apiKey: Arr::get ($ config , 'options.api_key ' ) ?? '' ,
145+ baseUri: Arr::get ($ config , 'options.base_uri ' ),
146+ version: Arr::get ($ config , 'options.version ' ),
147+ cacheStore: $ cacheStore ,
148+ cacheExpiryInSeconds: $ this ->config ->get ('cortex.llm.cache.ttl ' ),
154149 );
155150
156151 if (! isset ($ config ['default_model ' ])) {
@@ -169,6 +164,8 @@ public function createAnthropicDriver(array $config, string $name): AnthropicCha
169164 );
170165 $ driver ->setEventDispatcher (new IlluminateEventDispatcherBridge ($ this ->container ->make ('events ' )));
171166
167+ $ driver ->withCaching ($ cacheEnabled );
168+
172169 return $ driver ;
173170 }
174171
0 commit comments