Skip to content
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

Agent Mode: v1 Polish #1528

Merged
merged 6 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class ChatHistoryManager {

updateMessageAtIndex(index: number, newContent: string, isAgentMessage: boolean = false): IOutgoingMessage {
const activeCellID = getActiveCellID(this.notebookTracker)
const activeCellCode = getCellCodeByID(this.notebookTracker, activeCellID)
const activeCellCode = isAgentMessage ? undefined : getCellCodeByID(this.notebookTracker, activeCellID)

const metadata: IChatMessageMetadata = {
variables: this.variableManager.variables,
Expand All @@ -123,7 +123,11 @@ export class ChatHistoryManager {
}

this.displayOptimizedChatHistory[index] = {
message: getDisplayedOptimizedUserMessage(newContent, activeCellCode),
message: getDisplayedOptimizedUserMessage(
newContent,
activeCellCode,
isAgentMessage
),
type: isAgentMessage ? 'openai message:agent:planning' : 'openai message',
codeCellID: activeCellID,
promptType: isAgentMessage ? 'agent:planning' : 'chat'
Expand Down Expand Up @@ -288,10 +292,15 @@ export class ChatHistoryManager {
}


const getDisplayedOptimizedUserMessage = (input: string, activeCellCode?: string): OpenAI.Chat.ChatCompletionMessageParam => {
const getDisplayedOptimizedUserMessage = (
ngafar marked this conversation as resolved.
Show resolved Hide resolved
input: string,
activeCellCode?: string,
isAgentPlanning: boolean = false
): OpenAI.Chat.ChatCompletionMessageParam => {
return {
role: 'user',
content: activeCellCode ? `\`\`\`python
content: (!isAgentPlanning && activeCellCode) ?
`\`\`\`python
${activeCellCode}
\`\`\`

Expand Down
4 changes: 3 additions & 1 deletion mito-ai/src/Extensions/AiChat/ChatMessage/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface ChatInputProps {
variableManager?: IVariableManager;
notebookTracker: INotebookTracker;
renderMimeRegistry: IRenderMimeRegistry;
displayActiveCellCode?: boolean;
}

export interface ExpandedVariable extends Variable {
Expand All @@ -35,6 +36,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
variableManager,
notebookTracker,
renderMimeRegistry,
displayActiveCellCode = true,
}) => {

const [input, setInput] = useState(initialContent);
Expand Down Expand Up @@ -173,7 +175,7 @@ const ChatInput: React.FC<ChatInputProps> = ({
}}
>
{/* Show the active cell preview if the text area has focus or the user has started typing */}
{activeCellCodePreview.length > 0
{displayActiveCellCode && activeCellCodePreview.length > 0
&& (isFocused || input.length > 0)
&& <div className='active-cell-preview-container'>
<div className='code-block-container'>
Expand Down
1 change: 1 addition & 0 deletions mito-ai/src/Extensions/AiChat/ChatMessage/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const ChatMessage: React.FC<IChatMessageProps> = ({
variableManager={variableManager}
notebookTracker={notebookTracker}
renderMimeRegistry={renderMimeRegistry}
displayActiveCellCode={messageType !== 'openai message:agent:planning'}
/>
);
}
Expand Down
17 changes: 9 additions & 8 deletions mito-ai/src/Extensions/AiChat/ChatTaskpane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,14 @@ const ChatTaskpane: React.FC<IChatTaskpaneProps> = ({
// Step 3: Send the message to the AI
await _sendMessageAndSaveResponse(outgoingMessage, newChatHistoryManager)

// Step 4: Scroll so that the top of the last AI message is visible
// Step 4: Scroll to the bottom of the chat smoothly
setTimeout(() => {
const aiMessages = chatMessagesRef.current?.getElementsByClassName('message message-assistant');
if (aiMessages && aiMessages.length > 0) {
const lastAiMessage = aiMessages[aiMessages.length - 1];
lastAiMessage.scrollIntoView({ behavior: 'smooth' });
const chatContainer = chatMessagesRef.current;
if (chatContainer) {
chatContainer.scrollTo({
top: chatContainer.scrollHeight,
behavior: 'smooth'
});
}
}, 100);

Expand Down Expand Up @@ -298,11 +300,10 @@ const ChatTaskpane: React.FC<IChatTaskpaneProps> = ({
// Step 0: Reject the previous Ai generated code if they did not accept it
rejectAICode()

// Step 1: Clear the chat history, and add the new error message
const newChatHistoryManager = clearChatHistory()
// Step 1: Add user message to chat history
const newChatHistoryManager = getDuplicateChatHistoryManager()
const outgoingMessage = newChatHistoryManager.addAgentMessage(message)
setChatHistoryManager(newChatHistoryManager)
console.log('outgoingMessage: ', outgoingMessage)

// Step 2: Send the message to the AI
await _sendMessageAndSaveResponse(outgoingMessage, newChatHistoryManager)
Expand Down
3 changes: 3 additions & 0 deletions tests/mitoai_ui_tests/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
const lastAgentMessage = await page.locator('.message-assistant-agent').last();
await lastAgentMessage.locator('.message-edit-button').click();

// Make sure the active cell preview is not visible
await expect(page.locator('.active-cell-preview-container')).not.toBeVisible();

// Edit the message
await page.locator('.chat-input').fill(newMessage);
await page.keyboard.press('Enter');
Expand Down Expand Up @@ -114,7 +117,7 @@

// Ensure all code snippets are in the notebook
codeSnippetsFromChatMessages.forEach(codeSnippet => {
expect(codeFromCells).toContain(codeSnippet);

Check failure on line 120 in tests/mitoai_ui_tests/agent.spec.ts

View workflow job for this annotation

GitHub Actions / test-mitoai-frontend-jupyterlab (3.10, true)

[chromium] › mitoai_ui_tests/agent.spec.ts:78:9 › Agent mode integration tests › Run agent's plan

1) [chromium] › mitoai_ui_tests/agent.spec.ts:78:9 › Agent mode integration tests › Run agent's plan Error: expect(received).toContain(expected) // indexOf Expected value: "print('hi')" Received array: [" ", " "] 118 | // Ensure all code snippets are in the notebook 119 | codeSnippetsFromChatMessages.forEach(codeSnippet => { > 120 | expect(codeFromCells).toContain(codeSnippet); | ^ 121 | }); 122 | }); 123 | at forEach (/home/runner/work/mito/mito/tests/mitoai_ui_tests/agent.spec.ts:120:35) at /home/runner/work/mito/mito/tests/mitoai_ui_tests/agent.spec.ts:119:38

Check failure on line 120 in tests/mitoai_ui_tests/agent.spec.ts

View workflow job for this annotation

GitHub Actions / test-mitoai-frontend-jupyterlab (3.12, false)

[chromium] › mitoai_ui_tests/agent.spec.ts:78:9 › Agent mode integration tests › Run agent's plan

1) [chromium] › mitoai_ui_tests/agent.spec.ts:78:9 › Agent mode integration tests › Run agent's plan Error: expect(received).toContain(expected) // indexOf Expected value: "def say_hi(): print(\"hi\") say_hi()" Received array: [" ", " ", "def say_hi(): print(\"hi\")·· say_hi()", "Start writing python or Press Ctrl + E to ask Mito AI to write code for you. "] 118 | // Ensure all code snippets are in the notebook 119 | codeSnippetsFromChatMessages.forEach(codeSnippet => { > 120 | expect(codeFromCells).toContain(codeSnippet); | ^ 121 | }); 122 | }); 123 | at forEach (/home/runner/work/mito/mito/tests/mitoai_ui_tests/agent.spec.ts:120:35) at /home/runner/work/mito/mito/tests/mitoai_ui_tests/agent.spec.ts:119:38

Check failure on line 120 in tests/mitoai_ui_tests/agent.spec.ts

View workflow job for this annotation

GitHub Actions / test-mitoai-frontend-jupyterlab (3.12, false)

[chromium] › mitoai_ui_tests/agent.spec.ts:78:9 › Agent mode integration tests › Run agent's plan

1) [chromium] › mitoai_ui_tests/agent.spec.ts:78:9 › Agent mode integration tests › Run agent's plan Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── Error: expect(received).toContain(expected) // indexOf Expected value: "print(\"hi\")" Received array: [" ", " "] 118 | // Ensure all code snippets are in the notebook 119 | codeSnippetsFromChatMessages.forEach(codeSnippet => { > 120 | expect(codeFromCells).toContain(codeSnippet); | ^ 121 | }); 122 | }); 123 | at forEach (/home/runner/work/mito/mito/tests/mitoai_ui_tests/agent.spec.ts:120:35) at /home/runner/work/mito/mito/tests/mitoai_ui_tests/agent.spec.ts:119:38
});
});

Expand Down
Loading