feat: 添加硅基流动相关接口
This commit is contained in:
parent
caa43298ef
commit
1d5c6d2bd5
5
.env
5
.env
|
|
@ -5,10 +5,15 @@ SERVER_USER='root'
|
|||
PASSWORD='lichao1314'
|
||||
DB_NAME='auth_db'
|
||||
|
||||
# github
|
||||
GITHUB_CLIENT_ID=Ov23lihk723FlNAwlFg6
|
||||
GITHUB_CLIENT_SECRET=b839f50bba1f006ffdd43fb73c5ae221a54e1e2e
|
||||
GITHUB_CALLBACK_URL=http://localhost:3030/auth/github/callback
|
||||
|
||||
# 飞书
|
||||
|
||||
FEISHU_APP_ID=cli_a66a897f687a5013
|
||||
FEISHU_APP_SECRET=s106GAbbCZk66OcHN69Rng5TaLK6fiH2
|
||||
|
||||
# 深寻
|
||||
SILICONFLOW_API_KEY=sk-ojmkkuyrfigcmdlijbirbjaqmuwhhfsddcqdvpvayspqrupc
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { UserModule } from './user/user.module';
|
|||
import { User } from './user/entities/user.entity';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { LarkModule } from './lark/lark.module';
|
||||
import { DeepseekModule } from './deepseek/deepseek.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
|
@ -34,6 +35,7 @@ import { LarkModule } from './lark/lark.module';
|
|||
UserModule,
|
||||
AuthModule,
|
||||
LarkModule,
|
||||
DeepseekModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { DeepseekService } from './deepseek.service';
|
||||
import { Public } from 'src/auth/decorators/public.decorator';
|
||||
|
||||
@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);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { DeepseekService } from './deepseek.service';
|
||||
import { DeepseekController } from './deepseek.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [DeepseekController],
|
||||
providers: [DeepseekService],
|
||||
})
|
||||
export class DeepseekModule {}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import axios from 'axios';
|
||||
|
||||
@Injectable()
|
||||
export class DeepseekService {
|
||||
async chatRequest(message: string) {
|
||||
const url = 'https://api.siliconflow.cn/v1/chat/completions';
|
||||
try {
|
||||
const response = await axios.post(
|
||||
url,
|
||||
{
|
||||
messages: [
|
||||
{
|
||||
content: message,
|
||||
role: 'user',
|
||||
},
|
||||
],
|
||||
model: 'deepseek-ai/DeepSeek-V3',
|
||||
stream: false,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.SILICONFLOW_API_KEY}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,6 @@ import {
|
|||
Body,
|
||||
UnauthorizedException,
|
||||
BadRequestException,
|
||||
Get,
|
||||
} from '@nestjs/common';
|
||||
import { UserService } from '../user/user.service';
|
||||
import { Public } from '../auth/decorators/public.decorator';
|
||||
|
|
|
|||
Loading…
Reference in New Issue