67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace App\Service\common\ai;
|
||
|
||
/**
|
||
* AI 对话结果 DTO
|
||
* 统一各供应商响应,便于落库与业务解析
|
||
*/
|
||
class AiChatResult
|
||
{
|
||
/** 助手文本内容(已从 choices[0].message.content 取出) */
|
||
public string $content = '';
|
||
|
||
/** 供应商原始响应数组(便于排障) */
|
||
public array $raw = [];
|
||
|
||
/** 供应商标识 */
|
||
public string $provider = '';
|
||
|
||
/** 实际使用的模型名 */
|
||
public string $model = '';
|
||
|
||
/** token 用量(若供应商返回) */
|
||
public array $usage = [];
|
||
|
||
/** 本次调用使用的 API Key ID(库内密钥;env 回落为 0) */
|
||
public int $apiKeyId = 0;
|
||
|
||
/**
|
||
* @param string $content 助手文本
|
||
* @param array $raw 原始响应
|
||
* @param string $provider 供应商
|
||
* @param string $model 模型
|
||
* @param array $usage usage 字段
|
||
* @param int $apiKeyId 密钥 ID
|
||
*/
|
||
public function __construct(
|
||
string $content = '',
|
||
array $raw = [],
|
||
string $provider = '',
|
||
string $model = '',
|
||
array $usage = [],
|
||
int $apiKeyId = 0
|
||
) {
|
||
$this->content = $content;
|
||
$this->raw = $raw;
|
||
$this->provider = $provider;
|
||
$this->model = $model;
|
||
$this->usage = $usage;
|
||
$this->apiKeyId = $apiKeyId;
|
||
}
|
||
|
||
/**
|
||
* 转为数组(落库 / 接口返回用)
|
||
*/
|
||
public function toArray(): array
|
||
{
|
||
return [
|
||
'content' => $this->content,
|
||
'provider' => $this->provider,
|
||
'model' => $this->model,
|
||
'usage' => $this->usage,
|
||
'api_key_id' => $this->apiKeyId,
|
||
];
|
||
}
|
||
}
|