Skip to content

Commit ddeaa3e

Browse files
committed
feat: add grade from Use ratings for flat AI room
1 parent 2d72ae9 commit ddeaa3e

File tree

17 files changed

+576
-3
lines changed

17 files changed

+576
-3
lines changed

config/defaults.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ agora:
182182
- productID:
183183
eventType:
184184
secret:
185+
ai:
186+
server: "http://106.13.114.185:8081"
185187

186188
whiteboard:
187189
app_id:

config/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ agora:
177177
- productID:
178178
eventType:
179179
secret:
180+
ai:
181+
server: "http://106.13.114.185:8081"
180182

181183
whiteboard:
182184
app_id: "test/flat-server"

src/constants/Config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ export const Agora = {
160160
enable: config.agora.messageNotification.enable,
161161
events: config.agora.messageNotification.events,
162162
},
163+
ai: {
164+
server: config.agora.ai.server,
165+
}
163166
};
164167

165168
export const JWT = {

src/model/room/RoomUser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export class RoomUserModel extends Content {
2929
})
3030
rtc_uid: string;
3131

32+
@Column({
33+
default: -1,
34+
type: "int",
35+
})
36+
grade: number;
37+
3238
@Index("room_users_is_delete_index")
3339
@Column({
3440
default: false,

src/utils/ParseConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ type Config = {
202202
secret: string;
203203
}>;
204204
};
205+
ai: {
206+
server: string;
207+
}
205208
};
206209
whiteboard: {
207210
app_id: string;

src/v1/controller/agora/Router.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ import { GenerateRTM } from "./token/RTM";
33
import { ControllerClass } from "../../../abstract/controller";
44
import { MessageCallback } from "./message/Callback";
55
import { RTMCensor } from "./rtm/censor";
6+
import { AgoraAIPing } from "./ai/ping";
7+
import { AgoraAIStart } from "./ai/start";
8+
import { AgoraAIStop } from "./ai/stop";
69

710
export const agoraRouters: Readonly<Array<ControllerClass<any, any>>> = Object.freeze([
811
GenerateRTC,
912
GenerateRTM,
1013
MessageCallback,
1114
RTMCensor,
15+
AgoraAIPing,
16+
AgoraAIStart,
17+
AgoraAIStop
1218
]);

src/v1/controller/agora/ai/const.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Agora } from "../../../../constants/Config";
2+
3+
export const AI_SERVER_URL = Agora.ai.server || "http://106.13.114.185:8081";

src/v1/controller/agora/ai/ping.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
2+
import { ax } from "../../../utils/Axios";
3+
import { AbstractController } from "../../../../abstract/controller";
4+
import { Controller } from "../../../../decorator/Controller";
5+
import { AI_SERVER_URL } from "./const";
6+
7+
@Controller<RequestType, any>({
8+
method: "post",
9+
path: "agora/ai/ping",
10+
auth: true,
11+
})
12+
export class AgoraAIPing extends AbstractController<RequestType, any> {
13+
public static readonly schema: FastifySchema<RequestType> = {
14+
body: {
15+
type: "object",
16+
required: ["request_id", "channel_name"],
17+
properties: {
18+
request_id: {
19+
type: "string",
20+
},
21+
channel_name: {
22+
type: "string",
23+
},
24+
},
25+
},
26+
};
27+
28+
public async execute(): Promise<Response<any>> {
29+
const { request_id, channel_name } = this.body;
30+
31+
const res = await ax.post<any>(`${AI_SERVER_URL}/ping`, {
32+
request_id,
33+
channel_name
34+
},
35+
{
36+
headers: {
37+
"Content-Type": "application/json"
38+
}
39+
}
40+
)
41+
return res;
42+
43+
}
44+
45+
public errorHandler(error: Error): ResponseError {
46+
return this.autoHandlerError(error);
47+
}
48+
}
49+
50+
interface RequestType {
51+
body: {
52+
request_id: string;
53+
channel_name: string;
54+
};
55+
}

src/v1/controller/agora/ai/start.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
2+
import { ax } from "../../../utils/Axios";
3+
import { AbstractController } from "../../../../abstract/controller";
4+
import { Controller } from "../../../../decorator/Controller";
5+
import { AI_SERVER_URL } from "./const";
6+
7+
@Controller<RequestType, any>({
8+
method: "post",
9+
path: "agora/ai/start",
10+
auth: true,
11+
})
12+
export class AgoraAIStart extends AbstractController<RequestType, any> {
13+
public static readonly schema: FastifySchema<RequestType> = {
14+
body: {
15+
type: "object",
16+
required: ["request_id", "channel_name", "user_uid", "language", "scene", "role"],
17+
properties: {
18+
request_id: {
19+
type: "string",
20+
},
21+
channel_name: {
22+
type: "string",
23+
},
24+
user_uid: {
25+
type: "string",
26+
},
27+
language: {
28+
type: "string",
29+
},
30+
scene: {
31+
type: "string",
32+
},
33+
role: {
34+
type: "string",
35+
},
36+
},
37+
},
38+
};
39+
40+
public async execute(): Promise<Response<any>> {
41+
const { request_id, channel_name, user_uid } = this.body;
42+
43+
const res = await ax.post<any>(`${AI_SERVER_URL}/start`, {
44+
request_id,
45+
channel_name,
46+
user_uid,
47+
},
48+
{
49+
headers: {
50+
"Content-Type": "application/json"
51+
}
52+
}
53+
)
54+
return res;
55+
}
56+
57+
public errorHandler(error: Error): ResponseError {
58+
return this.autoHandlerError(error);
59+
}
60+
}
61+
62+
interface RequestType {
63+
body: {
64+
request_id: string;
65+
channel_name: string;
66+
user_uid: string;
67+
language: string;
68+
scene: string;
69+
role: string;
70+
};
71+
}

src/v1/controller/agora/ai/stop.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { FastifySchema, Response, ResponseError } from "../../../../types/Server";
2+
import { ax } from "../../../utils/Axios";
3+
import { AbstractController } from "../../../../abstract/controller";
4+
import { Controller } from "../../../../decorator/Controller";
5+
import { AI_SERVER_URL } from "./const";
6+
7+
@Controller<RequestType, any>({
8+
method: "post",
9+
path: "agora/ai/stop",
10+
auth: true,
11+
})
12+
export class AgoraAIStop extends AbstractController<RequestType, any> {
13+
public static readonly schema: FastifySchema<RequestType> = {
14+
body: {
15+
type: "object",
16+
required: ["request_id", "channel_name"],
17+
properties: {
18+
request_id: {
19+
type: "string",
20+
},
21+
channel_name: {
22+
type: "string",
23+
},
24+
},
25+
},
26+
};
27+
28+
public async execute(): Promise<Response<any>> {
29+
const { request_id, channel_name } = this.body;
30+
31+
const res = await ax.post<any>(`${AI_SERVER_URL}/start`, {
32+
request_id,
33+
channel_name,
34+
},
35+
{
36+
headers: {
37+
"Content-Type": "application/json"
38+
}
39+
}
40+
)
41+
return res;
42+
}
43+
44+
public errorHandler(error: Error): ResponseError {
45+
return this.autoHandlerError(error);
46+
}
47+
}
48+
49+
interface RequestType {
50+
body: {
51+
request_id: string;
52+
channel_name: string;
53+
};
54+
}

0 commit comments

Comments
 (0)