Skip to content

Commit 9b9c17f

Browse files
authored
fix: replicate llama init (#219)
1 parent ec37a3a commit 9b9c17f

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

src/Bridge/Meta/LlamaPromptConverter.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ public function convertMessage(UserMessage|SystemMessage|AssistantMessage $messa
3232
{
3333
if ($message instanceof SystemMessage) {
3434
return trim(<<<SYSTEM
35-
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
35+
<|begin_of_text|><|start_header_id|>system<|end_header_id|>
3636
37-
{$message->content}<|eot_id|>
38-
SYSTEM);
37+
{$message->content}<|eot_id|>
38+
SYSTEM);
3939
}
4040

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

4646
return trim(<<<ASSISTANT
47-
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
47+
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
4848
49-
{$message->content}<|eot_id|>
50-
ASSISTANT);
49+
{$message->content}<|eot_id|>
50+
ASSISTANT);
5151
}
5252

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

8282
return trim(<<<USER
83-
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
83+
<|start_header_id|>{$message->getRole()->value}<|end_header_id|>
8484
85-
{$content}<|eot_id|>
86-
USER);
85+
{$content}<|eot_id|>
86+
USER);
8787
}
8888

8989
throw new RuntimeException('Unsupported message type.'); // @phpstan-ignore-line

src/Bridge/Replicate/LlamaModelClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
{
1818
public function __construct(
1919
private Client $client,
20-
private LlamaPromptConverter $promptConverter,
20+
private LlamaPromptConverter $promptConverter = new LlamaPromptConverter(),
2121
) {
2222
}
2323

src/Bridge/Replicate/PlatformFactory.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
namespace PhpLlm\LlmChain\Bridge\Replicate;
66

7-
use PhpLlm\LlmChain\Bridge\Meta\LlamaPromptConverter;
87
use PhpLlm\LlmChain\Platform;
98
use Symfony\Component\Clock\Clock;
10-
use Symfony\Component\HttpClient\EventSourceHttpClient;
119
use Symfony\Component\HttpClient\HttpClient;
1210
use Symfony\Contracts\HttpClient\HttpClientInterface;
1311

@@ -18,10 +16,8 @@ public static function create(
1816
string $apiKey,
1917
?HttpClientInterface $httpClient = null,
2018
): Platform {
21-
$httpClient = $httpClient instanceof EventSourceHttpClient ? $httpClient : new EventSourceHttpClient($httpClient);
22-
2319
return new Platform(
24-
[new LlamaModelClient(new Client(HttpClient::create(), new Clock(), $apiKey), new LlamaPromptConverter())],
20+
[new LlamaModelClient(new Client($httpClient ?? HttpClient::create(), new Clock(), $apiKey))],
2521
[new LlamaResponseConverter()],
2622
);
2723
}

0 commit comments

Comments
 (0)