-
Notifications
You must be signed in to change notification settings - Fork 285
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: Scaffold model invocation params form (#5040) #5045
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
362e31a
feat: Scaffold model invocation params form (#5040)
cephalization 1293ee3
fix: Fix types
cephalization 28d7093
fix: Fix test outputs by updating model schema
cephalization 100d14d
Send invocation parameters with completion stream params
cephalization 774346a
Generate invocation parameters form based on provider/model schema
cephalization e384393
Constrain invocation params by appropriate schema
cephalization 44d386f
Update playground span parsing error text
cephalization 3cc0af6
Improve commenting, delete out of date comments
cephalization d20f6d0
Read and validate invocation parameters from span into store
cephalization fc15b09
Improve playground span transformation test
cephalization 2b509e1
--amend
cephalization 419ff2a
Safely parse invocation params schema, separately from other model co…
cephalization File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import React from "react"; | ||
|
||
import { Flex, Slider, TextField } from "@arizeai/components"; | ||
|
||
import { ModelConfig } from "@phoenix/store"; | ||
import { Mutable } from "@phoenix/typeUtils"; | ||
|
||
import { getInvocationParametersSchema } from "./playgroundUtils"; | ||
import { InvocationParametersSchema } from "./schemas"; | ||
|
||
/** | ||
* Form field for a single invocation parameter. | ||
*/ | ||
const FormField = ({ | ||
field, | ||
value, | ||
onChange, | ||
}: { | ||
field: keyof InvocationParametersSchema; | ||
value: InvocationParametersSchema[keyof InvocationParametersSchema]; | ||
onChange: ( | ||
value: InvocationParametersSchema[keyof InvocationParametersSchema] | ||
) => void; | ||
}) => { | ||
switch (field) { | ||
case "temperature": | ||
if (typeof value !== "number" && value !== undefined) return null; | ||
return ( | ||
<Slider | ||
label="Temperature" | ||
value={value} | ||
step={0.1} | ||
minValue={0} | ||
maxValue={2} | ||
onChange={(value) => onChange(value)} | ||
/> | ||
); | ||
case "topP": | ||
if (typeof value !== "number" && value !== undefined) return null; | ||
return ( | ||
<Slider | ||
label="Top P" | ||
value={value} | ||
step={0.1} | ||
minValue={0} | ||
maxValue={1} | ||
onChange={(value) => onChange(value)} | ||
/> | ||
); | ||
case "maxCompletionTokens": | ||
return ( | ||
<TextField | ||
label="Max Completion Tokens" | ||
value={value?.toString() || ""} | ||
type="number" | ||
onChange={(value) => onChange(Number(value))} | ||
/> | ||
); | ||
case "maxTokens": | ||
return ( | ||
<TextField | ||
label="Max Tokens" | ||
value={value?.toString() || ""} | ||
type="number" | ||
onChange={(value) => onChange(Number(value))} | ||
/> | ||
); | ||
case "stop": | ||
if (!Array.isArray(value) && value !== undefined) return null; | ||
return ( | ||
<TextField | ||
label="Stop" | ||
defaultValue={value?.join(", ") || ""} | ||
onChange={(value) => onChange(value.split(/, */g))} | ||
/> | ||
); | ||
case "seed": | ||
return ( | ||
<TextField | ||
label="Seed" | ||
value={value?.toString() || ""} | ||
type="number" | ||
onChange={(value) => onChange(Number(value))} | ||
/> | ||
); | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
export type InvocationParametersChangeHandler = < | ||
T extends keyof ModelConfig["invocationParameters"], | ||
>( | ||
parameter: T, | ||
value: ModelConfig["invocationParameters"][T] | ||
) => void; | ||
|
||
type InvocationParametersFormProps = { | ||
model: ModelConfig; | ||
onChange: InvocationParametersChangeHandler; | ||
}; | ||
|
||
export const InvocationParametersForm = ({ | ||
model, | ||
onChange, | ||
}: InvocationParametersFormProps) => { | ||
const { invocationParameters, provider, modelName } = model; | ||
// Get the schema for the incoming provider and model combination. | ||
const schema = getInvocationParametersSchema({ | ||
modelProvider: provider, | ||
modelName: modelName || "default", | ||
}); | ||
|
||
const fieldsForSchema = Object.keys(schema.shape).map((field) => { | ||
const fieldKey = field as keyof (typeof schema)["shape"]; | ||
const value = invocationParameters[fieldKey]; | ||
return ( | ||
<FormField | ||
key={fieldKey} | ||
field={fieldKey} | ||
value={value === null ? undefined : (value as Mutable<typeof value>)} | ||
onChange={(value) => onChange(fieldKey, value)} | ||
/> | ||
); | ||
}); | ||
return ( | ||
<Flex direction="column" gap="size-200"> | ||
{fieldsForSchema} | ||
</Flex> | ||
); | ||
}; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be a form? We use https://www.react-hook-form.com/ react hook form, seem slike this could be used here iwth controllers etc. might be tough though with the genericness of it, but would probably give it a try, can be afollow up