<?php
require __DIR__ . '/vendor/autoload.php';

use OpenAI\Client;

$baseUrl="https://wishub.ctyun.cn:1443/v1"; //api前缀地址
//从环境变量获取API密钥，如果没有设置，也可以直接终端执行export XIRANG_app_key="xxx"
$appkey = getenv("XIRANG_app_key");
$modelId="xxxxx"; //模型id
$question="你好，介绍一下自己"; //#对话问题

$client = OpenAI::factory()
    ->withApiKey($appkey)
    ->withBaseUri($baseUrl)
    ->make();

$response = $client->chat()->create([
    'model' => $modelId,
    'messages' => [
        ['role' => 'user', 'content' => $question],
    ],
]);


foreach ($response->choices as $result) {
    echo $result->message->content;
}