-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
⬆️ Upgrade AI SDK #1641
⬆️ Upgrade AI SDK #1641
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes encompass several updates across multiple files and modules. Key updates include renaming components, introducing new functions and constants, updating import statements, and enhancing function parameters and configurations. Notable additions are related to AI module functions, tool parsing, and constants for various models and APIs. Additionally, there are semantic changes in several functions and enhancements in the parsing and handling of data streams. Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@coderabbitai review |
Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 9
Outside diff range, codebase verification and nitpick comments (1)
packages/ai/parseChatCompletionMessages.ts (1)
12-19
: Ensure proper typing for function parameters.The function parameters are well-defined, but consider using TypeScript interfaces or types for better maintainability and readability.
interface Message { role: 'Dialogue' | 'user' | 'assistant' | 'system'; startsBy?: 'user' | 'assistant'; dialogueVariableId?: string; content?: string; } interface Props { messages: Message[] | undefined; isVisionEnabled: boolean; shouldDownloadImages: boolean; variables: VariableStore; toolCalls?: ToolCallPart[]; toolResults?: ToolResultPart[]; }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (12)
apps/builder/public/templates/openai-assistant-chat.json
is excluded by!**/*.json
apps/docs/openapi/builder.json
is excluded by!**/*.json
apps/docs/openapi/viewer.json
is excluded by!**/*.json
apps/viewer/package.json
is excluded by!**/*.json
packages/ai/package.json
is excluded by!**/*.json
packages/bot-engine/package.json
is excluded by!**/*.json
packages/embeds/js/package.json
is excluded by!**/*.json
packages/forge/blocks/anthropic/package.json
is excluded by!**/*.json
packages/forge/blocks/difyAi/package.json
is excluded by!**/*.json
packages/forge/blocks/mistral/package.json
is excluded by!**/*.json
packages/forge/blocks/openai/package.json
is excluded by!**/*.json
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
,!**/*.yaml
Files selected for processing (34)
- apps/builder/src/components/icons.tsx (1 hunks)
- apps/builder/src/features/blocks/integrations/webhook/components/HttpRequestIcon.tsx (1 hunks)
- apps/builder/src/features/editor/components/BlockIcon.tsx (2 hunks)
- apps/builder/src/features/forge/components/ForgedBlockNodeContent.tsx (2 hunks)
- apps/builder/src/features/forge/components/zodLayouts/ZodFieldLayout.tsx (2 hunks)
- apps/builder/src/features/graph/components/nodes/block/BlockNodeContent.tsx (1 hunks)
- apps/builder/src/features/preview/components/WebPreview.tsx (2 hunks)
- packages/ai/parseChatCompletionMessages.ts (1 hunks)
- packages/ai/parseTools.ts (1 hunks)
- packages/ai/schemas.ts (1 hunks)
- packages/ai/splitUserTextMessageIntoBlocks.ts (1 hunks)
- packages/embeds/js/rollup.config.js (2 hunks)
- packages/embeds/js/src/features/blocks/integrations/openai/streamChat.ts (1 hunks)
- packages/forge/blocks/anthropic/actions/createChatMessage.tsx (6 hunks)
- packages/forge/blocks/anthropic/constants.ts (3 hunks)
- packages/forge/blocks/anthropic/helpers/isModelCompatibleWithVision.ts (1 hunks)
- packages/forge/blocks/anthropic/helpers/runChatCompletionStream.ts (1 hunks)
- packages/forge/blocks/elevenlabs/actions/convertTextToSpeech.ts (1 hunks)
- packages/forge/blocks/mistral/actions/createChatCompletion.ts (5 hunks)
- packages/forge/blocks/mistral/constants.ts (1 hunks)
- packages/forge/blocks/mistral/helpers/runChatCompletionStream.ts (1 hunks)
- packages/forge/blocks/openRouter/actions/createChatCompletion.tsx (4 hunks)
- packages/forge/blocks/openRouter/constants.ts (1 hunks)
- packages/forge/blocks/openai/actions/askAssistant.tsx (2 hunks)
- packages/forge/blocks/openai/actions/createChatCompletion.tsx (3 hunks)
- packages/forge/blocks/openai/helpers/AssistantStream.ts (4 hunks)
- packages/forge/blocks/openai/helpers/splitUserTextMessageIntoOpenAIBlocks.ts (1 hunks)
- packages/forge/blocks/openai/shared/parseChatCompletionOptions.ts (4 hunks)
- packages/forge/blocks/openai/shared/parseGenerateVariablesOptions.ts (1 hunks)
- packages/forge/blocks/openai/shared/runOpenAIChatCompletion.ts (1 hunks)
- packages/forge/blocks/openai/shared/runOpenAIChatCompletionStream.ts (1 hunks)
- packages/forge/blocks/togetherAi/actions/createChatCompletion.tsx (4 hunks)
- packages/forge/blocks/togetherAi/constants.ts (1 hunks)
- packages/forge/core/zod/extendWithTypebotLayout.ts (1 hunks)
Files skipped from review due to trivial changes (7)
- apps/builder/src/features/blocks/integrations/webhook/components/HttpRequestIcon.tsx
- apps/builder/src/features/editor/components/BlockIcon.tsx
- packages/forge/blocks/elevenlabs/actions/convertTextToSpeech.ts
- packages/forge/blocks/mistral/constants.ts
- packages/forge/blocks/openRouter/constants.ts
- packages/forge/blocks/openai/helpers/splitUserTextMessageIntoOpenAIBlocks.ts
- packages/forge/blocks/togetherAi/constants.ts
Additional context used
Biome
packages/ai/parseTools.ts
[error] 21-21: Avoid the use of spread (
...
) syntax on accumulators.Spread syntax should be avoided on accumulators (like those in
.reduce
) because it causes a time complexity ofO(n^2)
.
Consider methods such as .splice or .push instead.(lint/performance/noAccumulatingSpread)
Additional comments not posted (45)
packages/forge/blocks/anthropic/helpers/isModelCompatibleWithVision.ts (1)
1-5
: LGTM!The function
isModelCompatibleWithVision
is correctly implemented.packages/forge/blocks/anthropic/constants.ts (7)
Line range hint
1-7
:
LGTM!The
anthropicModels
constant is correctly defined.
11-15
: LGTM!The
anthropicLegacyModels
constant is correctly defined.
17-25
: LGTM!The
anthropicModelLabels
constant is correctly defined.
27-30
: LGTM!The
defaultAnthropicOptions
constant is correctly defined.
Line range hint
32-32
:
LGTM!The
modelsWithImageUrlSupport
constant is correctly defined.
Line range hint
34-38
:
LGTM!The
supportedImageTypes
constant is correctly defined.
42-42
: LGTM!The
maxToolCalls
constant is correctly defined.packages/forge/core/zod/extendWithTypebotLayout.ts (2)
Line range hint
6-27
:
LGTM!The
ZodLayoutMetadata
type definition is correctly implemented.
Line range hint
31-45
:
LGTM!The
extendWithTypebotLayout
function is correctly implemented.packages/embeds/js/rollup.config.js (1)
10-10
: Approved: Addition ofcommonjs
plugin.The addition of the
commonjs
plugin is a good practice to ensure compatibility with CommonJS modules.packages/forge/blocks/togetherAi/actions/createChatCompletion.tsx (4)
6-7
: Approved: Addition ofrunOpenAIChatCompletionStream
.The addition of
runOpenAIChatCompletionStream
enhances the functionality by enabling chat completion streams.
16-16
: Approved: Use ofdefaultTogetherOptions.temperature
.Setting the default temperature value from
defaultTogetherOptions
ensures consistency in configuration.
42-42
: Approved: Use ofrunOpenAIChatCompletion
with default base URL.The use of
runOpenAIChatCompletion
with the default base URL fromdefaultTogetherOptions
is appropriate.
48-53
: Approved: Configuration forrunOpenAIChatCompletionStream
.The configuration for
runOpenAIChatCompletionStream
is correctly set up with the default base URL.apps/builder/src/features/preview/components/WebPreview.tsx (1)
1-1
: Approved: Use ofThunderIcon
inhandleNewLogs
.The use of
ThunderIcon
in thehandleNewLogs
function is consistent with the recent renaming of the icon.Also applies to: 21-21
packages/forge/blocks/openRouter/actions/createChatCompletion.tsx (4)
6-7
: Approved: Addition ofrunOpenAIChatCompletionStream
.The addition of
runOpenAIChatCompletionStream
enhances the functionality by enabling chat completion streams.
38-38
: Approved: Use ofdefaultOpenRouterOptions.temperature
.Setting the default temperature value from
defaultOpenRouterOptions
ensures consistency in configuration.
59-59
: Approved: Use ofrunOpenAIChatCompletion
with default base URL.The use of
runOpenAIChatCompletion
with the default base URL fromdefaultOpenRouterOptions
is appropriate.
65-70
: Approved: Configuration forrunOpenAIChatCompletionStream
.The configuration for
runOpenAIChatCompletionStream
is correctly set up with the default base URL.packages/ai/schemas.ts (3)
4-17
: LGTM!The
parameterBase
schema is well-defined and includes appropriate layout configurations.
19-51
: LGTM!The
toolParametersSchema
is comprehensive and well-structured, ensuring type safety through the use of discriminated unions.
52-77
: LGTM!The
toolsSchema
is well-defined and includes comprehensive layout configurations for each property.packages/forge/blocks/openai/shared/parseChatCompletionOptions.ts (2)
4-4
: LGTM!The import statement for
toolsSchema
is correct and necessary for the subsequent usage.
Line range hint
45-75
:
LGTM!The
Props
type and theparseChatCompletionOptions
function are well-defined and include comprehensive layout configurations for each option.packages/ai/parseTools.ts (1)
39-70
: LGTM!The
parseParameters
function is well-defined and handles different parameter types correctly.packages/forge/blocks/openai/actions/createChatCompletion.tsx (1)
Line range hint
7-74
:
LGTM!The
createChatCompletion
action is well-defined and includes comprehensive configurations. The addition of therunOpenAIChatCompletionStream
function is appropriate and follows the existing pattern.packages/forge/blocks/openai/shared/parseGenerateVariablesOptions.ts (1)
Line range hint
2-2
:
Ensure the new import is necessary.The new import statement for
readDataStream
from@ai-sdk/ui-utils
should be verified to ensure it is used within the file.packages/embeds/js/src/features/blocks/integrations/openai/streamChat.ts (1)
2-2
: Ensure the new import is necessary.The new import statement for
readDataStream
from@ai-sdk/ui-utils
should be verified to ensure it is used within the file.packages/forge/blocks/openai/shared/runOpenAIChatCompletion.ts (1)
1-1
: Ensure the new import is necessary.The new import statement for
maxToolCalls
from../constants
should be verified to ensure it is used within the file.apps/builder/src/features/forge/components/ForgedBlockNodeContent.tsx (1)
3-3
: Ensure the new import is necessary.The new import statement for
ThunderIcon
from@/components/icons
should be verified to ensure it is used within the file.packages/forge/blocks/mistral/helpers/runChatCompletionStream.ts (1)
22-35
: Ensure proper error handling for missing API key and model.The function correctly handles missing API keys and models, returning appropriate HTTP errors. Ensure that these checks are comprehensive and cover all edge cases.
packages/forge/blocks/anthropic/helpers/runChatCompletionStream.ts (1)
23-36
: Ensure proper error handling for missing API key and model.The function correctly handles missing API keys and models, returning appropriate HTTP errors. Ensure that these checks are comprehensive and cover all edge cases.
packages/forge/blocks/mistral/actions/createChatCompletion.ts (2)
67-67
: Ensure proper schema validation for tools.The
tools
option uses a schema for validation. Ensure that the schema is comprehensive and covers all necessary validations.
144-149
: Ensure proper handling of streaming operations.The streaming operations are handled correctly, but consider breaking down the logic into smaller helper functions for better readability and maintainability.
packages/forge/blocks/openai/shared/runOpenAIChatCompletionStream.ts (2)
10-18
: LGTM! The type definition is well-structured.The
Props
type is well-defined and includes all necessary fields.
20-131
: Ensure proper error handling and stream management.The function
runOpenAIChatCompletionStream
is well-structured and includes comprehensive error handling and stream management. However, consider the following suggestions:
- Error Logging: Add logging for errors to facilitate debugging.
- Stream Management: Ensure that the stream is properly closed in all scenarios, including error cases.
packages/forge/blocks/openai/helpers/AssistantStream.ts (1)
Line range hint
1-153
:
Ensure proper error handling and stream management.The function
AssistantStream
is well-structured and includes comprehensive stream management and error handling. However, consider the following suggestions:
- Error Logging: Add logging for errors to facilitate debugging.
- Stream Management: Ensure that the stream is properly closed in all scenarios, including error cases.
packages/forge/blocks/anthropic/actions/createChatMessage.tsx (2)
53-57
: LGTM! The schema definition is well-structured.The
options
schema is well-defined and includes all necessary fields.
126-162
: Ensure proper error handling and stream management.The function
createChatMessage
is well-structured and includes comprehensive error handling and stream management. However, consider the following suggestions:
- Error Logging: Add logging for errors to facilitate debugging.
- Stream Management: Ensure that the stream is properly closed in all scenarios, including error cases.
Verification successful
Error handling and stream management are properly implemented.
The
createChatMessage
function in bothanthropic
anddifyAi
implementations already includes comprehensive error handling and stream management. No further changes are required.
packages/forge/blocks/anthropic/actions/createChatMessage.tsx
packages/forge/blocks/difyAi/actions/createChatMessage.ts
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the function usage and error handling. # Test: Search for the function usage. Expect: Proper error handling and stream management. rg --type python -A 5 $'createChatMessage'Length of output: 72
Script:
#!/bin/bash # Description: Verify the function usage and error handling. # Test: Search for the function usage. Expect: Proper error handling and stream management. rg --type tsx -A 5 $'createChatMessage'Length of output: 66
Script:
#!/bin/bash # Description: Verify the function usage and error handling. # Test: Search for the function usage. Expect: Proper error handling and stream management. rg --type ts -A 5 $'createChatMessage'Length of output: 2189
Script:
#!/bin/bash # Extract the implementation of createChatMessage from both files for verification. # Extract from anthropic/actions/createChatMessage.tsx ast-grep --lang tsx --pattern $'export const createChatMessage = createAction({ $$$ })' packages/forge/blocks/anthropic/actions/createChatMessage.tsx # Extract from difyAi/actions/createChatMessage.ts ast-grep --lang ts --pattern $'export const createChatMessage = createAction({ $$$ })' packages/forge/blocks/difyAi/actions/createChatMessage.tsLength of output: 32022
apps/builder/src/features/graph/components/nodes/block/BlockNodeContent.tsx (1)
158-158
: LGTM! The component changes are well-structured.The
BlockNodeContent
component is well-structured and includes comprehensive handling of different block types. Theindices
prop is correctly passed to theForgedBlockNodeContent
component.packages/forge/blocks/openai/actions/askAssistant.tsx (2)
14-16
: Ensure new imports are necessary and correctly used.The new imports
AssistantStream
,isModelCompatibleWithVision
, andsplitUserTextMessageIntoOpenAIBlocks
should be reviewed to ensure they are necessary and correctly used in the new functionality.
297-306
: Verify the correctness and integration of new functionality.The new conditional block using
isModelCompatibleWithVision
andsplitUserTextMessageIntoOpenAIBlocks
should be verified for correctness and proper integration with the existing code.apps/builder/src/features/forge/components/zodLayouts/ZodFieldLayout.tsx (1)
33-46
: Verify the correctness and integration of new propertytoLabels
.The new property
toLabels
in theparseEnumItems
function should be verified for correctness and proper integration with the existing code.apps/builder/src/components/icons.tsx (1)
300-302
: Verify the correctness and integration of new icon componentThunderIcon
.The new icon component
ThunderIcon
should be verified for correctness and proper integration with the existing code.
if (toolCalls && toolCalls.length > 0) { | ||
parsedMessages.push({ | ||
role: 'assistant', | ||
content: toolCalls, | ||
}) | ||
} | ||
|
||
if (toolResults && toolResults.length > 0) { | ||
parsedMessages.push({ | ||
role: 'tool', | ||
content: toolResults, | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider separating tool calls and results handling.
The logic for handling tool calls and results is mixed with the main message parsing logic. Consider separating this into a different function or section for better readability and maintainability.
const handleToolCallsAndResults = (parsedMessages, toolCalls, toolResults) => {
if (toolCalls && toolCalls.length > 0) {
parsedMessages.push({ role: 'assistant', content: toolCalls });
}
if (toolResults && toolResults.length > 0) {
parsedMessages.push({ role: 'tool', content: toolResults });
}
return parsedMessages;
};
try { | ||
const response = await streamText({ | ||
model, | ||
temperature: options.temperature | ||
? Number(options.temperature) | ||
: undefined, | ||
messages: await parseChatCompletionMessages({ | ||
messages: options.messages, | ||
isVisionEnabled: false, | ||
shouldDownloadImages: false, | ||
variables, | ||
toolCalls, | ||
toolResults, | ||
}), | ||
tools: parseTools({ tools: options.tools, variables }), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize model creation and message parsing logic.
The model creation and message parsing logic are intertwined. Consider breaking down the logic into smaller helper functions for better readability and maintainability.
const createModel = (apiKey, modelName) => {
return createMistral({ apiKey })(modelName);
};
const parseMessagesAndTools = async (options, variables, toolCalls, toolResults) => {
const messages = await parseChatCompletionMessages({
messages: options.messages,
isVisionEnabled: false,
shouldDownloadImages: false,
variables,
toolCalls,
toolResults,
});
const tools = parseTools({ tools: options.tools, variables });
return { messages, tools };
};
packages/forge/blocks/mistral/helpers/runChatCompletionStream.ts
Outdated
Show resolved
Hide resolved
try { | ||
const response = await streamText({ | ||
model, | ||
temperature: options.temperature | ||
? Number(options.temperature) | ||
: undefined, | ||
messages: await parseChatCompletionMessages({ | ||
messages: options.messages, | ||
isVisionEnabled: isModelCompatibleWithVision(modelName), | ||
shouldDownloadImages: false, | ||
variables, | ||
toolCalls, | ||
toolResults, | ||
}), | ||
tools: parseTools({ tools: options.tools, variables }), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize model creation and message parsing logic.
The model creation and message parsing logic are intertwined. Consider breaking down the logic into smaller helper functions for better readability and maintainability.
const createModel = (apiKey, modelName) => {
return createAnthropic({ apiKey })(modelName);
};
const parseMessagesAndTools = async (options, variables, toolCalls, toolResults) => {
const messages = await parseChatCompletionMessages({
messages: options.messages,
isVisionEnabled: isModelCompatibleWithVision(modelName),
shouldDownloadImages: false,
variables,
toolCalls,
toolResults,
});
const tools = parseTools({ tools: options.tools, variables });
return { messages, tools };
};
|
||
let totalToolCalls = 0 | ||
|
||
return { | ||
stream: new ReadableStream({ | ||
async start(controller) { | ||
const reader = response.toAIStream().getReader() | ||
|
||
async function pump(reader: ReadableStreamDefaultReader<Uint8Array>) { | ||
const { done, value } = await reader.read() | ||
|
||
if (done) { | ||
toolCalls = (await response.toolCalls) as ToolCallPart[] | ||
toolResults = (await response.toolResults) as | ||
| ToolResultPart[] | ||
| undefined | ||
return | ||
} | ||
|
||
controller.enqueue(value) | ||
return pump(reader) | ||
} | ||
|
||
await pump(reader) | ||
|
||
if ( | ||
toolCalls && | ||
toolCalls.length > 0 && | ||
totalToolCalls < maxToolCalls | ||
) { | ||
totalToolCalls += 1 | ||
const streamResponse = await runChatCompletionStream({ | ||
credentials: { apiKey }, | ||
options, | ||
variables, | ||
toolCalls, | ||
toolResults, | ||
}) | ||
if (!streamResponse.stream) | ||
throw new APICallError({ | ||
message: streamResponse.httpError?.message ?? 'Unknown error', | ||
statusCode: streamResponse.httpError?.status, | ||
url: '', | ||
requestBodyValues: {}, | ||
}) | ||
await pump(streamResponse.stream.getReader()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve readability and maintainability of stream handling logic.
The stream handling logic is complex and involves nested async operations and recursive calls. Consider breaking down the logic into smaller helper functions for better readability and maintainability.
const handleStream = async (response, controller, toolCalls, toolResults, totalToolCalls, maxToolCalls, apiKey, options, variables) => {
const reader = response.toAIStream().getReader();
const pump = async (reader) => {
const { done, value } = await reader.read();
if (done) {
toolCalls = (await response.toolCalls) as ToolCallPart[];
toolResults = (await response.toolResults) as ToolResultPart[] | undefined;
return;
}
controller.enqueue(value);
return pump(reader);
};
await pump(reader);
if (toolCalls && toolCalls.length > 0 && totalToolCalls < maxToolCalls) {
totalToolCalls += 1;
const streamResponse = await runChatCompletionStream({
credentials: { apiKey },
options,
variables,
toolCalls,
toolResults,
});
if (!streamResponse.stream) throw new APICallError({
message: streamResponse.httpError?.message ?? 'Unknown error',
statusCode: streamResponse.httpError?.status,
url: '',
requestBodyValues: {},
});
await pump(streamResponse.stream.getReader());
}
controller.close();
};
messages: await parseChatCompletionMessages({ | ||
messages: options.messages, | ||
variables, | ||
isVisionEnabled: false, | ||
shouldDownloadImages: false, | ||
}), | ||
tools: parseTools({ tools: options.tools, variables }), | ||
maxToolRoundtrips: maxToolRoundtrips, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize message parsing and tool handling logic.
The message parsing and tool handling logic are intertwined. Consider breaking down the logic into smaller helper functions for better readability and maintainability.
const parseMessagesAndTools = async (options, variables) => {
const messages = await parseChatCompletionMessages({
messages: options.messages,
variables,
isVisionEnabled: false,
shouldDownloadImages: false,
});
const tools = parseTools({ tools: options.tools, variables });
return { messages, tools };
};
No description provided.