2025-03-30 09:13:46 +08:00
|
|
|
import ws from 'ws';
|
|
|
|
import { makeClient } from "./common";
|
|
|
|
|
2025-03-30 14:14:11 +08:00
|
|
|
let selected_text = {
|
|
|
|
"filepath": "example\\\\game.py", // 文件路径
|
|
|
|
"range": {
|
|
|
|
"start": { "line": 33, "character": 0}, // 从33行0字符开始
|
|
|
|
"end" : { "line": 45, "character": 41} // 到45行41字符结束
|
|
|
|
},
|
|
|
|
"text": `def change_direction(new_direction): \n\n\tglobal direction \n\n\tif new_direction == 'left': \n\t\tif direction != 'right': \n\t\t\tdirection = new_direction \n\telif new_direction == 'right': \n\t\tif direction != 'left': \n\t\t\tdirection = new_direction \n\telif new_direction == 'up': \n\t\tif direction != 'down': \n\t\t\tdirection = new_direction \n\telif new_direction == 'down': \n\t\tif direction != 'up': \n\t\t\tdirection = new_direction` // 源码片段
|
|
|
|
}
|
|
|
|
|
|
|
|
let req = {
|
|
|
|
"cmd" : "exec_fix",
|
|
|
|
"request_id": 123, // 随机生成 (必填)
|
|
|
|
"model" : "local deepseek-r1:32b", //(必填)
|
|
|
|
"stream" : false,
|
|
|
|
"selected_text": selected_text,
|
|
|
|
}
|
|
|
|
|
2025-03-30 09:13:46 +08:00
|
|
|
async function run() {
|
2025-03-30 14:14:11 +08:00
|
|
|
let client = await makeClient()
|
|
|
|
req.stream = false
|
|
|
|
client.send(JSON.stringify(req))
|
|
|
|
}
|
|
|
|
|
|
|
|
async function run_stream() {
|
2025-03-30 09:13:46 +08:00
|
|
|
let client = await makeClient((data: ws.RawData)=>{
|
|
|
|
let d = JSON.parse(data.toString())
|
2025-03-30 14:14:11 +08:00
|
|
|
process.stdout.write(d.msg)
|
|
|
|
// console.log(data.toString())
|
2025-03-30 09:13:46 +08:00
|
|
|
})
|
2025-03-30 14:14:11 +08:00
|
|
|
req.stream = true
|
2025-03-30 09:13:46 +08:00
|
|
|
client.send(JSON.stringify(req))
|
|
|
|
}
|
|
|
|
|
2025-03-30 14:14:11 +08:00
|
|
|
|
|
|
|
run_stream()
|