-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Hide tool button on non-supported providers, Display errors for …
…missing invocation params (#5470) * fix: Hide tool button on providers that do not have tool support implemented * refactor: Hoist invocation param fetching to top level of instance, cache results in store Additionally moves invocation param filtering to just before making the completion queries, not when the invocation param form is opened * feat: Display error messages and tooltips when required invocation param fields are not provided * fix test * Remove redundant gql query in PlaygroundChatTemplateFooter * lint * Add comments * Merge default model parameter values with playground instance values * Use danger color alias for invocation param field errors * Rename variable for clarity * Simplify invocation parameter merging logic * Add comments describing reasoning for query field name aliases
- Loading branch information
1 parent
326830c
commit baecc54
Showing
15 changed files
with
617 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { useEffect } from "react"; | ||
import { graphql, useLazyLoadQuery } from "react-relay"; | ||
|
||
import { usePlaygroundContext } from "@phoenix/contexts/PlaygroundContext"; | ||
import { Mutable } from "@phoenix/typeUtils"; | ||
|
||
import { ModelSupportedParamsFetcherQuery } from "./__generated__/ModelSupportedParamsFetcherQuery.graphql"; | ||
|
||
/** | ||
* Fetches the supported invocation parameters for a model and syncs them to the | ||
* playground store instance. | ||
*/ | ||
export const ModelSupportedParamsFetcher = ({ | ||
instanceId, | ||
}: { | ||
instanceId: number; | ||
}) => { | ||
const modelProvider = usePlaygroundContext( | ||
(state) => | ||
state.instances.find((instance) => instance.id === instanceId)?.model | ||
.provider | ||
); | ||
const modelName = usePlaygroundContext( | ||
(state) => | ||
state.instances.find((instance) => instance.id === instanceId)?.model | ||
.modelName | ||
); | ||
const updateModelSupportedInvocationParameters = usePlaygroundContext( | ||
(state) => state.updateModelSupportedInvocationParameters | ||
); | ||
const { modelInvocationParameters } = | ||
useLazyLoadQuery<ModelSupportedParamsFetcherQuery>( | ||
graphql` | ||
query ModelSupportedParamsFetcherQuery($input: ModelsInput!) { | ||
modelInvocationParameters(input: $input) { | ||
__typename | ||
... on InvocationParameterBase { | ||
invocationName | ||
canonicalName | ||
required | ||
} | ||
# defaultValue must be aliased because Relay will not create a union type for fields with the same name | ||
# follow the naming convention of the field type e.g. floatDefaultValue for FloatInvocationParameter | ||
# default value mapping elsewhere in playground code relies on this naming convention | ||
# https://github.com/facebook/relay/issues/3776 | ||
... on BooleanInvocationParameter { | ||
booleanDefaultValue: defaultValue | ||
invocationInputField | ||
} | ||
... on BoundedFloatInvocationParameter { | ||
floatDefaultValue: defaultValue | ||
invocationInputField | ||
} | ||
... on FloatInvocationParameter { | ||
floatDefaultValue: defaultValue | ||
invocationInputField | ||
} | ||
... on IntInvocationParameter { | ||
intDefaultValue: defaultValue | ||
invocationInputField | ||
} | ||
... on JSONInvocationParameter { | ||
jsonDefaultValue: defaultValue | ||
invocationInputField | ||
} | ||
... on StringInvocationParameter { | ||
stringDefaultValue: defaultValue | ||
invocationInputField | ||
} | ||
... on StringListInvocationParameter { | ||
stringListDefaultValue: defaultValue | ||
invocationInputField | ||
} | ||
} | ||
} | ||
`, | ||
{ | ||
input: { | ||
providerKey: modelProvider, | ||
modelName, | ||
}, | ||
} | ||
); | ||
useEffect(() => { | ||
updateModelSupportedInvocationParameters({ | ||
instanceId, | ||
supportedInvocationParameters: modelInvocationParameters as Mutable< | ||
typeof modelInvocationParameters | ||
>, | ||
}); | ||
}, [ | ||
modelInvocationParameters, | ||
instanceId, | ||
updateModelSupportedInvocationParameters, | ||
]); | ||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.