-
-
Notifications
You must be signed in to change notification settings - Fork 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
✨ (openai) Add tools and functions support #1167
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe recent updates focus on enhancing form control and validation in a code editor component, expanding layout options for Zod fields, and integrating custom JavaScript functions within the OpenAI assistant interactions. This includes new UI elements for better user guidance and the ability to define and execute additional functions in various actions, as well as support for more diverse input types and programming languages in the layout metadata. 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 (
|
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files ignored due to path filters (4)
apps/docs/images/blocks/integrations/openai/tools.png
is excluded by:!**/*.png
packages/embeds/js/package.json
is excluded by:!**/*.json
packages/embeds/nextjs/package.json
is excluded by:!**/*.json
packages/embeds/react/package.json
is excluded by:!**/*.json
Files selected for processing (8)
- apps/builder/src/components/inputs/CodeEditor.tsx (4 hunks)
- apps/builder/src/features/forge/components/zodLayouts/ZodFieldLayout.tsx (7 hunks)
- apps/docs/editor/blocks/integrations/openai.mdx (2 hunks)
- packages/embeds/js/src/components/ConversationContainer/ConversationContainer.tsx (3 hunks)
- packages/forge/blocks/openai/actions/askAssistant.tsx (5 hunks)
- packages/forge/blocks/openai/actions/createChatCompletion.tsx (5 hunks)
- packages/forge/blocks/openai/helpers/parseToolParameters.ts (1 hunks)
- packages/forge/core/zod/extendWithTypebotLayout.ts (1 hunks)
Files not reviewed due to errors (1)
- apps/embeds/js/src/components/ConversationContainer/ConversationContainer.tsx (no review received)
Files skipped from review due to trivial changes (1)
- apps/docs/editor/blocks/integrations/openai.mdx
Additional comments: 12
packages/forge/blocks/openai/helpers/parseToolParameters.ts (1)
- 5-22: The function
parseToolParameters
correctly constructs an object of typeOpenAI.FunctionParameters
. It uses thereduce
method to accumulate properties, ensuring that only parameters with a name are included. Therequired
field is correctly populated with the names of parameters that are marked as required.packages/forge/core/zod/extendWithTypebotLayout.ts (1)
- 11-12: The
ZodLayoutMetadata
interface has been correctly extended to include newinputType
andlang
options, which now support'code'
and programming languages respectively. This aligns with the PR objectives to enhance input types and languages within the layout metadata.apps/builder/src/components/inputs/CodeEditor.tsx (1)
- 102-187: The
CodeEditor
component has been updated to include new props such aslabel
,moreInfoTooltip
,helperText
, andisRequired
. The use of Chakra UI'sFormControl
,FormLabel
, andFormHelperText
for form control and validation is correctly implemented. The component's props are properly passed down and used within the JSX, ensuring that the new UI elements are rendered as expected.packages/forge/blocks/openai/actions/askAssistant.tsx (3)
- 27-44: The
functions
option has been added to theaskAssistant
function, allowing the definition and use of custom JavaScript functions. This is consistent with the PR's goal of enhancing the OpenAI integration with custom tools and functions.- 85-118: The
fetchAssistantFunctions
function has been added to retrieve available assistant functions from the OpenAI service. The function checks for the presence ofoptions.assistantId
before proceeding, which is a good practice to avoid unnecessary API calls.- 192-236: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [132-266]
The
askAssistant
function now includes logic to handle and execute custom functions based on the assistant's requirements. The use ofAsyncFunction
to dynamically execute code is a powerful feature but should be used with caution due to potential security implications. Ensure that the code executed byAsyncFunction
is properly sandboxed and validated to prevent security vulnerabilities.apps/builder/src/features/forge/components/zodLayouts/ZodFieldLayout.tsx (2)
- 25-25: The
CodeEditor
component is correctly imported and used within theZodFieldLayout
component. This allows for code editing capabilities within the layout, aligning with the PR's objectives to enhance the application's UI components.- 238-258: The
CodeEditor
component is correctly rendered within theZodFieldLayout
when theinputType
is'code'
. The properties such asdefaultValue
,lang
,label
,placeholder
,helperText
,isRequired
,withVariableButton
, andmoreInfoTooltip
are properly passed to theCodeEditor
, ensuring that it is configured correctly.packages/forge/blocks/openai/actions/createChatCompletion.tsx (4)
- 4-10: The import statement for
ToolCallPayload
and theChatCompletionTool
type are correctly added to support the new payload types related to the execution of tools and functions within the OpenAI chat completions.- 37-54: The
parameterSchema
is correctly defined to describe the parameters for the OpenAI functions. It includes fields for the parameter's name, type, description, and whether it is required, which is essential for the correct execution of custom functions.- 56-77: The
functionToolItemSchema
is correctly defined to describe the tools that can be executed by the OpenAI model. It includes the tool's name, description, parameters, and code, which are necessary for defining and executing custom JavaScript functions.- 181-242: The logic to handle tool calls within the
createChatCompletion
action is correctly implemented. It constructs thetools
array from the options and usesparseToolParameters
to format the parameters. TheAsyncFunction
is used to execute the tool's code, and the results are appended to the messages array. This is a complex operation that should be carefully reviewed to ensure security and correctness.
Closes baptisteArno#863 Got helped from baptisteArno#1162 for the implementation. Closing it in favor of this PR. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced `CodeEditor` with additional properties for better form control and validation. - Introduced tools and functions in OpenAI integrations documentation for custom JavaScript execution. - Added capability to define and use custom JavaScript functions with the OpenAI assistant. - Expanded layout metadata options to include various input types and languages. - **Improvements** - Updated the OpenAI actions to support new function execution features. - **Documentation** - Added new sections for tools and functions in the OpenAI integrations guide. - **Refactor** - Refactored components and actions to integrate new features and improve existing functionalities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Closes #863
Got helped from #1162 for the implementation. Closing it in favor of this PR.
Summary by CodeRabbit
New Features
CodeEditor
with additional properties for better form control and validation.Improvements
Documentation
Refactor