oliverearl/nomiai-php
Composer 安装命令:
composer require oliverearl/nomiai-php
包简介
PHP library for interacting with the Nomi.ai API
README 文档
README
This is a lightweight, PHP library for interacting with the Nomi.ai REST API. Nomi AI is a companionship application that uses artificial intelligence.
The only prerequisite is at least PHP 8.3 with the JSON extension. You'll need a HTTP client too, preferably Guzzle. If you're using a popular framework, you should be good to go.
If you're using Laravel, install the Laravel-specific library instead.
Installation
You can install the package via Composer:
composer require oliverearl/nomiai-php
Usage
Quickstart
After installing the library, getting started is easy:
$sdk = new \Nomiai\PhpSdk\NomiAI( token: $yourNomiAiApiKey, // Find it in the Integrations tab of the Nomi.ai app! // You can also provide a custom endpoint and HTTP Client as additional arguments. ); $nomis = $sdk->getNomis(); $conversation = $sdk->sendMessageToNomi($nomis[0], 'Hello!');
Retrieving Nomis
A numerically-indexed array of Nomis associated with an account can be returned using the library. If you know your Nomi's UUID, you can also retrieve their data individually.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ // Get all Nomis: /** @var array<int, \Nomiai\PhpSdk\Resources\Nomi> $nomis **/ $nomis = $sdk->getNomis(); // Grab a specific Nomi: /** @var \Nomiai\PhpSdk\Resources\Nomi $nomi **/ $nomi = $sdk->getNomi(id: 'Your Nomi UUID here');
Chatting with Nomis
Once you have a Nomi you want to chat with, or if you know their UUID, sending a message is easy. If all goes well, you
will end up with a MessageSet object containing both your message and the corresponding reply.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ /** @var \Nomiai\PhpSdk\Resources\Nomi $nomi **/ // Send a message directly to a Nomi $conversation = $sdk->sendMessageToNomi($nomi, 'Hello!'); // Or to their UUID! $conversation = $sdk->sendMessage($nomi->uuid, 'World!');
Retrieving an avatar
You can retrieve the avatar from a Nomi with either a Nomi object, or their corresponding UUID.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ /** @var \Nomiai\PhpSdk\Resources\Nomi $nomi **/ $avatar = $sdk->getAvatarFromNomi($nomi); // Or via the UUID: $avatar = $sdk->getAvatar($nomi->uuid); /* * Avatar is an object that might get more functionality down the line. For now, * to get the underlying .webp image, access the avatar property. */ $webp = $avatar->avatar; // You can also retrieve the underlying image by casting the object to a string. $image = (string) $avatar;
Rooms
Retrieving rooms
You can retrieve a numerically-indexed array of rooms associated with your account. Just like with Nomis, if you know the UUID of the room, you can also retrieve this individually.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ /** @var array<int, \Nomiai\PhpSdk\Resources\Room> $myRooms */ $myRooms = $sdk->getRooms(); /** @var \Nomiai\PhpSdk\Resources\Room $myFavouriteRoom */ $myFavouriteRoom = $sdk->getRoom(id: 'Your room UUID here');
Creating a room for your Nomis
Creating a room for Nomis can be done with either an array of Nomi objects, or an array containing their respective
UUIDs. A RoomRequest object exists to help you with this process, or you can use an associative array.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ // Get all Nomis: /** @var array<int, \Nomiai\PhpSdk\Resources\Nomi> $nomis **/ $nomis = $sdk->getNomis(); $request = new RoomRequest( name: 'Nomi HQ', note: 'The coolest place for Nomis to hang out', backchannelingEnabled: true, nomiUuids: $nomis, ); /** @var \Nomiai\PhpSdk\Resources\Room $room */ $room = $sdk->createRoom($request);
Updating and deleting rooms
Updating an existing room can also be done with a RoomRequest object, or an associative array containing the values
you wish to change. Whatever you choose, it's a good idea not to include fields you don't want to update.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ /** @var \Nomiai\PhpSdk\Resources\Room $room **/ $request = [ 'name' => 'The New Nomi HQ!', ]; $room = $sdk->updateRoom($room, $request); // You can also update a room by its UUID, for example if you don't have the full object. $room = $sdk->updateRoomById($room->uuid, $request);
Deleting a room is straightforward. These methods will simply return true as they will throw an appropriate
exception if something goes wrong.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ /** @var \Nomiai\PhpSdk\Resources\Room $room **/ $sdk->deleteRoom($room); // You can also delete it by its UUID $sdk->deleteRoomById($room->uuid);
Messaging within rooms
Sending a message into a room is easy. Be aware rooms do take time to initialise, so don't send a message to them immediately after creation. The message that was sent is returned as the result.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ /** @var \Nomiai\PhpSdk\Resources\Room $room **/ $message = 'Hello friends!'; $conversation = $sdk->sendMessageToRoom($room, $message); // Or via UUID: $conversation = $sdk->sendMessageToRoomById($room->uuid, $message);
Nomis can be prompted to send a message to a room. For more information about this, please check the Nomi.ai website.
/** @var \Nomiai\PhpSdk\NomiAI $sdk **/ /** @var \Nomiai\PhpSdk\Resources\Nomi $nomi **/ /** @var \Nomiai\PhpSdk\Resources\Room $room **/ $message = $sdk->requestNomiToMessageRoom($nomi, $room); // If you only have the Nomi UUID, and/or the room UUID, you have options: $message = $sdk->requestNomiByIdToMessageRoom($nomi->uuid, $room); $message = $sdk->requestNomiByIdToMessageRoomById($nomi->uuid, $room->uuid);
Functionality
The library is under active development. Complete feature availability is planned for the first major release.
| Nomi.ai API Functionality | Implemented | Release |
|---|---|---|
| Retrieve and view Nomis | Yes | v0.1.2-alpha |
| Send and receive messages to Nomis | Yes | v0.1.3-alpha |
| Retrieve Nomi avatars | Yes | v0.1.6-alpha |
| Retrieve rooms | Yes | v0.2.0-alpha |
| Create rooms | Yes | v0.2.0-alpha |
| Send messages into rooms | Yes | v0.2.0-alpha |
| Delete rooms | Yes | v0.2.0-alpha |
For more information regarding the Nomi.ai API, please check the documentation available here.
Testing
Tests are run using the Pest testing framework. You can run the suite like so:
composer test
Code Style
Laravel Pint is used to maintain the PER coding style. The linter can be run using:
composer format
PHPStan (level 8) is used for static analysis to catch type errors:
composer analyse
There are Pest architecture tests that also attempt to maintain certain conventions, including the use of strict typing where possible.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Your contributions are warmly welcomed! Anything from documentation, to optimisations, and additional tests. Pull requests must pass the existing test suite and conform to the required code style.
For new functionality, adequate tests must be included!
Credits
License
The MIT License (MIT). Please see License File for more information.
oliverearl/nomiai-php 适用场景与选型建议
oliverearl/nomiai-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 300 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「artificial intelligence」 「nomi ai」 「nomi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 oliverearl/nomiai-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 oliverearl/nomiai-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 oliverearl/nomiai-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
AI Content Translation for Laravel powered by SharpAPI.com
AI SEO Meta Tag Generator for Laravel powered by SharpAPI.com
PHP client for the IPLocate.io geolocation API
A laravel plugin to interact with AI providers
Boxalino Magento 2 plugin
Implementation of a k-Nearest Neighbors algorithm in PHP
统计信息
- 总下载量: 300
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-26