Bugfix/Check for proper thread id and avoid throwing error (#2551)

check for proper thread id and avoid throwing error
pull/2561/head
Henry Heng 2024-06-02 02:41:48 +01:00 committed by GitHub
parent 8c66d2c735
commit f2a0ffe542
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 3 deletions

View File

@ -138,10 +138,14 @@ class OpenAIAssistant_Agents implements INode {
const openai = new OpenAI({ apiKey: openAIApiKey })
options.logger.info(`Clearing OpenAI Thread ${sessionId}`)
try {
if (sessionId) await openai.beta.threads.del(sessionId)
options.logger.info(`Successfully cleared OpenAI Thread ${sessionId}`)
if (sessionId && sessionId.startsWith('thread_')) {
await openai.beta.threads.del(sessionId)
options.logger.info(`Successfully cleared OpenAI Thread ${sessionId}`)
} else {
options.logger.error(`Error clearing OpenAI Thread ${sessionId}`)
}
} catch (e) {
throw new Error(e)
options.logger.error(`Error clearing OpenAI Thread ${sessionId}`)
}
}