ai-chatbot icon indicating copy to clipboard operation
ai-chatbot copied to clipboard

Infered types based on the tool result

Open ikuzweelisa opened this issue 1 year ago • 1 comments

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
    }))
}

ikuzweelisa avatar Sep 27 '24 19:09 ikuzweelisa

@Ikuzweshema is attempting to deploy a commit to the Uncurated Tests Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Sep 27 '24 19:09 vercel[bot]