From 578436c654539a99b5e1c337c92d099b705f1daa Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Sat, 30 Mar 2024 10:32:17 -0400 Subject: [PATCH] add ollama --- app/LlmDriver/ClaudeClient.php | 2 -- app/LlmDriver/LlmDriverClient.php | 2 +- app/LlmDriver/OllamaClient.php | 18 ++++++++---------- .../js/Pages/Collection/Components/LlmType.vue | 2 +- tests/Feature/OllamaClientTest.php | 3 --- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/LlmDriver/ClaudeClient.php b/app/LlmDriver/ClaudeClient.php index 7aa8e4f5..bae0197e 100644 --- a/app/LlmDriver/ClaudeClient.php +++ b/app/LlmDriver/ClaudeClient.php @@ -15,7 +15,6 @@ class ClaudeClient extends BaseClient protected string $version = '2023-06-01'; - protected string $driver = 'claude'; public function embedData(string $data): EmbeddingsResponseDto @@ -141,5 +140,4 @@ protected function getClient() 'content-type' => 'application/json', ])->baseUrl($this->baseUrl); } - } diff --git a/app/LlmDriver/LlmDriverClient.php b/app/LlmDriver/LlmDriverClient.php index 5863be40..228c3241 100644 --- a/app/LlmDriver/LlmDriverClient.php +++ b/app/LlmDriver/LlmDriverClient.php @@ -20,7 +20,7 @@ public function driver($name = null) protected function createDriver($name) { /** - * @TODO + * @TODO * Turn into a match statement */ switch ($name) { diff --git a/app/LlmDriver/OllamaClient.php b/app/LlmDriver/OllamaClient.php index ccf2685d..e51f54d2 100644 --- a/app/LlmDriver/OllamaClient.php +++ b/app/LlmDriver/OllamaClient.php @@ -7,18 +7,15 @@ use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; -use OpenAI; class OllamaClient extends BaseClient { - protected string $driver = 'ollama'; /** - * - * @param MessageInDto[] $messages - * @return CompletionResponse - * @throws BindingResolutionException + * @param MessageInDto[] $messages + * + * @throws BindingResolutionException */ public function chat(array $messages): CompletionResponse { @@ -32,11 +29,11 @@ public function chat(array $messages): CompletionResponse 'stream' => false, ]); - $results =$response->json()['message']['content']; + $results = $response->json()['message']['content']; return new CompletionResponse($results); } - + public function completion(string $prompt): CompletionResponse { Log::info('LlmDriver::Ollama::completion'); @@ -47,12 +44,13 @@ public function completion(string $prompt): CompletionResponse 'stream' => false, ]); - $results =$response->json()['response']; + $results = $response->json()['response']; return new CompletionResponse($results); } - protected function getClient() { + protected function getClient() + { $api_token = $this->getConfig('ollama')['api_key']; $baseUrl = $this->getConfig('ollama')['api_url']; if (! $api_token || ! $baseUrl) { diff --git a/resources/js/Pages/Collection/Components/LlmType.vue b/resources/js/Pages/Collection/Components/LlmType.vue index 2ad45dfa..e990ea47 100644 --- a/resources/js/Pages/Collection/Components/LlmType.vue +++ b/resources/js/Pages/Collection/Components/LlmType.vue @@ -51,7 +51,7 @@ { active: true, key: "openai", title: 'OpenAi', description: 'This will work with the OpenAi Api', current: false }, { active: true, key: "claude", title: 'Claude', description: 'This will work with the Claude Api', current: false }, { active: false, key: "mock", title: 'OpenAi Azure', description: 'This will work with the Azure OpenAi Api', current: false }, - { active: false, key: "ollama", title: 'Ollama', description: 'This will work with the Ollam API', current: false }, + { active: true, key: "ollama", title: 'Ollama', description: 'This will work with the Ollam API', current: false }, { active: false, key: "mock", title: 'Gemini', description: 'This will work with the Gemini Api', current: false }, ] diff --git a/tests/Feature/OllamaClientTest.php b/tests/Feature/OllamaClientTest.php index 67abeb94..63b99cce 100644 --- a/tests/Feature/OllamaClientTest.php +++ b/tests/Feature/OllamaClientTest.php @@ -53,7 +53,6 @@ public function test_chat(): void '127.0.0.1:11434/*' => Http::response($data, 200), ]); - $results = $client->chat([ MessageInDto::from([ 'content' => 'test', @@ -74,6 +73,4 @@ public function test_chat(): void }); } - - }