From c72a3243ed5cc9895dcfe6063243e31125af9a2e Mon Sep 17 00:00:00 2001 From: Wlad Paiva Date: Fri, 20 Oct 2023 15:18:58 -0300 Subject: [PATCH] fix a bug where wasn't handling errors for speaker selection --- src/aibitat.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/aibitat.ts b/src/aibitat.ts index 13ecbaa..b7e27b2 100644 --- a/src/aibitat.ts +++ b/src/aibitat.ts @@ -486,7 +486,15 @@ export class AIbitat { if (fromNode.type === 'manager') { // select a node from the group - const nextNode = await this.selectNext(message.from) + let nextNode: string | undefined + try { + nextNode = await this.selectNext(message.from) + } catch (error: unknown) { + if (error instanceof APIError) { + return this.newError({from: message.from, to: message.to}, error) + } + throw error + } if (!nextNode) { // TODO: should it throw an error or keep the chat alive when there is no node to chat with in the group? @@ -715,10 +723,9 @@ ${this.getHistory({to}) ] // get the functions that the node can call - const functions = - (fromConfig.functions - ?.map(name => this.functions.get(name)) - .filter(a => !!a) as FunctionDefinition[]) || [] + const functions = fromConfig.functions + ?.map(name => this.functions.get(name)) + .filter(a => !!a) as FunctionDefinition[] | undefined // get the chat completion const content = await provider.create(messages, functions)