44 lines
1.2 KiB
PHP
Executable File
44 lines
1.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Service\common\ai\xunfei;
|
|
|
|
use App\BaseApp\BaseService;
|
|
use App\Service\common\ai\xunfei\client\XunFeiAiClientV1;
|
|
use App\Service\common\ai\xunfei\client\XunFeiAiClientV2;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class XunFeiAiService extends BaseService
|
|
{
|
|
protected array $optionField = ['id', 'drug_name'];
|
|
|
|
|
|
private $client;
|
|
public function __construct()
|
|
{
|
|
$this->isAuth = false;
|
|
parent::__construct();
|
|
// $this->client = XunFeiAiClientV2::getInstance();
|
|
$this->client = XunFeiAiClientV1::getInstance();
|
|
}
|
|
|
|
public function genSign(string $time, $dayDesc, $version = 1)
|
|
{
|
|
// 构建提示词
|
|
$prompt = $this->client->genSignPrompt($time, $dayDesc, $version);
|
|
// $prompt = $this->client->buildPrescriptionPrompt($userInfo, $drugModel->toArray());
|
|
|
|
// 发送请求(模拟)
|
|
$requestResult = $this->client->sendRequest($prompt, 'text');
|
|
if ($requestResult['code'] !== 0) {
|
|
throw new Exception('AI请求失败: ' . ($requestResult['message'] ?? '未知错误'));
|
|
}
|
|
|
|
// 解析响应(模拟)
|
|
$response = $this->client->parseResponse($requestResult);
|
|
|
|
return $response;
|
|
}
|
|
|
|
}
|