定制 adachsoft/ai-integration-xai 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adachsoft/ai-integration-xai

Composer 安装命令:

composer require adachsoft/ai-integration-xai

包简介

xAI SPI provider for adachsoft/ai-integration: tool-calling chat integration with Grok models (OpenAI-compatible endpoint).

README 文档

README

adachsoft/ai-integration-xai is a small integration library that plugs the x.ai chat completions API into the adachsoft/ai-integration package using a tool-calling capable SPI.

It provides a tiny, focused adapter that exposes x.ai as an OpenAI-compatible tool-calling chat provider.

Features

  • Minimal integration layer for x.ai chat completions
  • OpenAI-compatible tool-calling SPI using OpenAiCompatibleToolCallingChatSpi
  • Simple configuration via the XaiConfig value object
  • Factory XaiToolCallingChatSpiFactory that wires configuration into the SPI implementation
  • Sensible defaults for base URI and model ID

Requirements

  • PHP 8.3 or higher
  • adachsoft/ai-integration package (for SPI interfaces and OpenAI-compatible implementation)
  • An active x.ai API key

Installation

Install via Composer:

composer require adachsoft/ai-integration-xai

Make sure you also have adachsoft/ai-integration installed; Composer will usually handle this automatically via dependencies.

Configuration

The library exposes a single configuration value object: AdachSoft\AiIntegrationXai\Config\XaiConfig.

use AdachSoft\AiIntegrationXai\Config\XaiConfig;

$xaiConfig = new XaiConfig(
    apiKey: 'your-xai-api-key',
    defaultModelId: 'grok-4', // optional, default is 'grok-4'
    baseUri: 'https://api.x.ai/v1/chat/completions', // optional, default x.ai chat endpoint
    providerId: 'xai', // optional, identifier used by ai-integration
);

You can keep this configuration in your dependency injection container or any other configuration layer used in your application.

Usage

The main entry point of this library is the factory AdachSoft\AiIntegrationXai\XaiToolCallingChatSpiFactory, which produces a ToolCallingChatSpiInterface compatible instance backed by x.ai.

use AdachSoft\AiIntegrationXai\Config\XaiConfig;
use AdachSoft\AiIntegrationXai\XaiToolCallingChatSpiFactory;
use AdachSoft\AiIntegration\Spi\ToolCalling\ToolCallingChatSpiInterface;

$xaiConfig = new XaiConfig(apiKey: 'your-xai-api-key');

$factory = new XaiToolCallingChatSpiFactory($xaiConfig);

/** @var ToolCallingChatSpiInterface $chatSpi */
$chatSpi = $factory->create();

// You can now pass $chatSpi to the ai-integration tooling that expects a ToolCallingChatSpiInterface

From this point on, you should use the standard APIs exposed by adachsoft/ai-integration for building prompts, registering tools, and executing tool-calling chat interactions. This library is intentionally thin and only concerns itself with wiring x.ai into that SPI.

Default Model

The XaiConfig exposes a defaultModelId property (default grok-4). Depending on your usage of adachsoft/ai-integration, you may:

  • Use this value as the default model when constructing higher-level services
  • Override it per-request when your domain logic requires a different model

Versioning and Changelog

This library follows semantic versioning. All notable changes are documented in CHANGELOG.md.

The first tagged version is 0.1.0, which provides the initial x.ai tool-calling integration.

Testing

This project includes unit tests and a dedicated production test for the actual x.ai integration. To run the test suite, use:

vendor/bin/phpunit

Production tests that hit the real x.ai API are grouped separately (for example under a production group); consult the tests under tests/Production before running them against live services.

License

This library is open-sourced under the MIT license.

adachsoft/ai-integration-xai 适用场景与选型建议

adachsoft/ai-integration-xai 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「chat」 「integration」 「ai」 「spi」 「grok」 「llm」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 adachsoft/ai-integration-xai 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 adachsoft/ai-integration-xai 我们能提供哪些服务?
定制开发 / 二次开发

基于 adachsoft/ai-integration-xai 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 40
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-28