{"id":36262628,"url":"https://github.com/webman-php/openai","last_synced_at":"2026-04-01T19:36:45.199Z","repository":{"id":218643468,"uuid":"746545873","full_name":"webman-php/openai","owner":"webman-php","description":"OpenAI PHP asynchronous client for workerman and webman.","archived":false,"fork":false,"pushed_at":"2026-03-20T07:34:46.000Z","size":75,"stargazers_count":65,"open_issues_count":4,"forks_count":9,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-03-21T00:23:40.370Z","etag":null,"topics":["chatgpt","client","openai","openai-php-sdk","webman","workerman"],"latest_commit_sha":null,"homepage":"https://www.workerman.net/plugin/157","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/webman-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-22T08:18:43.000Z","updated_at":"2026-03-20T07:31:38.000Z","dependencies_parsed_at":"2024-02-03T13:23:47.839Z","dependency_job_id":"af4f5862-1080-4bcb-a346-f8f1249d4d85","html_url":"https://github.com/webman-php/openai","commit_stats":null,"previous_names":["webman-php/openai"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/webman-php/openai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webman-php%2Fopenai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webman-php%2Fopenai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webman-php%2Fopenai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webman-php%2Fopenai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/webman-php","download_url":"https://codeload.github.com/webman-php/openai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/webman-php%2Fopenai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291152,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","client","openai","openai-php-sdk","webman","workerman"],"created_at":"2026-01-11T07:51:36.216Z","updated_at":"2026-04-01T19:36:45.175Z","avatar_url":"https://github.com/webman-php.png","language":"PHP","readme":"# openai\nOpenAI PHP asynchronous client for [workerman](https://github.com/walkor/workerman) and [webman](https://github.com/walkor/webman).\n\n# Install\n```\ncomposer create-project workerman/webman\ncd webman\ncomposer require webman/openai\n```\n\n### Chat with stream\n```php\n\u003c?php\nnamespace app\\controller;\nuse support\\Request;\n\nuse Webman\\Openai\\Chat;\nuse Workerman\\Protocols\\Http\\Chunk;\n\nclass ChatController\n{\n    public function completions(Request $request)\n    {\n        $connection = $request-\u003econnection;\n        $chat = new Chat(['apikey' =\u003e 'sk-xx', 'api' =\u003e 'https://api.openai.com']);\n        $chat-\u003ecompletions(\n            [\n                'model' =\u003e 'gpt-3.5-turbo',\n                'stream' =\u003e true,\n                'messages' =\u003e [['role' =\u003e 'user', 'content' =\u003e 'hello']],\n            ], [\n            'timeout' =\u003e 600, //可选参数,默认600s\n            'stream' =\u003e function($data) use ($connection) {\n                $connection-\u003esend(new Chunk(json_encode($data, JSON_UNESCAPED_UNICODE) . \"\\n\"));\n            },\n            'complete' =\u003e function($result, $response) use ($connection) {\n                if (isset($result['error'])) {\n                    $connection-\u003esend(new Chunk(json_encode($result, JSON_UNESCAPED_UNICODE) . \"\\n\"));\n                }\n                $connection-\u003esend(new Chunk(''));\n            },\n        ]);\n        return response()-\u003ewithHeaders([\n            \"Transfer-Encoding\" =\u003e \"chunked\",\n        ]);\n    }\n}\n```\n\n### Chat without stream\n```php\n\u003c?php\nnamespace app\\controller;\nuse support\\Request;\n\nuse Webman\\Openai\\Chat;\nuse Workerman\\Protocols\\Http\\Chunk;\n\nclass ChatController\n{\n    public function completions(Request $request)\n    {\n        $connection = $request-\u003econnection;\n        $chat = new Chat(['apikey' =\u003e 'sk-xxx', 'api' =\u003e 'https://api.openai.com']);\n        $chat-\u003ecompletions(\n            [\n                'model' =\u003e 'gpt-3.5-turbo',\n                'messages' =\u003e [['role' =\u003e 'user', 'content' =\u003e 'hello']],\n            ], [\n            'complete' =\u003e function($result, $response) use ($connection) {\n                $connection-\u003esend(new Chunk(json_encode($result, JSON_UNESCAPED_UNICODE) . \"\\n\"));\n                $connection-\u003esend(new Chunk(''));\n            },\n        ]);\n        return response()-\u003ewithHeaders([\n            \"Transfer-Encoding\" =\u003e \"chunked\",\n        ]);\n    }\n}\n```\n\n### Image generations\n```php\n\u003c?php\nnamespace app\\controller;\nuse support\\Request;\n\nuse Webman\\Openai\\Image;\nuse Workerman\\Protocols\\Http\\Chunk;\n\nclass ImageController\n{\n    public function generations(Request $request)\n    {\n        $connection = $request-\u003econnection;\n        $image = new Image(['apikey' =\u003e 'sk-xxx', 'api' =\u003e 'https://api.openai.com']);\n        $image-\u003egenerations([\n            'model' =\u003e 'dall-e-3',\n            'prompt' =\u003e 'a dog',\n            'n' =\u003e 1,\n            'size' =\u003e \"1024x1024\"\n        ], [\n            'complete' =\u003e function($result) use ($connection) {\n                $connection-\u003esend(new Chunk(json_encode($result)));\n                $connection-\u003esend(new Chunk(''));\n            }\n        ]);\n        return response()-\u003ewithHeaders([\n            \"Content-Type\" =\u003e \"application/json\",\n            \"Transfer-Encoding\" =\u003e \"chunked\",\n        ]);\n    }\n\n}\n```\n\n### Audio speech\n```php\n\u003c?php\nnamespace app\\controller;\nuse support\\Request;\n\nuse Webman\\Openai\\Audio;\nuse Workerman\\Protocols\\Http\\Chunk;\n\nclass AudioController\n{\n    public function speech(Request $request)\n    {\n        $connection = $request-\u003econnection;\n        $audio = new Audio(['apikey' =\u003e 'sk-xxx', 'api' =\u003e 'https://api.openai.com']);\n        $audio-\u003espeech([\n            'model' =\u003e 'tts-1',\n            'input' =\u003e '你好，有什么可以帮您？',\n            'voice' =\u003e 'echo'\n        ], [\n            'stream' =\u003e function($buffer) use ($connection) {\n                $connection-\u003esend(new Chunk($buffer));\n            },\n            'complete' =\u003e function($result, $response) use ($connection) {\n                $connection-\u003esend(new Chunk(''));\n            }\n        ]);\n        return response()-\u003ewithHeaders([\n            \"Content-Type\" =\u003e \"audio/mpeg\",\n            \"Transfer-Encoding\" =\u003e \"chunked\",\n        ]);\n    }\n}\n```\n\n### Embeddings\n```php\n\u003c?php\nnamespace app\\controller;\nuse support\\Request;\n\nuse Webman\\Openai\\Embedding;\nuse Workerman\\Protocols\\Http\\Chunk;\n\nclass EmbeddingController\n{\n    public function create(Request $request)\n    {\n        $connection = $request-\u003econnection;\n        $embedding = new Embedding(['apikey' =\u003e 'sk-xxx', 'api' =\u003e 'https://api.openai.com']);\n        $embedding-\u003ecreate([\n            'model' =\u003e 'text-embedding-ada-002',\n            'input' =\u003e 'Some words',\n            'encodding_format' =\u003e 'float',\n        ], [\n            'complete' =\u003e function($result) use ($connection) {\n                $connection-\u003esend(new Chunk(json_encode($result)));\n                $connection-\u003esend(new Chunk(''));\n            }\n        ]);\n        return response()-\u003ewithHeaders([\n            \"Content-Type\" =\u003e \"application/json\",\n            \"Transfer-Encoding\" =\u003e \"chunked\",\n        ]);\n    }\n}\n```\n\n### Azure openai\n```php\npublic function completions(Request $request)\n{\n    $connection = $request-\u003econnection;\n    $chat = new Chat(['api' =\u003e 'https://xxx.openai.azure.com', 'apikey' =\u003e 'xxx', 'isAzure' =\u003e true]);\n    $chat-\u003ecompletions(\n        [\n            'model' =\u003e 'gpt-3.5-turbo',\n            'stream' =\u003e true,\n            'messages' =\u003e [['role' =\u003e 'user', 'content' =\u003e 'hello']],\n        ], [\n        'stream' =\u003e function($data) use ($connection) {\n            $connection-\u003esend(new Chunk(json_encode($data, JSON_UNESCAPED_UNICODE) . \"\\n\"));\n        },\n        'complete' =\u003e function($result, $response) use ($connection) {\n            if (isset($result['error'])) {\n                $connection-\u003esend(new Chunk(json_encode($result, JSON_UNESCAPED_UNICODE) . \"\\n\"));\n            }\n            $connection-\u003esend(new Chunk(''));\n        },\n    ]);\n    return response()-\u003ewithHeaders([\n        \"Transfer-Encoding\" =\u003e \"chunked\",\n    ]);\n}\n```\n### Qwen openai\n\n```php\npublic function completions(Request $request)\n{\n    $connection = $request-\u003econnection;\n    $chat = new Chat(['api' =\u003e 'https://dashscope.aliyuncs.com/compatible-mode', 'apikey' =\u003e 'xxx']);\n    $chat-\u003ecompletions(\n        [\n            'model' =\u003e 'qwen-turbo',\n            'stream' =\u003e true,\n            'messages' =\u003e [['role' =\u003e 'user', 'content' =\u003e 'hello']],\n        ], [\n        'stream' =\u003e function($data) use ($connection) {\n            $connection-\u003esend(new Chunk(json_encode($data, JSON_UNESCAPED_UNICODE) . \"\\n\"));\n        },\n        'complete' =\u003e function($result, $response) use ($connection) {\n            if (isset($result['error'])) {\n                $connection-\u003esend(new Chunk(json_encode($result, JSON_UNESCAPED_UNICODE) . \"\\n\"));\n            }\n            $connection-\u003esend(new Chunk(''));\n        },\n    ]);\n    return response()-\u003ewithHeaders([\n        \"Transfer-Encoding\" =\u003e \"chunked\",\n    ]);\n}\n```\n\u003e Help：https://help.aliyun.com/zh/dashscope/developer-reference/compatibility-of-openai-with-dashscope\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebman-php%2Fopenai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwebman-php%2Fopenai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwebman-php%2Fopenai/lists"}