Skip to content

Commit

Permalink
chore: update to llm-chain 0.11.0 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
chr-hertel authored Dec 28, 2024
1 parent a64d8de commit 7030227
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 66 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"ext-iconv": "*",
"codewithkyrian/chromadb-php": "^0.3.0",
"league/commonmark": "^2.6",
"php-llm/llm-chain": "^0.10",
"php-llm/llm-chain-bundle": "^0.9",
"php-llm/llm-chain-bundle": "^0.11",
"phpdocumentor/reflection-docblock": "^5.5",
"phpstan/phpdoc-parser": "^1.33",
"runtime/frankenphp-symfony": "^0.2.0",
Expand Down
133 changes: 91 additions & 42 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Blog/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public function submitMessage(string $message): void
{
$messages = $this->loadMessages();

$messages[] = Message::ofUser($message);
$messages->add(Message::ofUser($message));
$response = $this->chain->call($messages);

assert($response instanceof TextResponse);

$messages[] = Message::ofAssistant($response->getContent());
$messages->add(Message::ofAssistant($response->getContent()));

$this->saveMessages($messages);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Blog/TwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Blog;

use PhpLlm\LlmChain\Model\Message\MessageBag;
use PhpLlm\LlmChain\Model\Message\MessageInterface;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveArg;
Expand All @@ -20,9 +20,12 @@ public function __construct(
) {
}

public function getMessages(): MessageBag
/**
* @return MessageInterface[]
*/
public function getMessages(): array
{
return $this->chat->loadMessages()->withoutSystemMessage();
return $this->chat->loadMessages()->withoutSystemMessage()->getMessages();
}

#[LiveAction]
Expand Down
9 changes: 5 additions & 4 deletions src/Wikipedia/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public function __construct(

public function loadMessages(): MessageBag
{
$default = new MessageBag();
$default[] = Message::forSystem('Please answer the users question based on Wikipedia and provide a link to the article.');
$default = new MessageBag(
Message::forSystem('Please answer the users question based on Wikipedia and provide a link to the article.')
);

return $this->requestStack->getSession()->get(self::SESSION_KEY, $default);
}
Expand All @@ -34,12 +35,12 @@ public function submitMessage(string $message): void
{
$messages = $this->loadMessages();

$messages[] = Message::ofUser($message);
$messages->add(Message::ofUser($message));
$response = $this->chain->call($messages);

assert($response instanceof TextResponse);

$messages[] = Message::ofAssistant($response->getContent());
$messages->add(Message::ofAssistant($response->getContent()));

$this->saveMessages($messages);
}
Expand Down
9 changes: 6 additions & 3 deletions src/Wikipedia/TwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace App\Wikipedia;

use PhpLlm\LlmChain\Model\Message\MessageBag;
use PhpLlm\LlmChain\Model\Message\MessageInterface;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveArg;
Expand All @@ -20,9 +20,12 @@ public function __construct(
) {
}

public function getMessages(): MessageBag
/**
* @return MessageInterface[]
*/
public function getMessages(): array
{
return $this->wikipedia->loadMessages()->withoutSystemMessage();
return $this->wikipedia->loadMessages()->withoutSystemMessage()->getMessages();
}

#[LiveAction]
Expand Down
Loading

0 comments on commit 7030227

Please sign in to comment.