Repository: LAION-AI/Open-Assistant
File: website/src/components/Chat/ChatConversation.tsx (TypeScript)

Code before:
  );

  const send = useCallback(async () => {
    const content = inputRef.current?.value.trim();
    if (!content || !chatId) {
      return;
    }
    setIsSending.on();

    // find last VALID assistant message
    const parent_id =
      currentThread
        .slice()
        .reverse()
        .find((m) => m.role === "assistant" && m.state === "complete")?.id ?? null;
    const prompter_arg: InferencePostPrompterMessageParams = {
      chat_id: chatId,
      content,
      parent_id,
    };

    const prompter_message: InferenceMessage = await post(API_ROUTES.CREATE_PROMPTER_MESSAGE, { arg: prompter_arg });

    setMessages((messages) => [...messages, prompter_message]);

    initiate_assistant_message(prompter_message.id);
  }, [chatId, currentThread, setIsSending, initiate_assistant_message]);

  const sendVote = useMessageVote();

  const handleOnRetry = useCallback(
    (messageId: string) => {
      setIsSending.on();
      initiate_assistant_message(messageId);
    },
    [initiate_assistant_message, setIsSending]
  );

  const handleOnVote: ChatMessageEntryProps["onVote"] = useCallback(
    async ({ chatId, messageId, newScore, oldScore }) => {
      // immediately set score
      setMessages((messages) =>
        messages.map((message) => {
          return message.id !== messageId ? message : { ...message, score: newScore };
        })
      );
      try {
        await sendVote({ chat_id: chatId, message_id: messageId, score: newScore });
      } catch {
        // TODO maybe we should trigger a toast or something
        // revert on any error

Review comment (suggestion):
```suggestion
   await initiate_assistant_message(prompter_message.id);
```

Code after:
  );

  const send = useCallback(async () => {
    const content = inputRef.current?.value.trim();
    if (!content || !chatId) {
      return;
    }
    setIsSending.on();

    // find last VALID assistant message
    const parent_id =
      currentThread
        .slice()
        .reverse()
        .find((m) => m.role === "assistant" && m.state === "complete")?.id ?? null;
    const prompter_arg: InferencePostPrompterMessageParams = {
      chat_id: chatId,
      content,
      parent_id,
    };

    const prompter_message: InferenceMessage = await post(API_ROUTES.CREATE_PROMPTER_MESSAGE, { arg: prompter_arg });

    setMessages((messages) => [...messages, prompter_message]);

    await initiate_assistant_message(prompter_message.id);
  }, [chatId, currentThread, setIsSending, initiate_assistant_message]);

  const sendVote = useMessageVote();

  const handleOnRetry = useCallback(
    (messageId: string) => {
      setIsSending.on();
      initiate_assistant_message(messageId);
    },
    [initiate_assistant_message, setIsSending]
  );

  const handleOnVote: ChatMessageEntryProps["onVote"] = useCallback(
    async ({ chatId, messageId, newScore, oldScore }) => {
      // immediately set score
      setMessages((messages) =>
        messages.map((message) => {
          return message.id !== messageId ? message : { ...message, score: newScore };
        })
      );
      try {
        await sendVote({ chat_id: chatId, message_id: messageId, score: newScore });
      } catch {
        // TODO maybe we should trigger a toast or something
        // revert on any error