承接 aisdk/openai-compatible 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

aisdk/openai-compatible

Composer 安装命令:

composer require aisdk/openai-compatible

包简介

Shared OpenAI-compatible chat-completions wire format (request builder, response/stream parsers) for the PHP AI SDK.

README 文档

README

Shared OpenAI-compatible chat-completions wire adapter for the PHP AI SDK. Reusable by any provider that speaks the OpenAI /chat/completions REST/SSE protocol.

Installation

composer require aisdk/openai-compatible

What This Package Does

This package provides the shared wire-format bridge between core portable contracts (AiSdk\*) and the OpenAI-compatible chat-completions shape. It is used by providers like Groq, xAI, OpenRouter, and others that implement the OpenAI-compatible API.

It owns:

  • Request body building (ChatRequestBuilder)
  • Response parsing (ChatResponseParser)
  • SSE stream parsing (ChatStreamParser)
  • Message conversion (ChatMessageConverter)
  • Tool conversion (ChatToolConverter)
  • Usage normalization (ChatUsage)
  • Finish reason mapping (MapsFinishReason)

It does not own:

  • Provider authentication
  • Model catalogs
  • Provider-specific quirks or fallback behavior

Usage

This package is consumed by provider packages, not directly by end users. A provider that speaks OpenAI-compatible chat completions uses it like this:

use AiSdk\OpenAICompatible\ChatRequestBuilder;
use AiSdk\OpenAICompatible\ChatResponseParser;
use AiSdk\OpenAICompatible\ChatStreamParser;

$body = ChatRequestBuilder::build($modelId, $providerName, $request, stream: false);
$payload = $this->runner()->postJson($url, $body, $headers, $providerName);
$response = ChatResponseParser::parse($payload, $providerName);

Provider Integration

To build a provider on top of this package:

  1. Depend on aisdk/core and aisdk/openai-compatible.
  2. Create a provider class extending BaseProvider.
  3. Create a text model extending BaseModel that calls ChatRequestBuilder::build(), ChatResponseParser::parse(), and ChatStreamParser::parse().
  4. Add provider-specific auth, base URL, headers, and model catalog.
  5. Apply any provider-specific adaptations (e.g., structured output downgrades) after calling ChatRequestBuilder::build().

Testing

composer test

Links

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固