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
|
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 { Body, Controller, Post } from '@nestjs/common';
|
||||||
import { DeepseekService } from './deepseek.service';
|
import { DeepseekService } from './deepseek.service';
|
||||||
import { Public } from 'src/auth/decorators/public.decorator';
|
import { Public } from 'src/auth/decorators/public.decorator';
|
||||||
|
import { PROVIDER_TYPE } from 'src/constants/providerType';
|
||||||
|
|
||||||
@Controller('deepSeek')
|
@Controller('deepSeek')
|
||||||
export class DeepseekController {
|
export class DeepseekController {
|
||||||
constructor(private readonly deepseekService: DeepseekService) {}
|
constructor(private readonly deepseekService: DeepseekService) {}
|
||||||
|
|
||||||
@Public()
|
@Public()
|
||||||
@Post('chat')
|
@Post('chat-flow')
|
||||||
async chat(@Body() body: { message: string }) {
|
async chatFlow(@Body() body: { message: string }) {
|
||||||
const response = await this.deepseekService.chatRequest(body.message);
|
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;
|
return response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,27 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import { PROVIDER_TYPE } from 'src/constants/providerType';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeepseekService {
|
export class DeepseekService {
|
||||||
async chatRequest(message: string) {
|
async chatRequest(message: string, provider = PROVIDER_TYPE.Flow.name) {
|
||||||
const url = 'https://api.siliconflow.cn/v1/chat/completions';
|
const { baseUrl, model } = PROVIDER_TYPE[provider];
|
||||||
|
const apiKey =
|
||||||
|
provider === PROVIDER_TYPE.Flow.name
|
||||||
|
? process.env.SILICONFLOW_API_KEY
|
||||||
|
: process.env.DEEPSEEK_API_KEY;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.post(
|
||||||
url,
|
baseUrl,
|
||||||
{
|
{
|
||||||
messages: [
|
messages: [{ content: message, role: 'user' }],
|
||||||
{
|
model,
|
||||||
content: message,
|
|
||||||
role: 'user',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
model: 'deepseek-ai/DeepSeek-V3',
|
|
||||||
stream: false,
|
stream: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${process.env.SILICONFLOW_API_KEY}`,
|
Authorization: `Bearer ${apiKey}`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue