Download the PHP package webman/openai without Composer
On this page you can find all versions of the php package webman/openai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download webman/openai
More information about webman/openai
Files in webman/openai
Informations about the package openai
webman/openai
English | 简体中文
Non-blocking OpenAI client for PHP with coroutine support and a built-in connection pool, designed for Workerman / webman.
Installation
Requires PHP 8.1+ and a Workerman 5.1+ runtime.
Enable coroutines in webman
Setwebman.eventLoopinconfig/process.phptoWorkerman\Events\Fiber::class.
If theswooleorswowextension is installed, you may useWorkerman\Events\Swoole::classorWorkerman\Events\Swow::classinstead.
Quick overview (Workerman)
Non-streaming
Streaming
Chat: completions (Webman)
Note
API usage is the same whether you run under Workerman or webman; the examples below use webman.
Coroutines · non-streaming
Coroutines · streaming
Under coroutines, streaming returns a generator: send response headers to the client first, then emit each piece with Chunk, and finish with close.
Async callbacks · streaming
Async callbacks · non-streaming
Tool / function calling (tools)
Image: generations (Webman)
Coroutines
Async callbacks
Embedding: vectors (Webman)
Coroutines
Async callbacks
Audio: text-to-speech (TTS) (Webman)
Coroutines
Coroutines · streaming
Async callbacks · streaming
Audio: speech-to-text (STT / transcriptions) (Webman)
Coroutines · non-streaming
Coroutines · streaming (SSE events)
Async callbacks · non-streaming
Async callbacks · streaming
Gateway compatibility: Azure OpenAI
Coroutines · Chat streaming
Async callbacks · Chat streaming
Gateway compatibility: Alibaba Cloud DashScope (OpenAI-compatible mode)
Documentation: https://help.aliyun.com/zh/dashscope/developer-reference/compatibility-of-openai-with-dashscope
Coroutines · Chat streaming
When Chat is configured with an api URL that includes a path, if the path ends with a trailing slash (/), chat/completions is appended automatically (same pattern as the OpenAI-compatible path). For DashScope compatibility mode, use a base URL ending with /v1/:
Async callbacks · Chat streaming
Optional parameters
The second argument $options on each API method may include:
timeout: timeout in seconds (defaults differ slightly per API; see the Client constructor in the source).headers: extra HTTP headers (merged with the defaults).
Response headers: with_response
Non-streaming
Note
Other endpoints also supportwith_responseto obtain theResponseobject; usage is the same.
Streaming
Exceptions and errors
Error handling is unified across coroutine and async styles via the same Webman\Openai\OpenAIException class.
Coroutines · non-streaming
Coroutines · streaming
Async callbacks · non-streaming
All versions of openai with dependencies
workerman/workerman Version ^5.1
workerman/http-client Version ^3.1
revolt/event-loop Version ^1.0