feat: 添加deepSeek支持

This commit is contained in:
lichao 2025-02-10 17:50:41 +08:00
parent 1d5c6d2bd5
commit 0b2ac82f5c
4 changed files with 42 additions and 14 deletions

1
.env
View File

@ -17,3 +17,4 @@ FEISHU_APP_SECRET=s106GAbbCZk66OcHN69Rng5TaLK6fiH2
# 深寻
SILICONFLOW_API_KEY=sk-ojmkkuyrfigcmdlijbirbjaqmuwhhfsddcqdvpvayspqrupc
DEEPSEEK_API_KEY=sk-e8941dc2bf1d4d099001b161db6f4317

View File

@ -0,0 +1,12 @@
export const PROVIDER_TYPE = {
Deep: {
name: 'Deep',
baseUrl: 'https://api.deepseek.com/chat/completions',
model: 'deepseek-chat',
},
Flow: {
name: 'Flow',
baseUrl: 'https://api.siliconflow.cn/v1/chat/completions',
model: 'deepseek-ai/DeepSeek-V3',
},
};

View File

@ -1,15 +1,29 @@
import { Body, Controller, Post } from '@nestjs/common';
import { DeepseekService } from './deepseek.service';
import { Public } from 'src/auth/decorators/public.decorator';
import { PROVIDER_TYPE } from 'src/constants/providerType';
@Controller('deepSeek')
export class DeepseekController {
constructor(private readonly deepseekService: DeepseekService) {}
@Public()
@Post('chat')
async chat(@Body() body: { message: string }) {
const response = await this.deepseekService.chatRequest(body.message);
@Post('chat-flow')
async chatFlow(@Body() body: { message: string }) {
const response = await this.deepseekService.chatRequest(
body.message,
PROVIDER_TYPE.Flow.name,
);
return response;
}
@Public()
@Post('chat-deep')
async chatDeep(@Body() body: { message: string }) {
const response = await this.deepseekService.chatRequest(
body.message,
PROVIDER_TYPE.Deep.name,
);
return response;
}
}

View File

@ -1,26 +1,27 @@
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { PROVIDER_TYPE } from 'src/constants/providerType';
@Injectable()
export class DeepseekService {
async chatRequest(message: string) {
const url = 'https://api.siliconflow.cn/v1/chat/completions';
async chatRequest(message: string, provider = PROVIDER_TYPE.Flow.name) {
const { baseUrl, model } = PROVIDER_TYPE[provider];
const apiKey =
provider === PROVIDER_TYPE.Flow.name
? process.env.SILICONFLOW_API_KEY
: process.env.DEEPSEEK_API_KEY;
try {
const response = await axios.post(
url,
baseUrl,
{
messages: [
{
content: message,
role: 'user',
},
],
model: 'deepseek-ai/DeepSeek-V3',
messages: [{ content: message, role: 'user' }],
model,
stream: false,
},
{
headers: {
Authorization: `Bearer ${process.env.SILICONFLOW_API_KEY}`,
Authorization: `Bearer ${apiKey}`,
},
},
);