jazz-max/yandex-ai-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

jazz-max/yandex-ai-laravel

Composer 安装命令:

composer require jazz-max/yandex-ai-laravel

包简介

Laravel SDK for Yandex AI Studio — Responses API, Vision OCR, Embeddings

README 文档

README

Laravel SDK for Yandex AI Studio — text generation (Responses API), Vision OCR, and Embeddings.

Installation

composer require jazz-max/yandex-ai-laravel

Publish config:

php artisan vendor:publish --tag=yandex-ai-config

Add to .env:

YANDEX_AI_API_KEY=your-api-key
YANDEX_AI_FOLDER_ID=your-folder-id

Quick Start

use JazzMax\YandexAi\Facades\YandexAi;

// Text generation
$response = YandexAi::responses()->create([
    'model'        => 'yandexgpt-5-lite',
    'instructions' => 'You are a helpful assistant.',
    'input'        => 'Hello!',
]);
echo $response->text;

// OCR
$result = YandexAi::vision()->recognizeText(
    file_get_contents('photo.jpg')
);
echo $result->text();

// Embeddings
$vector = YandexAi::embeddings()->embedQuery('search query');

API Clients

Responses API

$client = YandexAi::responses();
Method Description
create(array $params) Text generation
stream(array $params, Closure $onDelta) Streaming generation
continue(string $prevId, array $input) Multi-turn dialog
submitToolOutput(string $prevId, string $callId, string $output) Function calling follow-up
createBackground(array $params) Background async task
retrieve(string $id) Get background task status
poll(string $id, int $timeout) Poll until complete
formatModel(string $model) Add gpt://folder_id/ prefix
supportsReasoning(string $model) Check Pro model
calculateCostRub(...) Cost in RUB

Vision OCR

$client = YandexAi::vision();
Method Description
recognizeText(string $data, OcrModel $model) Sync image OCR
recognizeDocument(string $pdfData, OcrModel $model) Async PDF OCR

Available models (OcrModel enum):

  • Page — general text
  • PageColumnSort — multi-column layouts
  • Handwritten — handwriting (ru/en only)
  • Table — table extraction (ru/en only)
  • Markdown / MathMarkdown — structured output
  • Passport — Russian passport fields
  • DriverLicenseFront / DriverLicenseBack — driver license
  • VehicleRegistrationFront / VehicleRegistrationBack — vehicle registration
  • LicensePlates — license plate numbers

Embeddings

$client = YandexAi::embeddings();
Method Description
embedDocument(string $text) Document vector (for indexing)
embedQuery(string $text) Query vector (for searching)
cosineSimilarity(array $a, array $b) Vector similarity

Function Calling

use JazzMax\YandexAi\Tools\FunctionTool;

$tools = [
    FunctionTool::make('get_weather', 'Get weather for a city.', [
        'type'       => 'object',
        'properties' => [
            'city' => ['type' => 'string', 'description' => 'City name'],
        ],
        'required' => ['city'],
    ]),
];

$response = YandexAi::responses()->create([
    'model' => 'yandexgpt-5-lite',
    'input' => 'Weather in Moscow?',
    'tools' => $tools,
]);

if ($response->hasFunctionCall()) {
    $call = $response->functionCall;

    // Check if function call was extracted from text (fallback parser)
    if ($response->isFallbackFunctionCall) {
        // Model returned tool call as text — consider shortening tool descriptions
    }

    // Execute function, then submit result:
    $final = YandexAi::responses()->submitToolOutput(
        $response->id, $call['id'], '{"temp": 15}'
    );
}

Note: Yandex models sometimes return function calls as plain text instead of proper function_call items. The SDK includes a fallback parser that automatically extracts them. Check $response->isFallbackFunctionCall to detect this. Disable via YANDEX_AI_FUNCTION_CALL_FALLBACK=false.

Known Gotchas

See docs/GOTCHAS.md for production-tested pitfalls:

  1. Tool descriptions must be short (< 15 words, English) or models write calls as text
  2. Never use empty properties — always include a dummy property
  3. Auth header is Api-Key, not Bearer
  4. Models require URI format: gpt://folder_id/model
  5. Only gemma-3-27b-it supports images, and only via base64
  6. Prices are RUB per 1000 tokens, not USD per 1M
  7. Cached tokens cost 50% of prompt price
  8. Async OCR returns JSON Lines, not JSON array
  9. handwritten/table models only support ru/en

Configuration

All options in config/yandex-ai.php:

Key Default Description
api_key API key
folder_id Cloud folder ID
base_url https://ai.api.cloud.yandex.net/v1 API base URL
ocr_base_url https://ocr.api.cloud.yandex.net/ocr/v1 OCR API URL
timeout 120 HTTP timeout (seconds)
proxy null HTTP proxy URL
default_model yandexgpt-5-lite Default generation model
pricing RUB per 1000 tokens per model
ocr_pricing RUB per image per OCR model

Examples

See examples/ directory:

  • simple_request.php — basic generation
  • dialog.php — multi-turn conversation
  • streaming.php — streaming output
  • function_calling.php — tool use
  • reasoning.php — Pro model reasoning
  • vision_with_gpt.php — image analysis
  • vision_ocr.php — OCR recognition
  • vision_ocr_async.php — async PDF OCR
  • embeddings.php — semantic search
  • background.php — background tasks

Claude Code Skill

If you use Claude Code, install the companion skill (jazz-max/yandex-ai-laravel-skill) for expert guidance on this SDK:

npx skills add jazz-max/yandex-ai-laravel-skill

The skill provides full API reference, code examples, and knows all Yandex API gotchas.

Example prompts that activate the skill:

Add YandexGPT text generation to my Laravel app with streaming support

Build a document recognition feature using Yandex Vision OCR for passports and driver licenses

Implement semantic search with Yandex Embeddings and cosine similarity

Set up function calling with Yandex AI Studio in my Laravel project

Подключи Yandex AI Studio к моему Laravel-проекту и сделай artisan-команду для генерации текста через YandexGPT

Добавь распознавание документов через Yandex Vision OCR с поддержкой паспортов и водительских удостоверений

Реализуй семантический поиск по базе статей с помощью Yandex Embeddings

License

MIT

jazz-max/yandex-ai-laravel 适用场景与选型建议

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

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

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

围绕 jazz-max/yandex-ai-laravel 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-12