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

fix: clean up two explicit errors handled elsewhere #138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 1 addition & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,13 @@ export const App = () => {
messageStore,
)
.catch((error) => {
let errorMessage =
const errorMessage =
typeof error === 'object' &&
error !== null &&
'message' in error
? (error as { message: string }).message
: 'An error occurred - please try again';

// Errors can be thrown when recursive call is cancelled
if (errorMessage.includes('JSON')) {
errorMessage = 'You clicked cancel - please try again';
}

Comment on lines -161 to -165
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer an error after introducing JSON streaming parser.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup

setErrorText(errorMessage);
})
.finally(() => {
Expand Down
12 changes: 2 additions & 10 deletions src/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,7 @@ export const ChatView = ({
);

const handleButtonClick = useCallback(() => {
const lastMessage = messages[messages.length - 1];
const lastMessageRole = lastMessage.role;

// if a user has initiated a wallet-based tool call, but not confirmed or denied it
// we don't want to add more messages to the history
const userRequestInProgress =
messages.length > 1 && lastMessageRole === 'user';

if (isRequesting || userRequestInProgress) {
Comment on lines -65 to -73
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now early return from the streaming store if we get into a bad state and don't call the .write() method which triggered the error when a user entered more messages after starting a tx, but never completing that tool call in metamask.

if (!streamParser) {
return;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason for the write error in the streaming store is because:

  1. model generates a single tool call which gets added to the toolCallStream store the index for the tool call is 0
  2. the tool call stream store parses the streaming json for the tool call and removes the underlying parser once the tool call stream is finished from the model.
  3. another tool call is made but it's scoped to a different request, however the problem is that the index of the new tool call corresponds with the old tool call which had it's parser removed, so when the new tool call json args are being streamed this is when the errors gets thrown. The problem here is that the old tool call from the previous request is not removed/resolved yet, and there's no way for us to know that this reffers to a different request all together since all we get is an index for each tool call request from the model. and those indices are scoped per request. so the problem here is that we shouldn't allow users to submit more requests until the previous tool call is resolved/removed in some way.

if (isRequesting) {
onCancel();
return;
}
Expand All @@ -90,7 +82,7 @@ export const ChatView = ({

onSubmit(output);
setInputValue('');
}, [messages, isRequesting, inputValue, onSubmit, onCancel]);
}, [isRequesting, inputValue, onSubmit, onCancel]);

const buttonRef = useRef<HTMLButtonElement>(null);
const handleKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
Expand Down
Loading