Download the PHP package snowman/ai without Composer

On this page you can find all versions of the php package snowman/ai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package ai

PHP AI SDK

轻量、多驱动、标准化输出的 PHP AI 接入 SDK

PHP Version CI Packagist Version

Features

快速上手

安装

Laravel 配置

.env 配置

使用

调试命令

驱动配置

Claude

OpenAI

DeepSeek

智谱 AI (GLM)

通义千问 (Qwen)

文心一言 (Wenxin)

月之暗面 (Moonshot)

MiniMax

Kimi for Coding

Xiaomi MiMo

高级配置

你可以在任意驱动的配置中加入以下选项:

Tools / Vision / Reasoning

Function Calling

Claude 驱动会自动把上面的 OpenAI 风格 Tool::define() 转换为 Anthropic 格式,返回的 toolCalls 结构保持一致。

Vision(图像输入)

Claude 只支持 base64 图片,可直接用 VisionMessage::claudeImage():

如果你使用 VisionMessage::image('data:image/png;base64,xxx'),Claude 驱动会自动转换成它需要的格式;纯 HTTP URL 图片暂不支持。

Reasoning Content

部分模型(如 DeepSeek、Kimi for Coding)会返回推理过程:

流式输出时,StreamChunk 也支持 reasoningContent 与 toolCalls:

API 参考

chat()

参数:

参数 类型 说明
messages array 消息数组,格式:[['role' => 'user|assistant|system', 'content' => '...']]
options.model string 模型名称
options.max_tokens int 最大输出 token 数
options.temperature float 温度参数

返回 AiResponse:

字段 类型 说明
content string 模型输出文本
model string 实际使用的模型名
usage TokenUsage token 用量
driver string 驱动标识
raw array 原始 API 响应
toolCalls ToolCall[]\|null 模型请求调用的工具
reasoningContent string\|null 模型推理过程文本
finishReason string\|null 结束原因(stop / tool_calls / length 等)
id string\|null 响应 ID
created int\|null 响应时间戳

stream()

返回 StreamChunk:

字段 类型 说明
content string 本次增量文本
done bool 是否结束
reasoningContent string\|null 本次增量推理文本
toolCalls ToolCall[]\|null 本次增量中的工具调用(通常在模型生成完工具参数后一次性返回)

流式解析兼容 \n、\r\n、\r 三种换行,并会自动跳过格式错误的 SSE 数据行。

切换驱动

自定义驱动

异常处理

异常类型

异常类 触发条件
AiAuthException API Key 无效或缺失(HTTP 401)
AiRateLimitException 请求频率超限(HTTP 429)
AiTimeoutException 连接或读取超时
AiServerException 模型端 5xx 错误
AiDriverNotFoundException 指定驱动未注册

ThinkPHP 6 使用

安装与发布配置

使用容器或门面

调试命令

纯 PHP 使用

测试

Contributing

欢迎提交 Issue 和 PR!

License

MIT


All versions of ai with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
guzzlehttp/guzzle Version ^6.5|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package snowman/ai contains the following files

Loading the files please wait ...