|
|
@@ -125,7 +125,7 @@ class DeepSeekService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 通用文生文方法 - 支持多模型流式输出和图片输入
|
|
|
+ * 通用文生文方法 - 支持多模型流式输出、图片输入;视频输入仅 Gemini 模型支持
|
|
|
*
|
|
|
* @param array $data 请求参数
|
|
|
* @return \Generator 返回生成器,用于流式输出
|
|
|
@@ -138,6 +138,13 @@ class DeepSeekService
|
|
|
$prompt = getProp($data, 'prompt', '');
|
|
|
$images = getProp($data, 'images', []); // 支持多张图片
|
|
|
$imageUrls = getProp($data, 'image_urls', []); // 支持图片URL
|
|
|
+ $videos = getProp($data, 'videos', []); // Gemini 支持视频文件
|
|
|
+ $videoUrls = getProp($data, 'video_urls', []); // Gemini 支持视频URL
|
|
|
+ $isGeminiModel = in_array($model, $this->gemini_text_models);
|
|
|
+
|
|
|
+ if ((!empty($videos) || !empty($videoUrls)) && !$isGeminiModel) {
|
|
|
+ Utils::throwError('20003:仅Gemini模型支持视频输入');
|
|
|
+ }
|
|
|
|
|
|
// 如果没有提供messages,则根据system_prompt、content和images构建
|
|
|
if (empty($messages)) {
|
|
|
@@ -152,7 +159,7 @@ class DeepSeekService
|
|
|
}
|
|
|
|
|
|
// 构建用户消息内容(支持文本+图片)
|
|
|
- if (!empty($prompt) || !empty($images) || !empty($imageUrls)) {
|
|
|
+ if (!empty($prompt) || !empty($images) || !empty($imageUrls) || !empty($videos) || !empty($videoUrls)) {
|
|
|
$userMessage = [
|
|
|
'role' => 'user',
|
|
|
'content' => []
|
|
|
@@ -202,6 +209,39 @@ class DeepSeekService
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 处理上传的视频文件(仅 Gemini)
|
|
|
+ if (!empty($videos) && $isGeminiModel) {
|
|
|
+ if (!is_array($videos)) {
|
|
|
+ $videos = [$videos];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($videos as $video) {
|
|
|
+ $inlineData = $this->processMediaToInlineData($video);
|
|
|
+ if ($inlineData) {
|
|
|
+ $userMessage['content'][] = [
|
|
|
+ 'type' => 'video',
|
|
|
+ 'inline_data' => $inlineData
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理视频URL(仅 Gemini)
|
|
|
+ if (!empty($videoUrls) && $isGeminiModel) {
|
|
|
+ if (!is_array($videoUrls)) {
|
|
|
+ $videoUrls = [$videoUrls];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($videoUrls as $url) {
|
|
|
+ if (!empty($url)) {
|
|
|
+ $userMessage['content'][] = [
|
|
|
+ 'type' => 'video_url',
|
|
|
+ 'video_url' => ['url' => $url]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 如果只有文本内容,简化为字符串格式
|
|
|
if (count($userMessage['content']) === 1 && $userMessage['content'][0]['type'] === 'text') {
|