llm-agents/cli-chat
Composer 安装命令:
composer require llm-agents/cli-chat
包简介
A simple CLI chat application
README 文档
README
This cool package gives you a CLI chat interface to chat with LLM agents. It's built on top of Symfony Console, so you know it's gonna be smooth sailing.
What's this all about?
- Start chat sessions with different agents
- Send messages and get responses
- Handle tool calls and their results
- Display chat history
It's perfect for testing your agents or building CLI-based chatbots.
Installation
You can install the package via Composer:
composer require llm-agents/cli-chat
Configuration
This package doesn't require much configuration. The main things you'll need to set up are:
- An implementation of
LLM\Agents\Chat\ChatServiceInterface - An implementation of
LLM\Agents\Chat\ChatHistoryRepositoryInterface - An implementation of
LLM\Agents\Chat\SessionInterface - Your agent registry
- Your tool registry
Usage
To use this package, you need to create two console commands in your application:
- A command to start a chat session
- A command to display chat history
Here's how you can set these up using Spiral framework:
Note: You can use any framework or library that supports Symfony Console commands.
Chat Session Command
This command starts a new chat session:
<?php 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; } }
Chat History Command
This command displays the chat history for a specific session:
<?php 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; } }
To use these commands, you'll need to register them with your application's console kernel or command loader, depending on your framework.
Class Diagram
Here's a quick look at how everything fits together:
classDiagram
class ChatServiceInterface {
+getSession(UuidInterface) SessionInterface
+updateSession(SessionInterface) void
+startSession(UuidInterface, string) UuidInterface
+ask(UuidInterface, string|Stringable) UuidInterface
+closeSession(UuidInterface) void
}
class SessionInterface {
+getUuid() UuidInterface
+getAgentName() string
+updateHistory(array) void
+isFinished() bool
}
class ChatHistoryRepositoryInterface {
+clear(UuidInterface) void
+getMessages(UuidInterface) iterable
+addMessage(UuidInterface, object) void
}
class ChatSession {
-io: ChatStyle
-cursor: Cursor
+run(UuidInterface, string) void
}
class ChatHistory {
-io: ChatStyle
+run(UuidInterface) void
}
class StreamChunkCallback {
+__invoke(?string, bool, ?string) void
}
ChatServiceInterface -- SessionInterface
ChatSession -- ChatServiceInterface
ChatSession -- ChatHistoryRepositoryInterface
ChatHistory -- ChatHistoryRepositoryInterface
ChatHistory -- ChatServiceInterface
Loading
Contributing
We'd love your help to make this package even better! Here's how you can contribute:
- Fork the repository
- Write some awesome code
- Create a new Pull Request
Please make sure your code follows PSR-12 coding standards and include tests for any new features.
License
This package is open-sourced software licensed under the MIT license. Feel free to use it, modify it, and share it!
That's all, folks! If you have any questions or run into any issues, don't hesitate to open an issue on GitHub.
llm-agents/cli-chat 适用场景与选型建议
llm-agents/cli-chat 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 246 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 llm-agents/cli-chat 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 llm-agents/cli-chat 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 246
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-31