book-by-ai icon indicating copy to clipboard operation
book-by-ai copied to clipboard

json 格式解析

Open visoar opened this issue 1 year ago • 2 comments

使用gpt-3.5-turbo-16k部分情况下会有这个报错,看起来是部分情况下模型返回没有按照 json 格式。

SyntaxError: Unexpected number in JSON at position 48
    at JSON.parse (<anonymous>)
    at canJsonParse (file:///Users/NAME/Code/Github/book-by-ai/lib/functions_cn.js:132:14)
    at extractJSON (file:///Users/NAME/Code/Github/book-by-ai/lib/functions_cn.js:117:24)
    at gen (file:///Users/NAME/Code/Github/book-by-ai/lib/functions_cn.js:70:24)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async GenBook.sections (file:///Users/NAME/Code/Github/book-by-ai/actions/book_cn.js:165:32)
    at async GenBook.main (file:///Users/NAME/Code/Github/book-by-ai/actions/book_cn.js:15:9)
file:///Users/NAME/Code/Github/book-by-ai/actions/book_cn.js:167
                if( result.json.sections )
                                ^

TypeError: Cannot read properties of null (reading 'sections')
    at GenBook.sections (file:///Users/NAME/Code/Github/book-by-ai/actions/book_cn.js:167:33)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async GenBook.main (file:///Users/NAME/Code/Github/book-by-ai/actions/book_cn.js:15:9)

Node.js v18.17.0

visoar avatar Aug 15 '23 03:08 visoar

这是3.5的智商问题,总有小概率会这样,暂时只能重试。你也可以自己改改脚本,让它自动重试。

easychen avatar Aug 15 '23 06:08 easychen

in lib/prompts.js search for JSON format then replace with valid JSON format

nullart avatar Nov 13 '23 01:11 nullart