# swoole-ai **Repository Path**: cffycls/swoole-ai ## Basic Information - **Project Name**: swoole-ai - **Description**: swoole ai调用服务 - **Primary Language**: PHP - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-10-18 - **Last Updated**: 2024-05-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # swoole-ai服务 文档地址: [https://doc.swoole.com/@swoole-ai/chat.html](https://doc.swoole.com/@swoole-ai/chat.html) >下文使用结果:为代码在linux(WSL)上执行返回,win下无返回和报错。 ## 1. api返回测试 - demo/demo.php ```shell # $messages[] = ["role" => "user", "content" => "你是谁呀"]; $chunk = { "data": { "id": "chatcmpl-8ArnSGCQ6gLWXOoPu9D2UDCuCq2AL", "object": "chat.completion", "created": 1697600766, "model": "gpt-3.5-turbo-0613", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "我是一个AI助手,被设计用来提供帮助和回答问题。请问有什么我可以帮助你的吗?" }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 13, "completion_tokens": 42, "total_tokens": 55 } }, "code": 0, "message": "" } $res = $chunk['data']['choices']; $data = array_column($res, 'message'); // AI返回`message`格式,如果是多个、可以点击“换一个” [ { "role": "assistant", "content": "我是一个AI助手,被设计用来提供帮助和回答问题。请问有什么我可以帮助你的吗?" } ] ``` ## 2. 获取可用的模型列表 - demo/apis.php [模型列表](demo/model-list.json)