承接 aisdk/ollama 相关项目开发

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

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

aisdk/ollama

Composer 安装命令:

composer require aisdk/ollama

包简介

Official Ollama provider for the PHP AI SDK.

README 文档

README

Official Ollama provider for the framework-agnostic PHP AI SDK. It supports text, streaming, and Ollama's experimental OpenAI-compatible image endpoint.

Installation

composer require aisdk/ollama

Basic Usage

use AiSdk\Generate;
use AiSdk\Ollama;

$result = Generate::text()
    ->model(Ollama::model('your-installed-model'))
    ->prompt('Explain closures in PHP.')
    ->run();

echo $result->text;

Any model installed on the configured Ollama server can be selected. Like every AI SDK provider package, this package treats model IDs as opaque provider values and does not ship a model inventory.

Available models

Read the current server registry instead of relying on package data:

$models = Ollama::availableModels();

foreach ($models as $model) {
    echo $model->id;
}

availableModels() calls Ollama's native /api/tags endpoint. To load a model's optional capabilities—such as vision, tools, audio input, or thinking—inspect it explicitly:

$definition = Ollama::inspectModel('your-installed-model');

if (in_array('image_input', $definition->capabilityNames(), true)) {
    // The installed model advertises vision support.
}

Inspection calls /api/show and returns informational details reported by the current Ollama server. It does not change adapter behavior, and ordinary generation does not perform hidden discovery requests.

Image generation

$image = Generate::image('A small robot')
    ->model(Ollama::image('your-installed-image-model'))
    ->size('1024x1024')
    ->run();

Image generation is experimental in Ollama. Ollama does not currently expose an OpenAI-compatible speech endpoint, so this package intentionally does not implement Generate::speech().

Streaming

use AiSdk\Generate;
use AiSdk\Ollama;

foreach (Generate::text('Tell me a story.')->model(Ollama::model('your-installed-model'))->stream()->chunks() as $chunk) {
    echo $chunk;
}

Configuration

No API key is required for a local Ollama server. Provide one only if your server is protected.

Variable Description Default
OLLAMA_BASE_URL Base URL for the OpenAI-compatible API http://localhost:11434/v1
OLLAMA_NATIVE_BASE_URL Base URL for native discovery endpoints Derived by removing /v1 from OLLAMA_BASE_URL
OLLAMA_API_KEY Optional bearer token
Ollama::create([
    'baseUrl' => 'http://localhost:11434/v1',
    'nativeBaseUrl' => 'http://localhost:11434',
]);

Testing

composer test

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固