ai-chatbot
ai-chatbot copied to clipboard
Infered types based on the tool result
I refactored the code to infer the types based on the tool's result. to complete this todo ( TODO: Infer types based on the tool result )
export const getUIStateFromAIState = (aiState: Chat) => {
return aiState.messages
.filter(message => message.role !== 'system')
.map((message, index) => ({
id: `${aiState.chatId}-${index}`,
display:
message.role === 'tool' ? (
message.content.map(tool => {
return tool.toolName === 'listStocks' ? (
<BotCard>
<Stocks {...tool.result as ListStockProps} />
</BotCard>
) : tool.toolName === 'showStockPrice' ? (
<BotCard>
<Stock {...tool.result as ShowStockPriceProps} />
</BotCard>
) : tool.toolName === 'showStockPurchase' ? (
<BotCard>
<Purchase {...tool.result as PurchaseProps} />
</BotCard>
) : tool.toolName === 'getEvents' ? (
<BotCard>
<Events events={tool.result as GetEventProps["events"]} />
</BotCard>
) : null
})
) : message.role === 'user' ? (
<UserMessage>{message.content as string}</UserMessage>
) : message.role === 'assistant' &&
typeof message.content === 'string' ? (
<BotMessage content={message.content} />
) : null
}))
}
@Ikuzweshema is attempting to deploy a commit to the Uncurated Tests Team on Vercel.
A member of the Team first needs to authorize it.