-
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(playground): save model config by provider in preferences #5216
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
efe0731
feat(playground): save model config by provider in preferences
Parker-Stafford 8a08447
fallback to other saved providers if default is not there
Parker-Stafford 4df4f3e
update comment
Parker-Stafford 80b7290
update config save messaging
Parker-Stafford 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
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 | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,14 +18,18 @@ import { | |||||||||||||||
Picker, | ||||||||||||||||
Text, | ||||||||||||||||
TextField, | ||||||||||||||||
Tooltip, | ||||||||||||||||
TooltipTrigger, | ||||||||||||||||
View, | ||||||||||||||||
} from "@arizeai/components"; | ||||||||||||||||
|
||||||||||||||||
import { | ||||||||||||||||
AZURE_OPENAI_API_VERSIONS, | ||||||||||||||||
ModelProviders, | ||||||||||||||||
} from "@phoenix/constants/generativeConstants"; | ||||||||||||||||
import { useNotifySuccess } from "@phoenix/contexts"; | ||||||||||||||||
import { usePlaygroundContext } from "@phoenix/contexts/PlaygroundContext"; | ||||||||||||||||
import { usePreferencesContext } from "@phoenix/contexts/PreferencesContext"; | ||||||||||||||||
import { PlaygroundInstance } from "@phoenix/store"; | ||||||||||||||||
|
||||||||||||||||
import { ModelConfigButtonDialogQuery } from "./__generated__/ModelConfigButtonDialogQuery.graphql"; | ||||||||||||||||
|
@@ -43,6 +47,9 @@ function AzureOpenAiModelConfigFormField({ | |||||||||||||||
instance: PlaygroundInstance; | ||||||||||||||||
}) { | ||||||||||||||||
const updateModel = usePlaygroundContext((state) => state.updateModel); | ||||||||||||||||
const modelConfigByProvider = usePreferencesContext( | ||||||||||||||||
(state) => state.modelConfigByProvider | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
const updateModelConfig = useCallback( | ||||||||||||||||
({ | ||||||||||||||||
|
@@ -58,9 +65,10 @@ function AzureOpenAiModelConfigFormField({ | |||||||||||||||
...instance.model, | ||||||||||||||||
[configKey]: value, | ||||||||||||||||
}, | ||||||||||||||||
modelConfigByProvider, | ||||||||||||||||
}); | ||||||||||||||||
}, | ||||||||||||||||
[instance.id, instance.model, updateModel] | ||||||||||||||||
[instance.id, instance.model, modelConfigByProvider, updateModel] | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
return ( | ||||||||||||||||
|
@@ -128,13 +136,7 @@ export function ModelConfigButton(props: ModelConfigButtonProps) { | |||||||||||||||
size="compact" | ||||||||||||||||
onClick={() => { | ||||||||||||||||
startTransition(() => { | ||||||||||||||||
setDialog( | ||||||||||||||||
<Dialog title="Model Configuration" size="M"> | ||||||||||||||||
<Suspense> | ||||||||||||||||
<ModelConfigDialogContent {...props} /> | ||||||||||||||||
</Suspense> | ||||||||||||||||
</Dialog> | ||||||||||||||||
); | ||||||||||||||||
setDialog(<ModelConfigDialog {...props} />); | ||||||||||||||||
}); | ||||||||||||||||
}} | ||||||||||||||||
> | ||||||||||||||||
|
@@ -156,18 +158,75 @@ export function ModelConfigButton(props: ModelConfigButtonProps) { | |||||||||||||||
); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
interface ModelConfigDialogProps extends ModelConfigButtonProps {} | ||||||||||||||||
function ModelConfigDialog(props: ModelConfigDialogProps) { | ||||||||||||||||
const instance = usePlaygroundContext((state) => | ||||||||||||||||
state.instances.find( | ||||||||||||||||
(instance) => instance.id === props.playgroundInstanceId | ||||||||||||||||
) | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
if (!instance) { | ||||||||||||||||
throw new Error( | ||||||||||||||||
`Playground instance ${props.playgroundInstanceId} not found` | ||||||||||||||||
); | ||||||||||||||||
} | ||||||||||||||||
const setModelConfigForProvider = usePreferencesContext( | ||||||||||||||||
(state) => state.setModelConfigForProvider | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
const notifySuccess = useNotifySuccess(); | ||||||||||||||||
const onSaveConfig = useCallback(() => { | ||||||||||||||||
setModelConfigForProvider({ | ||||||||||||||||
provider: instance.model.provider, | ||||||||||||||||
modelConfig: instance.model, | ||||||||||||||||
}); | ||||||||||||||||
notifySuccess({ | ||||||||||||||||
title: "Model Configuration Saved", | ||||||||||||||||
message: `${ModelProviders[instance.model.provider]} model configuration saved`, | ||||||||||||||||
expireMs: 3000, | ||||||||||||||||
}); | ||||||||||||||||
}, [instance.model, notifySuccess, setModelConfigForProvider]); | ||||||||||||||||
return ( | ||||||||||||||||
<Dialog | ||||||||||||||||
title="Model Configuration" | ||||||||||||||||
size="M" | ||||||||||||||||
extra={ | ||||||||||||||||
<TooltipTrigger delay={0} offset={5}> | ||||||||||||||||
<Button size={"compact"} variant="default" onClick={onSaveConfig}> | ||||||||||||||||
Save Config | ||||||||||||||||
</Button> | ||||||||||||||||
<Tooltip> | ||||||||||||||||
Save {ModelProviders[instance.model.provider]} configuration to | ||||||||||||||||
local storage. | ||||||||||||||||
</Tooltip> | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
How does this sound? I'd probably avoid mentioning local storage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes much better! Thanks! |
||||||||||||||||
</TooltipTrigger> | ||||||||||||||||
} | ||||||||||||||||
> | ||||||||||||||||
<Suspense> | ||||||||||||||||
<ModelConfigDialogContent {...props} /> | ||||||||||||||||
</Suspense> | ||||||||||||||||
</Dialog> | ||||||||||||||||
); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
interface ModelConfigDialogContentProps extends ModelConfigButtonProps {} | ||||||||||||||||
function ModelConfigDialogContent(props: ModelConfigDialogContentProps) { | ||||||||||||||||
const { playgroundInstanceId } = props; | ||||||||||||||||
const updateModel = usePlaygroundContext((state) => state.updateModel); | ||||||||||||||||
const instance = usePlaygroundContext((state) => | ||||||||||||||||
state.instances.find((instance) => instance.id === playgroundInstanceId) | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
if (!instance) { | ||||||||||||||||
throw new Error( | ||||||||||||||||
`Playground instance ${props.playgroundInstanceId} not found` | ||||||||||||||||
); | ||||||||||||||||
} | ||||||||||||||||
const modelConfigByProvider = usePreferencesContext( | ||||||||||||||||
(state) => state.modelConfigByProvider | ||||||||||||||||
); | ||||||||||||||||
const updateModel = usePlaygroundContext((state) => state.updateModel); | ||||||||||||||||
|
||||||||||||||||
const query = useLazyLoadQuery<ModelConfigButtonDialogQuery>( | ||||||||||||||||
graphql` | ||||||||||||||||
query ModelConfigButtonDialogQuery($providerKey: GenerativeProviderKey!) { | ||||||||||||||||
|
@@ -186,9 +245,15 @@ function ModelConfigDialogContent(props: ModelConfigDialogContentProps) { | |||||||||||||||
provider: instance.model.provider, | ||||||||||||||||
modelName, | ||||||||||||||||
}, | ||||||||||||||||
modelConfigByProvider, | ||||||||||||||||
}); | ||||||||||||||||
}, | ||||||||||||||||
[instance.model.provider, playgroundInstanceId, updateModel] | ||||||||||||||||
[ | ||||||||||||||||
instance.model.provider, | ||||||||||||||||
modelConfigByProvider, | ||||||||||||||||
playgroundInstanceId, | ||||||||||||||||
updateModel, | ||||||||||||||||
] | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
const onInvocationParametersChange: InvocationParametersChangeHandler = | ||||||||||||||||
|
@@ -203,9 +268,10 @@ function ModelConfigDialogContent(props: ModelConfigDialogContentProps) { | |||||||||||||||
[parameter]: value, | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
modelConfigByProvider, | ||||||||||||||||
}); | ||||||||||||||||
}, | ||||||||||||||||
[instance.model, playgroundInstanceId, updateModel] | ||||||||||||||||
[instance.model, modelConfigByProvider, playgroundInstanceId, updateModel] | ||||||||||||||||
); | ||||||||||||||||
|
||||||||||||||||
return ( | ||||||||||||||||
|
@@ -221,6 +287,7 @@ function ModelConfigDialogContent(props: ModelConfigDialogContentProps) { | |||||||||||||||
provider, | ||||||||||||||||
modelName: null, | ||||||||||||||||
}, | ||||||||||||||||
modelConfigByProvider, | ||||||||||||||||
}); | ||||||||||||||||
}} | ||||||||||||||||
/> | ||||||||||||||||
|
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
106 changes: 106 additions & 0 deletions
106
app/src/store/playground/__tests__/playgroundStore.test.ts
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,106 @@ | ||
import { | ||
DEFAULT_MODEL_NAME, | ||
DEFAULT_MODEL_PROVIDER, | ||
} from "@phoenix/constants/generativeConstants"; | ||
|
||
import { | ||
_resetInstanceId, | ||
createPlaygroundInstance, | ||
getInitialInstances, | ||
} from "../playgroundStore"; | ||
import { InitialPlaygroundState } from "../types"; | ||
|
||
describe("getInitialInstances", () => { | ||
beforeEach(() => { | ||
_resetInstanceId(); | ||
}); | ||
it("should return instances from initialProps if they exist", () => { | ||
const existingInstance = { | ||
...createPlaygroundInstance(), | ||
model: { | ||
modelName: "test-model", | ||
provider: "OPENAI" as const, | ||
invocationParameters: {}, | ||
}, | ||
}; | ||
const initialProps: InitialPlaygroundState = { | ||
instances: [existingInstance], | ||
modelConfigByProvider: {}, | ||
}; | ||
|
||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toEqual([existingInstance]); | ||
}); | ||
|
||
it("should create a new default instance if no instances exist in initialProps and there are no saved modelConfigs", () => { | ||
const initialProps: InitialPlaygroundState = { | ||
modelConfigByProvider: {}, | ||
}; | ||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toHaveLength(1); | ||
expect(instances[0].id).toBe(0); | ||
expect(instances[0].model.provider).toBe(DEFAULT_MODEL_PROVIDER); | ||
expect(instances[0].model.modelName).toBe(DEFAULT_MODEL_NAME); | ||
}); | ||
|
||
it("should use saved model config if available", () => { | ||
const initialProps: InitialPlaygroundState = { | ||
modelConfigByProvider: { | ||
OPENAI: { | ||
modelName: "test-model", | ||
provider: "OPENAI", | ||
invocationParameters: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toHaveLength(1); | ||
expect(instances[0].model.provider).toBe("OPENAI"); | ||
expect(instances[0].model.modelName).toBe("test-model"); | ||
}); | ||
|
||
it("should use default model provider config if available", () => { | ||
const initialProps: InitialPlaygroundState = { | ||
modelConfigByProvider: { | ||
OPENAI: { | ||
modelName: "test-model-openai", | ||
provider: "OPENAI", | ||
invocationParameters: {}, | ||
}, | ||
ANTHROPIC: { | ||
modelName: "test-model-anthropic", | ||
provider: "ANTHROPIC", | ||
invocationParameters: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toHaveLength(1); | ||
expect(instances[0].model.provider).toBe("OPENAI"); | ||
expect(instances[0].model.modelName).toBe("test-model-openai"); | ||
}); | ||
|
||
it("should use any saved config if available if the default provider config is not", () => { | ||
const initialProps: InitialPlaygroundState = { | ||
modelConfigByProvider: { | ||
ANTHROPIC: { | ||
modelName: "test-model-anthropic", | ||
provider: "ANTHROPIC", | ||
invocationParameters: {}, | ||
}, | ||
}, | ||
}; | ||
|
||
const instances = getInitialInstances(initialProps); | ||
|
||
expect(instances).toHaveLength(1); | ||
expect(instances[0].model.provider).toBe("ANTHROPIC"); | ||
expect(instances[0].model.modelName).toBe("test-model-anthropic"); | ||
}); | ||
}); |
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.
any advice on messaging here is appreciated