1. Go to this page and download the library: Download llm-agents/cli-chat library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
llm-agents / cli-chat example snippets
declare(strict_types=1);
namespace App\Endpoint\Console;
use LLM\Agents\Agent\AgentRegistryInterface;
use LLM\Agents\Chat\ChatHistoryRepositoryInterface;
use LLM\Agents\Chat\ChatServiceInterface;
use LLM\Agents\Chat\Console\ChatSession;
use LLM\Agents\Tool\ToolRegistryInterface;
use Ramsey\Uuid\Uuid;
use Spiral\Console\Attribute\AsCommand;
use Spiral\Console\Command;
use Spiral\Console\Console;
use Symfony\Component\Console\Cursor;
#[AsCommand(
name: 'chat',
description: 'Chat session'
)]
final class ChatCommand extends Command
{
public function __invoke(
AgentRegistryInterface $agents,
ChatServiceInterface $chat,
Console $console,
ChatHistoryRepositoryInterface $chatHistory,
ToolRegistryInterface $tools,
): int {
$cursor = new Cursor($this->output);
$cursor->clearScreen();
$console->run(command: 'agent:list', output: $this->output);
$chat = new ChatSession(
input: $this->input,
output: $this->output,
agents: $agents,
chat: $chat,
chatHistory: $chatHistory,
tools: $tools,
);
$chat->run(accountUuid: Uuid::fromString('00000000-0000-0000-0000-000000000000'));
return self::SUCCESS;
}
}
declare(strict_types=1);
namespace App\Endpoint\Console;
use LLM\Agents\Chat\ChatHistoryRepositoryInterface;
use LLM\Agents\Chat\ChatServiceInterface;
use LLM\Agents\Chat\Console\ChatHistory;
use Ramsey\Uuid\Uuid;
use Spiral\Console\Attribute\Argument;
use Spiral\Console\Attribute\AsCommand;
use Spiral\Console\Command;
#[AsCommand(
name: 'chat:session',
description: 'Chat session'
)]
final class ChatWindowCommand extends Command
{
#[Argument(name: 'session_uuid')]
public string $sessionUuid;
public function __invoke(
ChatHistoryRepositoryInterface $chatHistory,
ChatServiceInterface $chatService,
): int {
$chatWindow = new ChatHistory(
input: $this->input,
output: $this->output,
chatHistory: $chatHistory,
chat: $chatService,
);
$chatWindow->run(Uuid::fromString($this->sessionUuid));
return self::SUCCESS;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.