Skip to content

Commit

Permalink
fix a bug where wasn't handling errors for speaker selection
Browse files Browse the repository at this point in the history
  • Loading branch information
wladpaiva committed Oct 20, 2023
1 parent 9c16980 commit c72a324
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/aibitat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c72a324

Please sign in to comment.