import ws from 'ws';
import { makeClient } from "./common";

let req = {
    "cmd"          : "exec_chat",
    "request_id"   : 123,                       // 随机生成 （必填）
    "language"     : "en",                      // 语言, en-英文, cn-中文，默认为 en  （可选）
    "msg"          : "What would be a good company name a company that makes colorful socks?",
    "model"        : "local qwen2.5-coder:7b",   //（必填）
    "stream"       : false                       // stream方式返回，目前未支持 （可选）
}

async function run() {
    let client = await makeClient()
    req.stream = false
    client.send(JSON.stringify(req))
}


async function run_stream() {
    let client = await makeClient((data: ws.RawData)=>{
        let d = JSON.parse(data.toString())
        process.stdout.write(d.msg)
        // console.log(data.toString())
    })

    req.stream = true
    client.send(JSON.stringify(req))
}

run_stream()
