-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace App\LlmDriver; | ||
|
||
use App\LlmDriver\Requests\MessageInDto; | ||
use App\LlmDriver\Responses\CompletionResponse; | ||
use App\LlmDriver\Responses\EmbeddingsResponseDto; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class ClaudeClient | ||
{ | ||
protected string $driver = 'claude'; | ||
|
||
public function embedData(string $data): EmbeddingsResponseDto | ||
{ | ||
if (! app()->environment('testing')) { | ||
sleep(2); | ||
} | ||
Log::info('LlmDriver::MockClient::embedData'); | ||
|
||
$data = get_fixture('embedding_response.json'); | ||
|
||
return EmbeddingsResponseDto::from([ | ||
'embedding' => data_get($data, 'data.0.embedding'), | ||
'token_count' => 1000, | ||
]); | ||
} | ||
|
||
/** | ||
* @param MessageInDto[] $messages | ||
*/ | ||
public function chat(array $messages): CompletionResponse | ||
{ | ||
if (! app()->environment('testing')) { | ||
sleep(2); | ||
} | ||
|
||
Log::info('LlmDriver::MockClient::completion'); | ||
|
||
$data = <<<'EOD' | ||
Voluptate irure cillum dolor anim officia reprehenderit dolor. Eiusmod veniam nostrud consectetur incididunt proident id. Anim adipisicing pariatur amet duis Lorem sunt veniam veniam est. Deserunt ea aliquip cillum pariatur consectetur. Dolor in reprehenderit adipisicing consectetur cupidatat ad cupidatat reprehenderit. Nostrud mollit voluptate aliqua anim pariatur excepteur eiusmod velit quis exercitation tempor quis excepteur. | ||
EOD; | ||
|
||
return new CompletionResponse($data); | ||
} | ||
|
||
public function completion(string $prompt): CompletionResponse | ||
{ | ||
if (! app()->environment('testing')) { | ||
sleep(2); | ||
} | ||
|
||
Log::info('LlmDriver::MockClient::completion'); | ||
|
||
$data = <<<'EOD' | ||
Voluptate irure cillum dolor anim officia reprehenderit dolor. Eiusmod veniam nostrud consectetur incididunt proident id. Anim adipisicing pariatur amet duis Lorem sunt veniam veniam est. Deserunt ea aliquip cillum pariatur consectetur. Dolor in reprehenderit adipisicing consectetur cupidatat ad cupidatat reprehenderit. Nostrud mollit voluptate aliqua anim pariatur excepteur eiusmod velit quis exercitation tempor quis excepteur. | ||
EOD; | ||
|
||
return new CompletionResponse($data); | ||
} | ||
|
||
protected function getConfig(string $driver): array | ||
{ | ||
return config("llmdriver.drivers.$driver"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\LlmDriver\ClaudeClient; | ||
use App\LlmDriver\MockClient; | ||
use App\LlmDriver\Requests\MessageInDto; | ||
use App\LlmDriver\Responses\CompletionResponse; | ||
use App\LlmDriver\Responses\EmbeddingsResponseDto; | ||
use Tests\TestCase; | ||
|
||
class ClaudeClientTest extends TestCase | ||
{ | ||
/** | ||
* A basic feature test example. | ||
*/ | ||
public function test_embeddings(): void | ||
{ | ||
|
||
$client = new ClaudeClient(); | ||
|
||
$results = $client->embedData('test'); | ||
|
||
$this->assertInstanceOf(EmbeddingsResponseDto::class, $results); | ||
|
||
} | ||
|
||
public function test_completion(): void | ||
{ | ||
$client = new MockClient(); | ||
|
||
$results = $client->completion('test'); | ||
|
||
$this->assertInstanceOf(CompletionResponse::class, $results); | ||
|
||
} | ||
|
||
public function test_Chat(): void | ||
{ | ||
$client = new MockClient(); | ||
|
||
$results = $client->chat([ | ||
MessageInDto::from([ | ||
'content' => 'test', | ||
'role' => 'user', | ||
]), | ||
]); | ||
|
||
$this->assertInstanceOf(CompletionResponse::class, $results); | ||
|
||
} | ||
} |