forked from lcpu-club/overleaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllm.controller.js
More file actions
53 lines (48 loc) · 1.65 KB
/
llm.controller.js
File metadata and controls
53 lines (48 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { LLMService } from "../services/llm.service.js";
import {getUserIdentifier} from '../utils/common.js';
export class LLMController {
constructor() {
this.llmService = new LLMService();
}
async chat(req, res) {
try {
const sid = req.cookies['overleaf.sid'];
const userIdentifier = await getUserIdentifier(sid);
// console.log('llmcontroller:',userIdentifier)
const { ask, selection, filelist, outline, mode } = req.body;
//console.log('llmcontroller body:',ask, selection, filelist, outline, mode)
const content = await this.llmService.chat(
userIdentifier, ask, selection, filelist, outline, mode
);
res.status(200).json({
success: true,
data: content
});
} catch (error) {
res.status(400).json({ success: false, data:error.message });
}
}
/**
* completion
*/
async completion(req, res) {
try {
const sid = req.cookies['overleaf.sid'];
const userIdentifier = await getUserIdentifier(sid);
console.log('userIdentifier:', userIdentifier);
const { cursorOffset, leftContext, rightContext, language, maxLength, fileList, outline } = req.body;
const content = await this.llmService.completion(
userIdentifier, cursorOffset, leftContext, rightContext, language, maxLength, fileList, outline
);
//const content = "helo world";
console.log('completion content:', content);
res.status(200).json({
success: true,
data: content
});
} catch (err) {
console.error('completion error:', err);
res.status(400).json({ success: false, data:err.message });
}
}
}