FSSRepo / llama.cpp

Port of Facebook's LLaMA model in C/C++ with HTTP server
MIT License
4 stars 0 forks source link

SyntaxError: Unexpected token 'D', "[DONE]" is not valid JSON #2

Closed x4080 closed 1 year ago

x4080 commented 1 year ago

Hi again,

I tried to run the node and it works. But at the end there's error, here's the complete result :

node .
 Linux is a popular open-source operating system that is used by many computer systems and devices. It was developed by a community of developers who collaborate on its development through the Internet.
undefined:1
[DONE]
 ^

SyntaxError: Unexpected token 'D', "[DONE]" is not valid JSON
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (/Users/edwardnone/llama-client/index.js:26:28)
    at IncomingMessage.emit (node:events:511:28)
    at addChunk (node:internal/streams/readable:332:12)
    at readableAddChunk (node:internal/streams/readable:305:9)
    at Readable.push (node:internal/streams/readable:242:10)
    at HTTPParser.parserOnBody (node:_http_common:131:24)
    at Socket.socketOnData (node:_http_client:535:22)
    at Socket.emit (node:events:511:28)
    at addChunk (node:internal/streams/readable:332:12)

I was using WizardLM-7B-uncensored.ggml.q4_2.bin

did I do something wrong ?

Thanks

x4080 commented 1 year ago

I resolve it using try catch

if (result.data.can_inference) {
        result = await axios.get("http://127.0.0.1:8080/completion?stream=true", { responseType: 'stream' });
        result.data.on('data', (data) => {
            try {
                let dat = JSON.parse(data.toString());
                process.stdout.write(dat.content);
            }
            catch (err) {
                console.log(data.toString());
            }
            // token by token completion
        });
    }
FSSRepo commented 1 year ago

I haven't tried with other model, just with vicuna, it's a limitation of this implementation

FSSRepo commented 1 year ago

I recommend you use this code:

result.data.on('data', (data) => {
            // token by token completion
            if(data.toString() != "[DONE]"){
                let dat = JSON.parse(data.toString());
                process.stdout.write(dat.content);
            } else {
                console.log("Completed");
            }
        });
}
x4080 commented 1 year ago

Thanks