catch parse fail
This commit is contained in:
parent
b22b2b4366
commit
cf387bd6e6
|
|
@ -46,8 +46,15 @@ User Description: ${description.slice(0,100)}` }
|
||||||
})
|
})
|
||||||
})).json()
|
})).json()
|
||||||
|
|
||||||
const parsedResponse: {score: number, reasoning: string} = JSON.parse(llmResponse.choices[0].message.content.replace(/```json|```/g, '').trim())
|
let parsedResponse: {score: number, reasoning: string}
|
||||||
|
= { score: 0, reasoning: 'failed to parse' }
|
||||||
|
|
||||||
|
try {
|
||||||
|
parsedResponse = JSON.parse(llmResponse.choices[0].message.content.replace(/```json|```/g, '').trim())
|
||||||
console.log(`parsed ${id} - ${JSON.stringify(parsedResponse)}`)
|
console.log(`parsed ${id} - ${JSON.stringify(parsedResponse)}`)
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`failed to parse ${id} - ${llmResponse.choices[0].message.content}`)
|
||||||
|
}
|
||||||
|
|
||||||
return parsedResponse
|
return parsedResponse
|
||||||
}
|
}
|
||||||
|
|
@ -56,8 +63,9 @@ async function parseSlop(id: string, title: string, description: string): Promis
|
||||||
const cachedSlop = await redis.get(`slop:${id}`)
|
const cachedSlop = await redis.get(`slop:${id}`)
|
||||||
if (cachedSlop) return parseInt(cachedSlop)
|
if (cachedSlop) return parseInt(cachedSlop)
|
||||||
|
|
||||||
const { score } = await analyseSlop(id , title, description)
|
const { score, reasoning } = await analyseSlop(id , title, description)
|
||||||
await redis.set(`slop:${id}`, score, 'EX', 60 * 60 * 24 * 7)
|
if (reasoning != 'failed to parse') await redis.set(`slop:${id}`, score, 'EX', 60 * 60 * 24 * 7)
|
||||||
|
|
||||||
return score
|
return score
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue