gengx
This commit is contained in:
@@ -12,6 +12,7 @@ use app\service\ComfyUIService;
|
||||
use app\service\CosyVoiceService;
|
||||
use app\service\DifyService;
|
||||
use app\service\DocumentTextService;
|
||||
use app\service\GuestAccessService;
|
||||
use app\service\OpenAIService;
|
||||
use app\service\PermissionService;
|
||||
use app\service\SettingsService;
|
||||
@@ -21,7 +22,8 @@ class Chat extends BaseApi
|
||||
{
|
||||
public function speech()
|
||||
{
|
||||
$this->authUser();
|
||||
$user = $this->authUser();
|
||||
GuestAccessService::assertAccountRequired($user, '语音对话');
|
||||
$input = $this->request->post();
|
||||
$text = trim((string) ($input['text'] ?? ''));
|
||||
|
||||
@@ -71,7 +73,8 @@ class Chat extends BaseApi
|
||||
|
||||
public function speechStream(): never
|
||||
{
|
||||
$this->authUser();
|
||||
$user = $this->authUser();
|
||||
GuestAccessService::assertAccountRequired($user, '语音对话');
|
||||
$input = $this->request->post();
|
||||
$text = trim((string) ($input['text'] ?? ''));
|
||||
$requestId = trim((string) ($input['request_id'] ?? ''));
|
||||
@@ -134,7 +137,8 @@ class Chat extends BaseApi
|
||||
|
||||
public function speechCancel()
|
||||
{
|
||||
$this->authUser();
|
||||
$user = $this->authUser();
|
||||
GuestAccessService::assertAccountRequired($user, '语音对话');
|
||||
$requestId = trim((string) $this->request->post('request_id', ''));
|
||||
if (!preg_match('/^[A-Za-z0-9._:-]{8,128}$/', $requestId)) {
|
||||
return $this->error('语音请求标识无效', 422);
|
||||
@@ -168,6 +172,7 @@ class Chat extends BaseApi
|
||||
if (!is_array($attachments)) {
|
||||
return $this->error('附件格式无效', 422);
|
||||
}
|
||||
GuestAccessService::assertTextChatOnly($user, $attachments, $agentId, $imageTool, $voiceMode);
|
||||
|
||||
if (!$conversationId) {
|
||||
return $this->error('缺少 conversation_id');
|
||||
@@ -178,10 +183,6 @@ class Chat extends BaseApi
|
||||
if ($imageTool !== '' && !$this->hasImageAttachments($attachments)) {
|
||||
return $this->error('图片处理工具需要一张原图', 422);
|
||||
}
|
||||
if (!empty($user['is_guest']) && $this->hasImageAttachments($attachments)) {
|
||||
return $this->error('游客模式不支持发送图片,请登录后重试', 403);
|
||||
}
|
||||
|
||||
$agent = AgentCatalog::find($agentId);
|
||||
if ($agentId !== '' && !$agent) {
|
||||
return $this->error('所选 Agent 不存在或已停用', 422);
|
||||
@@ -197,7 +198,17 @@ class Chat extends BaseApi
|
||||
}
|
||||
|
||||
$imageGenerationContent = $content;
|
||||
$model = OpenAIService::getModel($conversation->model_id ? (int) $conversation->model_id : null);
|
||||
if (GuestAccessService::isGuest($user)) {
|
||||
$model = GuestAccessService::model();
|
||||
if ((int) $conversation->model_id !== (int) $model->id) {
|
||||
$conversation->save([
|
||||
'model_id' => (int) $model->id,
|
||||
'external_conversation_id' => null,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
$model = OpenAIService::getModel($conversation->model_id ? (int) $conversation->model_id : null);
|
||||
}
|
||||
if ($imageTool !== '' && $imageTool !== 'commit') {
|
||||
$preferredImageModelId = ($model->provider ?? '') === 'comfy' ? (int) ($model->id ?? 0) : null;
|
||||
$model = OpenAIService::getImageModel($preferredImageModelId ?: null);
|
||||
|
||||
Reference in New Issue
Block a user