MCPcopy
hub / github.com/marimo-team/marimo / useModelChange

Function useModelChange

frontend/src/core/ai/config.ts:31–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29 * Hook for saving model and mode changes.
30 */
31export const useModelChange = () => {
32 const [userConfig, setUserConfig] = useAtom(userConfigAtom);
33 const { saveUserConfig } = useRequestClient();
34
35 const saveConfig = async (newConfig: Partial<UserConfig>) => {
36 await saveUserConfig({ config: newConfig }).then(() => {
37 setUserConfig((prev) => ({ ...prev, ...newConfig }));
38 });
39 };
40
41 const saveModelChange = async (
42 model: QualifiedModelId,
43 forRole: SupportedRole,
44 ) => {
45 const modelKey = getModelKeyForRole(forRole);
46
47 if (!modelKey) {
48 return;
49 }
50
51 const newConfig: Partial<UserConfig> = {
52 ai: {
53 ...userConfig.ai,
54 models: {
55 custom_models: userConfig.ai?.models?.custom_models ?? [],
56 displayed_models: userConfig.ai?.models?.displayed_models ?? [],
57 ...userConfig.ai?.models,
58 [modelKey]: model,
59 },
60 },
61 };
62
63 saveConfig(newConfig);
64 };
65
66 const saveModeChange = async (newMode: CopilotMode) => {
67 const newConfig: Partial<UserConfig> = {
68 ai: {
69 ...userConfig.ai,
70 mode: newMode,
71 },
72 };
73
74 saveConfig(newConfig);
75 };
76
77 return { saveModelChange, saveModeChange };
78};

Callers 2

chat-panel.tsxFile · 0.90
AIModelDropdownFunction · 0.90

Calls 1

useRequestClientFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…