Created
May 28, 2026 03:11
-
-
Save wangjiezhe/aea52d7e49e02ca4b225352c4311e060 to your computer and use it in GitHub Desktop.
KISS-Translator custom api for LM Studio REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async (args, { url, body, headers, userMsg, method } = {}) => { | |
| // console.log("request hook args:", { args, url, body, headers, userMsg, method }); | |
| body = { | |
| model: args.model, | |
| input: [ | |
| { | |
| type: "text", | |
| content: args.systemPrompt, | |
| }, | |
| { | |
| type: "text", | |
| content: args.userPrompt, | |
| } | |
| ], | |
| temperature: 0.7, | |
| top_p: 0.6, | |
| top_k: 20, | |
| repeat_penalty: 1.05, | |
| max_output_tokens: 4096, | |
| stream: true, | |
| }; | |
| // console.log("request :", { args, url, body, headers, userMsg, method }); | |
| return { url, body, headers, userMsg, method }; | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async ({ res, ...args }) => { | |
| // console.log("response hook args:", { res, args }); | |
| let translation = ''; | |
| let response_id = ''; | |
| const lines = res.split('\n'); | |
| for (const line of lines) { | |
| if (line.startsWith('data: ')) { | |
| const jsonStr = line.slice(6); | |
| try { | |
| const data = JSON.parse(jsonStr); | |
| if (data.type == 'chat.end') { | |
| translation = data?.result?.output?.[0]?.content; | |
| response_id = data?.result?.response_id; | |
| break; | |
| } | |
| } catch (e) {} | |
| } | |
| } | |
| const translations = args.parseAIRes(translation); | |
| const modelMsg = { | |
| response_id: response_id, | |
| }; | |
| // console.log("response: ", {translations, modelMsg}) | |
| return { translations, modelMsg }; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment