cognesy/instructor-messages
Composer 安装命令:
composer require cognesy/instructor-messages
包简介
Message and message lists handling for Instructor PHP library
README 文档
README
Utilities for representing chat messages, multimodal content parts, and message stores. The API is immutable and designed for composing OpenAI-compatible message payloads.
Canonical content-part shape
Non-text parts are emitted in nested form. Legacy flat inputs are accepted and normalized on output.
Content stores parts in a ContentParts collection. Use partsList() if you need the value object.
You can also build content directly from a ContentParts collection via Content::fromParts().
parts() remains for backward compatibility but is deprecated.
Messages now use an internal MessageList collection for immutable operations while keeping the public API unchanged. Use messageList() if you need the value object.
You can construct a Messages instance from a MessageList via Messages::fromList().
Use headList() / tailList() when you need MessageList for partitions.
head() and tail() remain for backward compatibility but are deprecated.
all() remains for backward compatibility but is deprecated.
// text ['type' => 'text', 'text' => 'hello'] // image ['type' => 'image_url', 'image_url' => ['url' => 'https://example.com/image.jpg']] // audio ['type' => 'input_audio', 'input_audio' => ['data' => '...base64...', 'format' => 'wav']] // file ['type' => 'file', 'file' => ['file_data' => 'data:...base64...', 'file_name' => 'report.pdf', 'file_id' => 'file-...']]
Quick example
use Cognesy\Messages\Content; use Cognesy\Messages\Message; use Cognesy\Messages\ContentPart; use Cognesy\Messages\MessageSessionId; use Cognesy\Messages\Utils\Image; use Cognesy\Messages\MessageStore\Storage\InMemoryStorage; $message = new Message('user', Content::text('Describe this image:')); $message = $message->addContentPart(ContentPart::image(Image::fromUrl('https://example.com/cat.jpg', 'image/jpeg'))); $messageId = $message->id(); // MessageId value object $messageIdString = $messageId->toString(); // boundary serialization $payload = $message->toArray(); $storage = new InMemoryStorage(); $sessionId = $storage->createSession(MessageSessionId::generate()); $storage->append($sessionId, 'messages', $message);
Migration notes (2026-01-05)
- Non-text content parts are now emitted in nested form (e.g.
image_url,file,input_audio). Flat legacy inputs are still accepted but normalized on output. - File payloads use
file_name(nested underfile) as the canonical key. Messages::filter()with no callback now returns all non-empty messages (previously it returned an empty collection).
cognesy/instructor-messages 适用场景与选型建议
cognesy/instructor-messages 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 73 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cognesy/instructor-messages 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cognesy/instructor-messages 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 73
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-16