|
@@ -15,6 +15,23 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
|
|
|
|
|
|
class DeepSeekChatController extends Controller
|
|
|
{
|
|
|
+ public function getLlmList(): JsonResponse
|
|
|
+ {
|
|
|
+ $list = config('llm');
|
|
|
+ $llmList = [];
|
|
|
+ foreach ($list as $key => $item) {
|
|
|
+ if (!isset($item['enabled']) || !$item['enabled']) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $llmList[] = [
|
|
|
+ 'name' => $item['name'],
|
|
|
+ 'model' => $item['model'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->success(['data' => $llmList]);
|
|
|
+ }
|
|
|
+
|
|
|
// 重命名
|
|
|
public function renameSession(Request $request, $sessionId): JsonResponse
|
|
|
{
|
|
@@ -71,11 +88,17 @@ class DeepSeekChatController extends Controller
|
|
|
if (!$request->input('title')) {
|
|
|
return $this->badRequest('会话标题不能为空');
|
|
|
}
|
|
|
+ $list = config('llm');
|
|
|
+ $modelMap = array_column($list, null, 'model');
|
|
|
+ $llm = $modelMap[$request->input('model')] ?? null;
|
|
|
+ if (!$llm || !$llm['enabled']) {
|
|
|
+ return $this->badRequest('LLM服务未启用或未配置');
|
|
|
+ }
|
|
|
$session = LlmSession::create([
|
|
|
'session_id' => Str::uuid(),
|
|
|
'user_id' => $userId,
|
|
|
'title' => $request->input('title', ''),
|
|
|
- 'model' => $request->input('model', config('llm.deepseek')['model']),
|
|
|
+ 'model' => $llm['model'],
|
|
|
]);
|
|
|
|
|
|
return $this->success(['data' => $session]);
|
|
@@ -129,6 +152,10 @@ class DeepSeekChatController extends Controller
|
|
|
{
|
|
|
// 一个session进行多轮对话
|
|
|
$sessionId = $request->input("session_id");
|
|
|
+ $list = config('llm');
|
|
|
+ $modelMap = array_column($list, null, 'model');
|
|
|
+ $llm = $modelMap[$request->input('model')] ?? null;
|
|
|
+
|
|
|
// 获取该session的历史对话记录
|
|
|
$history = [];
|
|
|
if ($sessionId) {
|
|
@@ -142,7 +169,7 @@ class DeepSeekChatController extends Controller
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- return new StreamedResponse(function () use ($request, $history) {
|
|
|
+ return new StreamedResponse(function () use ($llm, $request, $history) {
|
|
|
// 1. 设置SSE头
|
|
|
header('Content-Type: text/event-stream');
|
|
|
header('Cache-Control: no-cache');
|
|
@@ -156,7 +183,7 @@ class DeepSeekChatController extends Controller
|
|
|
$message = array_merge($history ? $history->toArray() : [], [
|
|
|
['role' => 'user', 'content' => $prompt],
|
|
|
]);
|
|
|
- DeepSeekService::streamedResponseChat($message, $request->input("session_id"));
|
|
|
+ DeepSeekService::streamedResponseChat($llm, $message, $request->input("session_id"));
|
|
|
}, 200, [
|
|
|
'Content-Type' => 'text/event-stream',
|
|
|
'Access-Control-Allow-Origin' => '*'
|