定制 eseperio/yii2-openai-responses 二次开发

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

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

eseperio/yii2-openai-responses

最新稳定版本:1.0.0

Composer 安装命令:

composer require eseperio/yii2-openai-responses

包简介

Yii2 component wrapper around openai-php client responses API.

README 文档

README

Easily integrate AI features into any Yii2 application. This library provides a drop‑in component to interact with OpenAI's Responses API.

Wrapper for the openai-php/client focused on the Responses API.

Installation

composer require eseperio/yii2-openai-responses

Configuration

Register the component in the application configuration:

return [
    'components' => [
        'openai' => [
            'class' => eseperio\openai\responses\OpenAiComponent::class,
            'apiKey' => 'YOUR_API_KEY',
            'model' => eseperio\openai\responses\enums\OpenAiModel::GPT_4_1_MINI,
            // optional defaults
            'instructions' => 'Always answer politely.',
            'instructionsPolicy' => eseperio\openai\responses\OpenAiComponent::INSTRUCTIONS_COMPLEMENTARY,
        ],
    ],
];

apiKey and instructions are write-only properties to avoid exposing sensitive values.

Available OpenAI models are exposed through the OpenAiModel enum for convenient access.

Usage

Basic request

$content = Yii::$app->openai->ask('Explain gravity.');

With instructions and metadata

$content = Yii::$app->openai->ask(
    'Explain gravity.',
    'Provide examples',
    ['topic' => 'physics']
);

Handling instructions

OpenAiComponent supports a policy for default instructions:

  • required – user instructions are ignored. If the caller provides instructions, an exception is thrown.
  • complementary – user instructions are appended to the default ones.
  • optional – user instructions override the defaults.

Creating custom requests

To override default configuration for a single call, create an AskRequest model:

$request = Yii::$app->openai->createAskRequest();
$request->model = eseperio\\openai\\responses\\enums\\OpenAiModel::GPT_4_1;
$request->input = 'Explain gravity.';
$request->instructions = 'Use simple terms.';

$content = Yii::$app->openai->ask($request);

The model is validated before sending the request. If validation fails an exception is thrown.

Retrieve last response

$response = Yii::$app->openai->getLastResponse();

The component returns only the text content of the first item in the response. The full response object can be obtained via getLastResponse().

Tests

Functional tests are included. Run them with:

vendor/bin/codecept run functional

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固