-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into tim/basic_batch_actions_UI
- Loading branch information
Showing
36 changed files
with
1,053 additions
and
268 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
...e-js/src/components/PagePanelComponents/Home/Browse2/Browse2RootObjectVersionOutputOf.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/CallSummary.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
weave-js/src/components/PagePanelComponents/Home/Browse3/pages/CallPage/ValueView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
...rc/components/PagePanelComponents/Home/Browse3/pages/ChatView/HorizontalRuleWithLabel.tsx
This file was deleted.
Oops, something went wrong.
75 changes: 69 additions & 6 deletions
75
weave-js/src/components/PagePanelComponents/Home/Browse3/pages/ChatView/MessageList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(() => { | ||
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; | ||
}; |
Oops, something went wrong.