Skip to content

Commit

Permalink
add ollama
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Mar 30, 2024
1 parent 58972a5 commit 578436c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
2 changes: 0 additions & 2 deletions app/LlmDriver/ClaudeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ClaudeClient extends BaseClient

protected string $version = '2023-06-01';


protected string $driver = 'claude';

public function embedData(string $data): EmbeddingsResponseDto
Expand Down Expand Up @@ -141,5 +140,4 @@ protected function getClient()
'content-type' => 'application/json',
])->baseUrl($this->baseUrl);
}

}
2 changes: 1 addition & 1 deletion app/LlmDriver/LlmDriverClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function driver($name = null)
protected function createDriver($name)
{
/**
* @TODO
* @TODO
* Turn into a match statement
*/
switch ($name) {
Expand Down
18 changes: 8 additions & 10 deletions app/LlmDriver/OllamaClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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');
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Collection/Components/LlmType.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
]
Expand Down
3 changes: 0 additions & 3 deletions tests/Feature/OllamaClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -74,6 +73,4 @@ public function test_chat(): void
});

}


}

0 comments on commit 578436c

Please sign in to comment.