|
|
@@ -30,7 +30,7 @@ class DeepSeekService
|
|
|
|
|
|
public function __construct(AIImageGenerationService $aiImageGenerationService) {
|
|
|
$this->aiImageGenerationService = $aiImageGenerationService;
|
|
|
- $this->url = 'https://api.deepseek.com/chat/completions';
|
|
|
+ $this->url = 'https://api.deepseek.com/chat/completions'; // DeepSeek API请求地址
|
|
|
$this->api_key = env('DEEPSEEK_API_KEY');
|
|
|
$this->headers = [
|
|
|
'Authorization' => 'Bearer '.$this->api_key,
|
|
|
@@ -1935,8 +1935,7 @@ class DeepSeekService
|
|
|
$bid = getProp($data, 'bid', 0);
|
|
|
$question =getProp($data, 'question', "请根据实例格式完成剧本大纲");
|
|
|
$prompt = getProp($data, 'prompt');
|
|
|
- $model = getProp($data, 'model', 'v3');
|
|
|
- $model = $model == 'r1' ? 'deepseek-reasoner' : 'deepseek-chat';
|
|
|
+ $model = getProp($data, 'model');
|
|
|
$is_multi = getProp($data, 'is_multi', 1);
|
|
|
|
|
|
// if (!$file && !$content && !$bid) {
|
|
|
@@ -2037,10 +2036,10 @@ class DeepSeekService
|
|
|
$usage = [];
|
|
|
|
|
|
if (in_array($model, ['deepseek-reasoner', 'deepseek-chat'])) {
|
|
|
- // R1模型使用DeepSeek API
|
|
|
+ // R1和V3模型使用DeepSeek API
|
|
|
$streamGenerator = $this->deepSeekStreamResponse($post_data);
|
|
|
} else {
|
|
|
- // V3模型使用火山引擎API
|
|
|
+ // 其他模型使用火山引擎API
|
|
|
$streamGenerator = $this->volcEngineChatCompletion($post_data);
|
|
|
}
|
|
|
|
|
|
@@ -2193,8 +2192,7 @@ class DeepSeekService
|
|
|
}
|
|
|
$question =getProp($data, 'question', "请根据实例格式完成剧本大纲");
|
|
|
$prompt = getProp($data, 'prompt', '帮我根据给出的内容生成短剧大纲');
|
|
|
- $model = getProp($data, 'model', 'v3');
|
|
|
- $model = $model == 'r1' ? 'deepseek-reasoner' : 'deepseek-chat';
|
|
|
+ $model = getProp($data, 'model');
|
|
|
|
|
|
// 提取文件内容
|
|
|
if ($file) {
|
|
|
@@ -2388,10 +2386,10 @@ class DeepSeekService
|
|
|
$usage = [];
|
|
|
|
|
|
if (in_array($model, ['deepseek-reasoner', 'deepseek-chat'])) {
|
|
|
- // R1模型使用DeepSeek API
|
|
|
+ // R1和V3模型使用DeepSeek API
|
|
|
$streamGenerator = $this->deepSeekStreamResponse($post_data);
|
|
|
} else {
|
|
|
- // V3模型使用火山引擎API
|
|
|
+ // 其他模型使用火山引擎API
|
|
|
$streamGenerator = $this->volcEngineChatCompletion($post_data);
|
|
|
}
|
|
|
|
|
|
@@ -2726,8 +2724,7 @@ class DeepSeekService
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- $model = getProp($data, 'model', 'v3');
|
|
|
- $model = $model == 'r1' ? 'deepseek-reasoner' : 'deepseek-chat';
|
|
|
+ $model = getProp($data, 'model');
|
|
|
|
|
|
$post_data = [
|
|
|
'model' => $model,
|
|
|
@@ -2746,10 +2743,10 @@ class DeepSeekService
|
|
|
$usage = [];
|
|
|
|
|
|
if (in_array($model, ['deepseek-reasoner', 'deepseek-chat'])) {
|
|
|
- // R1模型使用DeepSeek API
|
|
|
+ // R1和V3模型使用DeepSeek API
|
|
|
$streamGenerator = $this->deepSeekStreamResponse($post_data);
|
|
|
} else {
|
|
|
- // V3模型使用火山引擎API
|
|
|
+ // 其他模型使用火山引擎API
|
|
|
$streamGenerator = $this->volcEngineChatCompletion($post_data);
|
|
|
}
|
|
|
|
|
|
@@ -3270,9 +3267,7 @@ class DeepSeekService
|
|
|
$prompt = getProp($data, 'prompt');
|
|
|
$ref_img = getProp($data, 'ref_img');
|
|
|
$question = "请修改已有的内容{$segment_content}\n修改要求如下:\n{$prompt}";
|
|
|
-
|
|
|
- $model = getProp($data, 'model', 'v3');
|
|
|
- $model = $model == 'r1' ? 'deepseek-reasoner' : 'deepseek-chat';
|
|
|
+ $model = getProp($data, 'model');
|
|
|
|
|
|
$messages[] =
|
|
|
[
|
|
|
@@ -3291,8 +3286,13 @@ class DeepSeekService
|
|
|
'stream' => false // 是否启用流式输出
|
|
|
];
|
|
|
|
|
|
- // 调用流式输出的deepseek
|
|
|
- $chatResult = $this->chatOnly($post_data);
|
|
|
+ if (in_array($model, ['deepseek-reasoner', 'deepseek-chat'])) {
|
|
|
+ // R1和V3模型使用DeepSeek API
|
|
|
+ $chatResult = $this->chatOnly($post_data);
|
|
|
+ } else {
|
|
|
+ // 其他模型使用火山引擎API
|
|
|
+ $chatResult = $this->volcEngineChatCompletion($post_data);
|
|
|
+ }
|
|
|
if (is_array($chatResult)) {
|
|
|
extract($chatResult);
|
|
|
}else {
|
|
|
@@ -3870,7 +3870,17 @@ class DeepSeekService
|
|
|
$responseData = json_decode($response->getBody(), true);
|
|
|
dLog('deepseek')->info('火山引擎对话API响应: ', $responseData);
|
|
|
|
|
|
- return $responseData;
|
|
|
+ $usage = isset($responseData['usage']) ? $responseData['usage'] : [];
|
|
|
+ if (isset($responseData['choices']) && count($responseData['choices']) > 0) {
|
|
|
+ $fullContent = isset($responseData['choices'][0]['message']['content']) ? $responseData['choices'][0]['message']['content'] : '';
|
|
|
+ $fullReasoningContent = isset($responseData['choices'][0]['message']['reasoning_content']) ? $responseData['choices'][0]['message']['reasoning_content'] : '';
|
|
|
+ }
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'fullContent' => $fullContent,
|
|
|
+ 'fullReasoningContent' => $fullReasoningContent,
|
|
|
+ 'usage' => $usage
|
|
|
+ ];
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
dLog('deepseek')->error('火山引擎对话API请求异常: ' . $e->getMessage());
|