feat: 添加deepSeek支持
This commit is contained in:
parent
1d5c6d2bd5
commit
0b2ac82f5c
1
.env
1
.env
|
|
@ -17,3 +17,4 @@ FEISHU_APP_SECRET=s106GAbbCZk66OcHN69Rng5TaLK6fiH2
|
|||
|
||||
# 深寻
|
||||
SILICONFLOW_API_KEY=sk-ojmkkuyrfigcmdlijbirbjaqmuwhhfsddcqdvpvayspqrupc
|
||||
DEEPSEEK_API_KEY=sk-e8941dc2bf1d4d099001b161db6f4317
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
},
|
||||
};
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue