Skip to content

Commit 105a281

Browse files
committed
Added chat with LLama3 + fixed qa example
1 parent 50c81e2 commit 105a281

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/rag/fwdays/chat_llama3.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Chat example with LLPhant
4+
*/
5+
6+
use LLPhant\Chat\OllamaChat;
7+
use LLPhant\OllamaConfig;
8+
9+
require dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php';
10+
11+
# Ollama with Llama3
12+
$config = new OllamaConfig();
13+
$config->model = 'llama3.1';
14+
$chat = new OllamaChat($config);
15+
16+
while (true) {
17+
$question = readline('(Llama 3.1) ask me anything: ');
18+
$response = $chat->generateText($question);
19+
20+
printf("%s\n", $response);
21+
}

src/rag/fwdays/qa.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@
4040

4141
foreach ($qa->getRetrievedDocuments() as $doc) {
4242
printf("-- Document: %s\n", $doc->sourceName);
43-
printf("-- Content (%d characters): %s\n", strlen($doc->content), $doc->content);
43+
printf("-- Content (%d characters): %s\n", strlen($doc->content), substr($doc->content, 0, 100));
4444
}

0 commit comments

Comments
 (0)