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 Amazon Nova support (use StrOutputParser) #1202

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

dlqqq
Copy link
Member

@dlqqq dlqqq commented Jan 15, 2025

Description

  • Closes Fix Amazon Nova support #1198.
  • Appends StrOutputParser to the runnable defined in DefaultChatHandler.
    • The original issue was caused by the runnable yielding AIMessageChunk objects with a unique structure that we did not expect. This only happens when Amazon Nova is used through ChatBedrock, as far I'm aware.
    • By adding StrOutputParser to the runnable, the runnable now yields primitive strings when streamed, which we already handle in BaseChatHandler.stream_reply().

Demo

Screen.Recording.2025-01-15.at.3.20.46.PM.mov

Open questions

(mainly for @3coins)

  1. Do you know why this change fixes the original issue?
  2. Are you aware of any risk this change introduces?
    • I've verified that these changes do not break support for OpenAI & Anthropic models.

@dlqqq dlqqq added the bug Something isn't working label Jan 15, 2025
@dlqqq dlqqq added this to the v3.0.0a1 milestone Jan 15, 2025
@dlqqq dlqqq requested a review from 3coins January 15, 2025 23:24
@dlqqq dlqqq force-pushed the fix-amazon-nova-chat branch from e5a808f to ad70210 Compare January 15, 2025 23:27
@dlqqq
Copy link
Member Author

dlqqq commented Jan 15, 2025

Interestingly, all of the other slash commands work with Amazon Nova, even though this PR only changes DefaultChatHandler. I believe this is because the original issue in #1198 only occurs when streaming, and none of the slash commands support streaming yet.

The only exception is /fix in Jupyter AI v2. I've already made sure to update /fix in the 2.x port (#1203).

@dlqqq dlqqq changed the title Fix Amazon Nova support Fix Amazon Nova support (use StrOutputParser) Jan 15, 2025
Copy link
Collaborator

@srdas srdas left a comment

Choose a reason for hiding this comment

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

The code changes look good. The use of StrOutputParser() works great!

Tested for use in magics:
image
Note the interesting new layout of the response from StrOutputParser().

Tested for use in Chat:
image

image

Retested with Nova-Micro:
image

image

Restested with Nova-Lite:
image

image

@dlqqq dlqqq force-pushed the fix-amazon-nova-chat branch from ad70210 to ed3bcf8 Compare January 16, 2025 19:10
Copy link
Collaborator

@3coins 3coins left a comment

Choose a reason for hiding this comment

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

@dlqqq
LGTM!
The original code expecting chunk.content to be a string might not cover all Message responses, which is causing this error.
Using StrOutputParser should handle these different content types and any future changes that might happen in LangChain.

@dlqqq
Copy link
Member Author

dlqqq commented Jan 16, 2025

Thanks for the reviews folks! Merging.

@dlqqq dlqqq merged commit 7c1c8c0 into jupyterlab:main Jan 16, 2025
9 checks passed
@dlqqq dlqqq deleted the fix-amazon-nova-chat branch January 16, 2025 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Amazon Nova support
3 participants