Skip to content

Commit

Permalink
god i suck at this
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan committed Dec 7, 2024
1 parent 92aca9d commit 0f4eaeb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const context = await model.createContext();
// Add this function to free sequences
async function recreateContext() {
await context.dispose();
return await model.createContext();
context = await model.createContext();
return context;
}

// Helper function to format chat messages
Expand Down Expand Up @@ -80,9 +81,9 @@ app.post('/chat', async (req, res) => {
try {
contextSequence = context.getSequence();
} catch (error) {
if (error.message === 'No sequences left') {
// Recreate context if we run out of sequences
await recreateContext();
if (error.message === 'No sequences left' || error.message.includes('disposed')) {
// Recreate context if we run out of sequences or if it's disposed
context = await recreateContext();
contextSequence = context.getSequence();
} else {
throw error;
Expand Down

0 comments on commit 0f4eaeb

Please sign in to comment.