completion context limit check

This commit is contained in:
Kolby Nottingham 2023-12-04 21:39:07 -08:00
parent 6fc33525d8
commit cac31cc171

View file

@ -27,11 +27,13 @@ export async function sendRequest(turns, systemMessage, stop_seq='***') {
messages: messages,
stop: stop_seq,
});
if (completion.choices[0].finish_reason == 'length')
throw new Error('Context length exceeded');
console.log('Received.')
res = completion.choices[0].message.content;
}
catch (err) {
if (err.code == 'context_length_exceeded' && turns.length > 1) {
if ((err.message == 'Context length exceeded' || err.code == 'context_length_exceeded') && turns.length > 1) {
console.log('Context length exceeded, trying again with shorter context.');
return await sendRequest(turns.slice(1), systemMessage, stop_seq);
} else {