Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions src/hasura/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,6 @@ export const upsert_llm_usage_by_uuid = async (
return upsert_llm_usage_by_uuids([uuid], token_limit);
};

export const sync_rl_registered_users_to_llm_usage = async (
token_limit: number = 0,
) => {
const query: any = await client.request(
gql`
query GetRLRegisteredUserUuids {
contest_team_member(
where: { contest_team: { contest: { name: { _ilike: "RL%" } } } }
) {
user_uuid
}
}
`,
);

const uuids = (query.contest_team_member || []).map(
(member: any) => member.user_uuid,
);
const affectedRows = await upsert_llm_usage_by_uuids(uuids, token_limit);

return {
totalRegisteredUsers: Array.from(new Set(uuids)).length,
insertedUsers: affectedRows,
};
};

export const get_user_llm_usage = async (student_no: string) => {
const query: any = await client.request(
gql`
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/docker_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const docker_cron = async () => {
console.log(ContConf.contest_image_map[contest_name]);

const game_time =
(await ContHasFunc.get_game_time(queue_front.contest_id)) ?? 10;
(await ContHasFunc.get_game_time(queue_front.contest_id)) ?? 600;
const server_memory_limit =
(await ContHasFunc.get_server_memory_limit(queue_front.contest_id)) ??
2;
Expand Down
2 changes: 1 addition & 1 deletion src/routes/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ router.post("/compile-finish", async (req, res) => {

if (compile_status === "Completed") {
const key = `${cosPath}/${code_id}`;
const localFilePath = `${base_directory}/${contest_name}/code/${team_id}/${code_id}/output/capi`;
const localFilePath = `${base_directory}/${contest_name}/code/${team_id}/${code_id}/output/${code_id}`;
const found = await waitForFile(localFilePath);
if (!found) {
throw new Error(`File not found: ${localFilePath}`);
Expand Down
25 changes: 0 additions & 25 deletions src/routes/competition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as utils from "../helpers/utils";
import * as COS from "../helpers/cos";
import * as ContConf from "../configs/contest";
import * as ContHasFunc from "../hasura/contest";
import * as LlmHasFunc from "../hasura/llm";

const router = express.Router();

Expand Down Expand Up @@ -1887,28 +1886,4 @@ router.post("/rl-score/update", authenticate(), async (req, res) => {
}
});

router.post(
"/sync_RL_llm_usage",
authenticate(["root", "counselor"]),
async (req, res) => {
try {
const token_limit =
typeof req.body.token_limit === "number" ? req.body.token_limit : 0;
const result =
await LlmHasFunc.sync_rl_registered_users_to_llm_usage(token_limit);

return res.status(200).json({
message: "200 OK: RL registered users synced to llm_usage",
...result,
});
} catch (err: any) {
console.error(err);
return res.status(500).json({
error: "500 Internal Server Error",
message: err.message,
});
}
},
);

export default router;
13 changes: 8 additions & 5 deletions src/routes/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import * as LlmHasFunc from "../hasura/llm";

const router = express.Router();

const ensureRlUserLlmUsage = async (contest_id: string, user_uuid: string) => {
const ensureTHUAI9UserLlmUsage = async (
contest_id: string,
user_uuid: string,
) => {
try {
const contestName = await ContHasFunc.get_contest_name(contest_id);
if (contestName?.trim().toUpperCase().startsWith("RL")) {
if (contestName?.trim().toUpperCase().startsWith("THUAI9")) {
await LlmHasFunc.upsert_llm_usage_by_uuid(user_uuid);
}
} catch (err) {
console.error("Failed to add RL user to llm_usage:", err);
console.error("Failed to add THUAI9 user to llm_usage:", err);
}
};

Expand Down Expand Up @@ -132,7 +135,7 @@ router.post("/add_team", authenticate(["student"]), async (req, res) => {
invited_code,
contest_id,
);
await ensureRlUserLlmUsage(contest_id, team_leader_uuid);
await ensureTHUAI9UserLlmUsage(contest_id, team_leader_uuid);
res
.status(200)
.json({ team_id: team_id, message: "Team Added Successfully" });
Expand Down Expand Up @@ -160,7 +163,7 @@ router.post("/add_team_member", authenticate(), async (req, res) => {
}
const contest_id = await ContHasFunc.get_contest_id_from_team_id(team_id);
if (contest_id) {
await ensureRlUserLlmUsage(contest_id, user_uuid);
await ensureTHUAI9UserLlmUsage(contest_id, user_uuid);
}
return res.status(200).json({
message: "Team Member Added Successfully",
Expand Down
Loading