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: frontend #1509

Merged
merged 38 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
398244e
re-enable agent mode btn
ngafar Feb 5, 2025
a5b2892
mito-ai: Add support for OpenAI response format parsing
ngafar Feb 5, 2025
1961bb9
Add handling for agent mode AI responses
ngafar Feb 5, 2025
6b8f2e1
Adding dependencies to chat history
ngafar Feb 5, 2025
f56d58d
Added agent as possible type in chat history
ngafar Feb 5, 2025
1800583
Added message-agent styles
ngafar Feb 5, 2025
fd40189
Add execute agent plan functionality to ChatTaskpane
ngafar Feb 5, 2025
a503725
Turned agent toggle into dropdown
ngafar Feb 6, 2025
5d0f946
Added better dark mode support
ngafar Feb 6, 2025
7f05dde
Clearning history on toggle
ngafar Feb 6, 2025
43abe21
Fixed bugs where edits not saved in agent mode
ngafar Feb 6, 2025
a2a1274
Commented out file upload
ngafar Feb 6, 2025
09d6cab
Add user guidance message for agent response plan
ngafar Feb 7, 2025
14dc6a9
Renamed type IDisplayOptimizedChatHistory to be more inline with backend
ngafar Feb 7, 2025
7c071df
comments
ngafar Feb 7, 2025
29b4eef
Not clearning chat (was not working)
ngafar Feb 7, 2025
3165879
comment
ngafar Feb 7, 2025
9941299
Update agent plan button visibility condition
ngafar Feb 7, 2025
a0bc9f3
Updated input placeholder
ngafar Feb 7, 2025
46564c7
Updated icon viewBox
ngafar Feb 7, 2025
dbd6b2a
Updated icon viewBox
ngafar Feb 7, 2025
7f35983
Removed excess svg attr
ngafar Feb 7, 2025
7619055
Updated robot icon
ngafar Feb 7, 2025
dfdb831
Add step numbering to agent response actions
ngafar Feb 7, 2025
b71b7b8
Moved header styles to css
ngafar Feb 7, 2025
28a6788
Removed align items
ngafar Feb 7, 2025
0b47b1e
Add width and display style to dropdown item icon
ngafar Feb 7, 2025
7bcb742
Refactor message update handling to use optimized chat history type
ngafar Feb 7, 2025
7c7b9aa
Remove icon color props and use currentColor for icons
ngafar Feb 10, 2025
67d419a
Updated css selector for agent text
ngafar Feb 10, 2025
0c1fb28
Add support for editing agent messages
ngafar Feb 10, 2025
1ab7d57
Add disabled state support to dropdown menu items
ngafar Feb 10, 2025
af57227
Updated class names for clarity
ngafar Feb 10, 2025
291fa0f
Update class names in tests
ngafar Feb 10, 2025
5c9e78d
Merge branch 'dev' into feat/agent-mode-frontend
ngafar Feb 10, 2025
fde1fb8
formatting
ngafar Feb 10, 2025
52cdb61
Handle agent mode message parsing in chat history restoration
ngafar Feb 10, 2025
ee8b079
Fixed class selector for test
ngafar Feb 10, 2025
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
12 changes: 9 additions & 3 deletions mito-ai/mito_ai/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,15 @@ async def request_completions(
# Validate that the model is supported. If not fall back to gpt-4o-mini
if model not in self.models:
model = "gpt-4o-mini"

completion_function_params = get_open_ai_completion_function_params(model, request.messages, False, response_format)
completion = self._openAI_sync_client.chat.completions.create(**completion_function_params)

if response_format:
completion_function_params = get_open_ai_completion_function_params(
model, request.messages, False, response_format
)
completion = self._openAI_sync_client.beta.chat.completions.parse(**completion_function_params)
else:
completion_function_params = get_open_ai_completion_function_params(model, request.messages, False)
completion = self._openAI_sync_client.chat.completions.create(**completion_function_params)

if prompt_type == "agent:planning":
pass # TODO: Add logging for agents
Expand Down
5 changes: 5 additions & 0 deletions mito-ai/mito_ai/utils/open_ai_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ def get_open_ai_completion_function_params(
if model == "gpt-4o-mini":
completion_function_params["temperature"] = 0.0

# Remove "stream" key if response_format is set.
# beta.chat.completions.parse will error if we try to pass it as a param.
if response_format:
completion_function_params.pop("stream", None)

return completion_function_params
22 changes: 17 additions & 5 deletions mito-ai/src/Extensions/AiChat/ChatHistoryManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type PromptType = 'chat' | 'smartDebug' | 'codeExplain' | 'agent:planning
// we add a message to the chat ui that tells them to set an API key.
export interface IDisplayOptimizedChatHistory {
message: OpenAI.Chat.ChatCompletionMessageParam
type: 'openai message' | 'connection error',
type: 'openai message' | 'openai message:agent:planning' | 'connection error',
mitoAIConnectionErrorType?: string | null,
codeCellID: string | undefined
}
Expand Down Expand Up @@ -108,7 +108,7 @@ export class ChatHistoryManager {
}
}

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

Expand All @@ -121,11 +121,14 @@ export class ChatHistoryManager {

this.displayOptimizedChatHistory[index] = {
message: getDisplayedOptimizedUserMessage(newContent, activeCellCode),
type: 'openai message',
type: isAgentMessage ? 'openai message:agent:planning' : 'openai message',
codeCellID: activeCellID
}

this.displayOptimizedChatHistory = this.displayOptimizedChatHistory.slice(0, index + 1);
// Only slice the history if it's not an agent message
if (!isAgentMessage) {
this.displayOptimizedChatHistory = this.displayOptimizedChatHistory.slice(0, index + 1);
}

return {
promptType: 'chat',
Expand Down Expand Up @@ -216,12 +219,21 @@ export class ChatHistoryManager {
content: messageContent
}

let type: IDisplayOptimizedChatHistory['type'];
if (mitoAIConnectionError) {
type = 'connection error';
} else if (promptType === 'agent:planning') {
type = 'openai message:agent:planning';
} else {
type = 'openai message';
}

const activeCellID = getActiveCellID(this.notebookTracker)

this.displayOptimizedChatHistory.push(
{
message: aiMessage,
type: mitoAIConnectionError ? 'connection error' : 'openai message',
type: type,
mitoAIConnectionErrorType: mitoAIConnectionErrorType,
codeCellID: activeCellID
}
Expand Down
14 changes: 10 additions & 4 deletions mito-ai/src/Extensions/AiChat/ChatMessage/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import PlayButtonIcon from '../../../icons/PlayButtonIcon';
import CopyIcon from '../../../icons/CopyIcon';
import copyToClipboard from '../../../utils/copyToClipboard';
import TextButton from '../../../components/TextButton';
import { IDisplayOptimizedChatHistory } from '../ChatHistoryManager';

interface IChatMessageProps {
message: OpenAI.Chat.ChatCompletionMessageParam
messageType: IDisplayOptimizedChatHistory['type']
codeCellID: string | undefined
messageIndex: number
mitoAIConnectionError: boolean
Expand All @@ -33,13 +35,14 @@ interface IChatMessageProps {
previewAICode: () => void
acceptAICode: () => void
rejectAICode: () => void
onUpdateMessage: (messageIndex: number, newContent: string) => void
onUpdateMessage: (messageIndex: number, newContent: string, messageType: IDisplayOptimizedChatHistory['type']) => void
variableManager?: IVariableManager
codeReviewStatus: CodeReviewStatus
}

const ChatMessage: React.FC<IChatMessageProps> = ({
message,
messageType,
messageIndex,
mitoAIConnectionError,
mitoAIConnectionErrorType,
Expand All @@ -60,14 +63,16 @@ const ChatMessage: React.FC<IChatMessageProps> = ({
return null;
}

const editable = messageType === 'openai message:agent:planning' || message.role === 'user'

const messageContentParts = splitStringWithCodeBlocks(message);

const handleEditClick = () => {
setIsEditing(true);
};

const handleSave = (content: string) => {
onUpdateMessage(messageIndex, content);
onUpdateMessage(messageIndex, content, messageType);
setIsEditing(false);
};

Expand All @@ -94,7 +99,8 @@ const ChatMessage: React.FC<IChatMessageProps> = ({
<div className={classNames(
"message",
{ "message-user": message.role === 'user' },
{ 'message-assistant': message.role === 'assistant' },
{ 'message-assistant-chat': message.role === 'assistant' && messageType !== 'openai message:agent:planning' },
{ 'message-assistant-agent': messageType === 'openai message:agent:planning' },
)}>
{messageContentParts.map((messagePart, index) => {
if (messagePart.startsWith(PYTHON_CODE_BLOCK_START_WITHOUT_NEW_LINE)) {
Expand Down Expand Up @@ -178,7 +184,7 @@ const ChatMessage: React.FC<IChatMessageProps> = ({
/>
)}
</p>
{message.role === 'user' && (
{editable && (
<div style={{ display: 'flex', justifyContent: 'flex-end', marginTop: '4px' }}>
<button
className="message-edit-button"
Expand Down
Loading
Loading