定制 assistant-engine/php-openai-client 二次开发

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

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

assistant-engine/php-openai-client

最新稳定版本:v0.0.5

Composer 安装命令:

composer require assistant-engine/php-openai-client

包简介

Experimental PHP client for OpenAI’s new Responses API

README 文档

README

Hero

Experimental PHP OpenAI Responses Client

This is an experimental PHP client for the new OpenAI Responses API. It implements the create, find, delete and list input items methods from the API, returning mapped response objects for seamless integration.

The goal of this experimental client is to provide a quick, easy-to-use library that allows you to experiment with the new endpoints from early on.

Installation

Install the package via Composer:

composer require assistant-engine/php-openai-client

Usage

Conversation State

use AssistantEngine\OpenAI\Client;

$client = Client::make($_ENV['OPEN_AI_KEY']);

$response = $client->responses()->create([
    'model' => 'gpt-4o',
    'input' => "Can you recommend me what I can eat today?"
]);

print_r($response->getOutputText());

$response2 = $client->responses()->create([
    'model' => 'gpt-4o',
    'previous_response_id' => $response->id,
    'input' => "maybe Pizza?",
]);

print_r($response2->getOutputText());

File Search

use AssistantEngine\OpenAI\Client;

$client = Client::make($_ENV['OPEN_AI_KEY']);

$response = $client->responses()->create([
    'model' => 'gpt-4o',
    'tools' => [
        [
            'type' => 'file_search',
            "vector_store_ids" => ["vs_123456789"]
        ]
    ],
    'input' => "when is the event in berlin happening?"
]);

print_r($response->getOutputText());

Web Search

use AssistantEngine\OpenAI\Client;

$client = Client::make($_ENV['OPEN_AI_KEY']);

$response = $client->responses()->create([
    'model' => 'gpt-4o',
    'tools' => [
        [
            'type' => 'web_search_preview'
        ]
    ],
    'input' => "what was a positive news story from today?"
]);

print_r($response->getOutputText());

Computer Use

use AssistantEngine\OpenAI\Client;

$client = Client::make($_ENV['OPEN_AI_KEY']);

// Path to your image file
$imageFilePath = './path/to/browser_screenshot.png';

// Read the image file contents
$imageData = file_get_contents($imageFilePath);

// Base64 encode the image data
$base64Image = base64_encode($imageData);

$response = $client->responses()->create([
    'model' => 'computer-use-preview',
    'tools' => [
        [
            'type' => 'computer_use_preview',
            "display_width" => 1024,
            "display_height" => 768,
            "environment" => "browser"
        ]
    ],
    'input' => [
        [
            "role" => "user",
            "content" => [
                [
                    "type" => "input_text",
                    "text" => "Can you find me products in sale?"
                ],
                [
                    "type" => "input_image",
                    "image_url" => "data:image/png;base64," . $base64Image
                ]
            ]
        ],

    ],
    "truncation" => "auto"
]);

print_r($response);

List input items

use AssistantEngine\OpenAI\Client;

$client = Client::make($_ENV['OPEN_AI_KEY']);
// Define query parameters for pagination and ordering
$params = [
    'after'  => 'item-id-to-start-after',  // Optional: list items after this ID
    'limit'  => 50,                        // Optional: limit number of items (default is 20)
    'order'  => 'desc',                    // Optional: order items in descending order
];

$respId = "resp_123456789";
$list = $client->responses()->inputItems()->list($respId, $params);

print_r($list);

Please note that this is an experimental client with the purpose to give you a fast possibility to explore the new OpenAI responses API with PHP. Please expect bugs and that not every feature from the new API is implemented.

More Repositories

We’ve created more repositories to make AI integration even simpler and more powerful! Check them out:

  • Open Functions Core: Powerful primitives that simplify LLM calling and ready-to-use integrations for popular platforms such as Slack, GitHub, Bitbucket, Trello, and Jira Service Desk.
  • Filament Assistant: Add conversational AI capabilities directly into Laravel Filament.

We are a young startup aiming to make it easy for developers to add AI to their applications. We welcome feedback, questions, comments, and contributions. Feel free to contact us at contact@assistant-engine.com.

Consultancy & Support

Do you need assistance integrating AI into your PHP applications, or help setting it up?
We offer consultancy services to help you get the most out of our packages, whether you’re just getting started or looking to optimize an existing setup.

Reach out to us at contact@assistant-engine.com.

Contributing

We welcome contributions from the community! Feel free to submit pull requests, open issues, and help us improve the package.

License

This project is licensed under the MIT License. Please see License File for more information.

assistant-engine/php-openai-client 适用场景与选型建议

assistant-engine/php-openai-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 844 次下载、GitHub Stars 达 6, 最近一次更新时间为 2025 年 03 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 assistant-engine/php-openai-client 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-12