-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style(weave): chatview styling #2977
Changes from all commits
32d6477
3d865d8
1672f8b
031dadb
1fecc18
fcf5e4f
d0df473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,81 @@ | ||
import React from 'react'; | ||
import React, {useEffect, useRef} from 'react'; | ||
|
||
import {MessagePanel} from './MessagePanel'; | ||
import {Messages} from './types'; | ||
import {Message, Messages, ToolCall} from './types'; | ||
|
||
type MessageListProps = { | ||
messages: Messages; | ||
scrollLastMessage?: boolean; | ||
}; | ||
|
||
export const MessageList = ({messages}: MessageListProps) => { | ||
export const MessageList = ({ | ||
messages, | ||
scrollLastMessage = false, | ||
}: MessageListProps) => { | ||
const lastMessageRef = useRef<HTMLDivElement>(null); | ||
const processedMessages = processToolCallMessages(messages); | ||
|
||
useEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering why we are doing a scrollIntoView in both ChatView and MessageList There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. messagelist scrolls to the last message when theres no choice, or when we add a message in the playground chat view, chat view scrolls the last choice |
||
if (lastMessageRef.current && scrollLastMessage) { | ||
lastMessageRef.current.scrollIntoView(); | ||
} | ||
}, [messages.length, scrollLastMessage]); | ||
|
||
return ( | ||
<div className="flex flex-col gap-36"> | ||
{messages.map((m, i) => ( | ||
<MessagePanel key={i} message={m} /> | ||
<div className="flex flex-col"> | ||
{processedMessages.map((m, i) => ( | ||
<div | ||
ref={i === processedMessages.length - 1 ? lastMessageRef : null} | ||
key={i}> | ||
<MessagePanel index={m.original_index ?? i} message={m} /> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
// Associates tool calls with their responses | ||
const processToolCallMessages = (messages: Messages): Messages => { | ||
const processedMessages: Message[] = []; | ||
for (let i = 0; i < messages.length; i++) { | ||
const message = messages[i]; | ||
|
||
// If there are no tool calls, just add the message to the processed messages | ||
// and continue to the next iteration. | ||
if (!message.tool_calls) { | ||
processedMessages.push({ | ||
...message, | ||
// Store the original index of the message in the message object | ||
// so that we can use it to sort the messages later. | ||
original_index: i, | ||
}); | ||
continue; | ||
} | ||
|
||
// Otherwise, we need to associate the tool calls with their responses. | ||
// Get all the next messages where role = tool, these are all the responses | ||
const toolMessages: Message[] = []; | ||
while (i + 1 < messages.length && messages[i + 1].role === 'tool') { | ||
toolMessages.push({ | ||
...messages[i + 1], | ||
original_index: (messages[i + 1] as any).original_index ?? i + 1, | ||
}); | ||
i++; | ||
} | ||
|
||
const toolCallsWithResponses: ToolCall[] = message.tool_calls.map( | ||
toolCall => ({ | ||
...toolCall, | ||
response: toolMessages.find( | ||
toolMessage => toolMessage.tool_call_id === toolCall.id | ||
), | ||
}) | ||
); | ||
|
||
processedMessages.push({ | ||
...message, | ||
tool_calls: toolCallsWithResponses, | ||
}); | ||
} | ||
return processedMessages; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class was the only place using
HorizontalRuleWithLabel
; I'd delete it rather than leaving it unused in the codebase.