返回 AiToEarn
ai.controller.ts
根目录 / project / aitoearn-electron / server / src / modules / tools / ai.controller.ts
1 /*
2 * @Author: nevin
3 * @Date: 2024-06-17 19:19:20
4 * @LastEditTime: 2024-12-23 12:45:22
5 * @LastEditors: nevin
6 * @Description: AI工具
7 */
8 import { Body, Controller, Post, Sse } from '@nestjs/common';
9 import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
10 import { ParamsValidationPipe } from 'src/validation.pipe';
11 import {
12 AiArticleHtmlDto,
13 AiArticleHtmlTestDto,
14 ReviewAi,
15 ReviewAiRecover,
16 ReviewImgAi,
17 VideoAiDesDto,
18 } from './dto/ai.dto';
19 import { AiToolsService } from './ai.service';
20 import { Public } from 'src/auth/auth.guard';
21 @ApiTags('AI工具')
22 @Public()
23 @Controller('tools/ai')
24 export class AiToolsController {
25 constructor(private readonly aiToolsService: AiToolsService) {}
26
27 @ApiOperation({
28 summary: '视频AI标题',
29 description: '视频文件只能输入一个,大小限制为 150 MB,时长限制为 40s。',
30 })
31 @ApiResponse({
32 description: '视频AI标题',
33 type: String,
34 })
35 @Post('video/title')
36 async videoAiTitle(
37 // @GetToken() token: TokenInfo,
38 @Body(new ParamsValidationPipe()) body: VideoAiDesDto,
39 ) {
40 const res = await this.aiToolsService.videoAiTitle(body.url);
41 return res;
42 }
43
44 @ApiOperation({
45 summary: '智能评论',
46 description: '对作品进行智能评论',
47 })
48 @ApiResponse({
49 description: '评论',
50 type: String,
51 })
52 @Post('review')
53 async reviewAi(
54 // @GetToken() token: TokenInfo,
55 @Body(new ParamsValidationPipe()) body: ReviewAi,
56 ) {
57 const res = await this.aiToolsService.reviewAi(
58 body.title,
59 body.desc,
60 body.max,
61 );
62 return res;
63 }
64
65 @ApiOperation({
66 summary: '智能评论',
67 description: '对作品封面图进行智能评论',
68 })
69 @ApiResponse({
70 description: '评论',
71 type: String,
72 })
73 @Post('reviewImg')
74 async reviewImgAi(
75 // @GetToken() token: TokenInfo,
76 @Body(new ParamsValidationPipe()) body: ReviewImgAi,
77 ) {
78 const res = await this.aiToolsService.reviewImgByAi(
79 body.imgUrl,
80 body.title,
81 body.desc,
82 body.max,
83 );
84 return res;
85 }
86
87 @ApiOperation({
88 summary: '智能评论回复',
89 description: '对作品进行智能评论回复',
90 })
91 @ApiResponse({
92 description: '评论',
93 type: String,
94 })
95 @Post('recover/review')
96 async reviewAiRecover(
97 // @GetToken() token: TokenInfo,
98 @Body(new ParamsValidationPipe()) body: ReviewAiRecover,
99 ) {
100 const res = await this.aiToolsService.reviewAiRecover(
101 body.content,
102 body.title,
103 body.desc,
104 body.max,
105 );
106 return res;
107 }
108
109 @ApiOperation({
110 summary: '生成AI的html图文',
111 description: '生成AI的html图文',
112 })
113 @ApiResponse({
114 description: '生成AI的html图文',
115 type: String,
116 })
117 @Post('article/html')
118 async aiArticleHtml(
119 // @GetToken() token: TokenInfo,
120 @Body(new ParamsValidationPipe()) body: AiArticleHtmlDto,
121 ) {
122 const res = await this.aiToolsService.aiArticleHtml(body.content);
123 return res;
124 }
125
126 @ApiOperation({
127 summary: '生成AI的html图文',
128 description: '生成AI的html图文',
129 })
130 @ApiResponse({
131 description: '生成AI的html图文',
132 type: String,
133 })
134 @Public()
135 @Post('article/html2')
136 async aiArticleHtml2(
137 // @GetToken() token: TokenInfo,
138 @Body(new ParamsValidationPipe()) body: AiArticleHtmlTestDto,
139 ) {
140 const res = await this.aiToolsService.aiArticleHtml2(
141 body.model,
142 body.content,
143 body.content2,
144 );
145 return res;
146 }
147
148 @Public()
149 @Post('article/html/sse')
150 @Sse('article/html/sse')
151 aiArticleHtmlSse(@Body(new ParamsValidationPipe()) body: AiArticleHtmlDto) {
152 return this.aiToolsService.aiArticleHtmlSse(body.content);
153 }
154 }
155
155 lines TYPESCRIPT