mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-22 06:02:07 +02:00
completion context limit check
This commit is contained in:
parent
6fc33525d8
commit
cac31cc171
1 changed files with 3 additions and 1 deletions
|
@ -27,11 +27,13 @@ export async function sendRequest(turns, systemMessage, stop_seq='***') {
|
||||||
messages: messages,
|
messages: messages,
|
||||||
stop: stop_seq,
|
stop: stop_seq,
|
||||||
});
|
});
|
||||||
|
if (completion.choices[0].finish_reason == 'length')
|
||||||
|
throw new Error('Context length exceeded');
|
||||||
console.log('Received.')
|
console.log('Received.')
|
||||||
res = completion.choices[0].message.content;
|
res = completion.choices[0].message.content;
|
||||||
}
|
}
|
||||||
catch (err) {
|
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.');
|
console.log('Context length exceeded, trying again with shorter context.');
|
||||||
return await sendRequest(turns.slice(1), systemMessage, stop_seq);
|
return await sendRequest(turns.slice(1), systemMessage, stop_seq);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue