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

feat: Show invocation param errors within form #5559

Merged

Conversation

cephalization
Copy link
Contributor

@cephalization cephalization commented Nov 26, 2024

This involved a decently large refactor of InvocationParametersFormFields:

  • Remove redundant gql query, just load definitions from store after they are populated via ModelSupportedParametersFetcher
  • Update onChange to use referentially stable callbacks only, computations occur in store instead of inside of useCallback now
  • Memoize invocation parameter value mapping
  • Introduce react hook form, mirroring values and validating them
  • Wrap all form inputs in react hook form controllers, adding validation and passing through error messages
  • Fix controlled/uncontrolled warning in AzureOpenAiModelConfigFormField
  • Remove tools when tool_choice is not supported in incoming params

Resolves #5540
Resolves #5546

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 26, 2024
@@ -1,22 +1,19 @@
import React, { useCallback } from "react";
import { graphql, useLazyLoadQuery } from "react-relay";
import React, { useCallback, useLayoutEffect, useMemo } from "react";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Large but relevant diff

@@ -46,7 +61,7 @@ const InvocationParameterFormField = ({
<Slider
label={field.label}
isRequired={field.required}
value={value}
defaultValue={value}
Copy link
Contributor

Choose a reason for hiding this comment

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

why no controller around the slider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am just using controller to map errors to inputs, sliders can't have errors so I didn't see the point

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good, if it's low lift i might add it but yeah not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There isn't a possible error a slider can have since the value range is always constrained. I'm not sure what we could add to it

Comment on lines 284 to 292
const existingParameter = instanceInvocationParameters.find((p) =>
areInvocationParamsEqual(p, field)
);
const value = existingParameter
? getInvocationParameterValue(field, existingParameter)
: undefined;
return {
[field.invocationName!]: value ?? null,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

does this get defaults values from the server? I was working in this before i left and was running into issues here. It looks like we won't get the default no matter what here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the default will be merged into the store whenever model/provider is chosen. The only time you will lose the default value is if you manually edit/delete it

@Parker-Stafford
Copy link
Contributor

Couple of issues i noticed

  1. the param form doesnt show up until you start typing a deployment (model) name for azure, probably fine but the form does not actually depend on that for azure. (probably fine)
  2. the error for the form field only shows up on blur can be a bit confusing when the other error shows up first (nice to have)
Screen.Recording.2024-12-02.at.11.35.16.AM.mov
  1. saved config is overwritten when fields are dirty and are not - updated in this pr fix(playground): update saved model config to overwrite all model config if present #5544 to always respect saved config and defaults not dirty (debatable) and definitely not non dirty fields
Screen.Recording.2024-12-02.at.11.37.10.AM.mov

This involved a decently large refactor of InvocationParametersFormFields:
- Remove redundant gql query, just load definitions from store after they are populated via ModelSupportedParametersFetcher
- Update onChange to use referentially stable callbacks only, computations occur in store instead of inside of useCallback now
- Memoize invocation parameter value mapping
- Introduce react hook form, mirroring values and validating them
- Wrap all form inputs in react hook form controllers, adding validation and passing through error messages
- Fix controlled/uncontrolled warning in AzureOpenAiModelConfigFormField
Form values stay in-tact when model changes, unless that model has different parameter fields
@cephalization cephalization force-pushed the cephalization/5540-show-invocation-param-errors-in-form branch from 4c54856 to 5641a64 Compare December 3, 2024 17:08
@cephalization cephalization merged commit eac071f into main Dec 3, 2024
7 checks passed
@cephalization cephalization deleted the cephalization/5540-show-invocation-param-errors-in-form branch December 3, 2024 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: Done
2 participants