-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Ambiguous Type Check in @langchain/aws #6101
Comments
Hey @wailinkyaww! I'm here to help you out with any bugs, questions, or contributions you have in mind. Let's tackle this together while we wait for a human maintainer. To address the issue with the ambiguous type check in the
export function handleConverseStreamContentBlockDelta(
contentBlockDelta: ContentBlockDeltaEvent
): ChatGenerationChunk {
if (!contentBlockDelta.delta) {
throw new Error("No delta found in content block.");
}
if (typeof contentBlockDelta.delta.text === 'string' && contentBlockDelta.delta.text.trim() !== "") {
return new ChatGenerationChunk({
text: contentBlockDelta.delta.text,
message: new AIMessageChunk({
content: contentBlockDelta.delta.text,
}),
});
} else if (contentBlockDelta.delta.toolUse) {
const index = contentBlockDelta.contentBlockIndex;
return new ChatGenerationChunk({
text: "",
message: new AIMessageChunk({
content: "",
tool_call_chunks: [
{
args: contentBlockDelta.delta.toolUse.input,
index,
},
],
}),
});
} else {
const unsupportedField = Object.entries(contentBlockDelta.delta).filter(
([_, value]) => !!value
);
throw new Error(
`Unsupported content block type: ${unsupportedField[0][0]}`
);
}
} This change ensures that the |
Oof - will patch quickly, thanks for reporting! |
@wailinkyaww version |
Checked other resources
Example Code
This is from
@langchain/aws
.Link to source code -
langchainjs/libs/langchain-aws/src/common.ts
Line 378 in dbb3b59
Error Message and Stack Trace (if applicable)
Error Message
TypeError: undefined is not an object (evaluating 'unsupportedField[0][0]')
Stack Trace
The error is coming from -
langchainjs/libs/langchain-aws/src/common.ts
Line 401 in dbb3b59
Description
@langchain/aws
with streaming.empty string
as a token which will causecontentBlockDelta.delta.text
to be an empty string.text
using truthy/falsy behaviour of JS, the chunk doesn't fall into the first if block.This delta with an empty string ( text ) will goes into the else block.
langchainjs/libs/langchain-aws/src/common.ts
Line 401 in dbb3b59
In line 401, we are again retrieving the
unsupportedField
by checking the existence of the value.This will also fail because it is an empty string which will cause
unsupportedField
to be empty array.Basically our error handler is throwing the error here.
Resolution
I suggest we use the stricter type check instead of checking the existence of text from detla in
L370
.I believe the library shouldn't care about what kind of tokens are passing through. As long as it is a valid
string
, we shouldn't care.System Info
Package =>
@langchain-aws
-^0.0.2
Package manager => happens in both
yarn
andbun
( because it doesn't matter )The text was updated successfully, but these errors were encountered: