Skip to content

Commit

Permalink
fix: replicate llama init (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
chr-hertel authored Feb 21, 2025
1 parent ec37a3a commit 9b9c17f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/Bridge/Meta/LlamaPromptConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function convertMessage(UserMessage|SystemMessage|AssistantMessage $messa
{
if ($message instanceof SystemMessage) {
return trim(<<<SYSTEM
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
{$message->content}<|eot_id|>
SYSTEM);
{$message->content}<|eot_id|>
SYSTEM);
}

if ($message instanceof AssistantMessage) {
Expand All @@ -44,10 +44,10 @@ public function convertMessage(UserMessage|SystemMessage|AssistantMessage $messa
}

return trim(<<<ASSISTANT
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
{$message->content}<|eot_id|>
ASSISTANT);
{$message->content}<|eot_id|>
ASSISTANT);
}

if ($message instanceof UserMessage) {
Expand Down Expand Up @@ -80,10 +80,10 @@ public function convertMessage(UserMessage|SystemMessage|AssistantMessage $messa
$content = implode(PHP_EOL, $contentParts);

return trim(<<<USER
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
{$content}<|eot_id|>
USER);
{$content}<|eot_id|>
USER);
}

throw new RuntimeException('Unsupported message type.'); // @phpstan-ignore-line
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Replicate/LlamaModelClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
public function __construct(
private Client $client,
private LlamaPromptConverter $promptConverter,
private LlamaPromptConverter $promptConverter = new LlamaPromptConverter(),
) {
}

Expand Down
6 changes: 1 addition & 5 deletions src/Bridge/Replicate/PlatformFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

namespace PhpLlm\LlmChain\Bridge\Replicate;

use PhpLlm\LlmChain\Bridge\Meta\LlamaPromptConverter;
use PhpLlm\LlmChain\Platform;
use Symfony\Component\Clock\Clock;
use Symfony\Component\HttpClient\EventSourceHttpClient;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Contracts\HttpClient\HttpClientInterface;

Expand All @@ -18,10 +16,8 @@ public static function create(
string $apiKey,
?HttpClientInterface $httpClient = null,
): Platform {
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);

return new Platform(
[new LlamaModelClient(new Client(HttpClient::create(), new Clock(), $apiKey), new LlamaPromptConverter())],
[new LlamaModelClient(new Client($httpClient ?? HttpClient::create(), new Clock(), $apiKey))],
[new LlamaResponseConverter()],
);
}
Expand Down

0 comments on commit 9b9c17f

Please sign in to comment.