sudomakes/backroad

LLM:Unable to refresh the conversation.

2213500360 opened this issue ยท 6 comments

LLM: Unable to refresh the conversation.
When I tried to add a button to change the "messages" value to clear the conversation, I got a display bug, and the button and dialog were displayed incorrectly (two were displayed).
button related code:
let reset = br.button({ label: 'Reset', id: 'reset' }); if (reset) { chatHistory.messages = []; br.setValue('messages', [ { by: 'ai', content: 'Hi, how can I help you today? ' }, ]); }

image

Hi, can you send your full code if possible

I think I see the issue. For now the below code works (it just adds a couple lines more)

import { run } from '@backroad/backroad';

const initialMessages = [
  { by: 'ai', content: 'Hi, how can I help you today? ๐Ÿ˜€' },
];
run((brBase) => {
  const br = brBase.base({});
  const messages = br.getOrDefault('messages', initialMessages);
  br.write({ body: `# Backroad LLM Example\n---` });
  const button = br.button({ label: 'Reset' });
  messages.forEach((message) => {
    br
      .chatMessage({ name: message.by })
      .write({ body: message.content });
  });
  const input = br.chatInput({ id: 'input' });
  if (input) {
    br.setValue('messages', [
      ...messages,
      { by: 'human', content: input },
      { by: 'ai', content: getGPTResponse(input) },
    ]);
  }

  if (button) {
    br.setValue('messages', initialMessages);
  }
});

const getGPTResponse = (message: string) => {
  if (message.includes('1+1')) {
    return 'Ah, the answer to that is 2!! ๐Ÿ˜Ž';
  } else {
    return `I don't know...
    ![i-dont-know](https://t3.ftcdn.net/jpg/05/66/80/74/360_F_566807496_uKCQoOWWdXbFWKluJXo2ilg7B61J0qIe.jpg)`;
  }
};

the issue seems to be some bug in the code re-rendering every node except the root one (which is why the issue seems to go away when I add another base node and start using that for the app). When you use the root node directly, the re-rendering logic seems to have something off. Will investigate further.

The issue was resolved after I added the re-rendering. I had tried to search for re-rendering related API in the documentation before, but couldn't find any. Thank you for your response.

by re-rendering, I guess you are referring to the above snippet I shared. This fix works, but isn't ideal. I will try working towards fixing this in the base node itself.

should be fixed in @backroad/backroad@1.3.2 , lemme know if it doesn't work