feat: add/change model without reinit of extensions (#2334)
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
"license": {
|
||||
"name": "Apache-2.0"
|
||||
},
|
||||
"version": "1.0.19"
|
||||
"version": "1.0.20"
|
||||
},
|
||||
"paths": {
|
||||
"/agent/tools": {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { initializeSystem } from '../../../utils/providerUtils';
|
||||
import { initializeAgent } from '../../../agent';
|
||||
import { toastError, toastSuccess } from '../../../toasts';
|
||||
import { ProviderDetails } from '@/src/api';
|
||||
import Model, { getProviderMetadata } from './modelInterface';
|
||||
import { ProviderMetadata } from '../../../api';
|
||||
import type { ExtensionConfig, FixedExtensionEntry } from '../../ConfigContext';
|
||||
|
||||
// titles
|
||||
export const UNKNOWN_PROVIDER_TITLE = 'Provider name lookup';
|
||||
@@ -22,23 +21,16 @@ const SWITCH_MODEL_SUCCESS_MSG = 'Successfully switched models';
|
||||
interface changeModelProps {
|
||||
model: Model;
|
||||
writeToConfig: (key: string, value: unknown, is_secret: boolean) => Promise<void>;
|
||||
getExtensions?: (b: boolean) => Promise<FixedExtensionEntry[]>;
|
||||
addExtension?: (name: string, config: ExtensionConfig, enabled: boolean) => Promise<void>;
|
||||
}
|
||||
|
||||
// TODO: error handling
|
||||
export async function changeModel({
|
||||
model,
|
||||
writeToConfig,
|
||||
getExtensions,
|
||||
addExtension,
|
||||
}: changeModelProps) {
|
||||
export async function changeModel({ model, writeToConfig }: changeModelProps) {
|
||||
const modelName = model.name;
|
||||
const providerName = model.provider;
|
||||
try {
|
||||
await initializeSystem(providerName, modelName, {
|
||||
getExtensions,
|
||||
addExtension,
|
||||
await initializeAgent({
|
||||
model: model.name,
|
||||
provider: model.provider,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Failed to change model at agent step -- ${modelName} ${providerName}`);
|
||||
|
||||
@@ -30,7 +30,7 @@ export function BaseModelsList({
|
||||
} else {
|
||||
modelList = providedModelList;
|
||||
}
|
||||
const { read, upsert, getExtensions, addExtension } = useConfig();
|
||||
const { read, upsert } = useConfig();
|
||||
const [selectedModel, setSelectedModel] = useState<Model | null>(null);
|
||||
const [isInitialized, setIsInitialized] = useState(false);
|
||||
|
||||
@@ -75,7 +75,7 @@ export function BaseModelsList({
|
||||
}, [read, modelList, upsert]);
|
||||
|
||||
const handleModelSelection = async (model: Model) => {
|
||||
await changeModel({ model: model, writeToConfig: upsert, getExtensions, addExtension });
|
||||
await changeModel({ model: model, writeToConfig: upsert });
|
||||
};
|
||||
|
||||
const handleRadioChange = async (model: Model) => {
|
||||
|
||||
@@ -38,7 +38,7 @@ type AddModelModalProps = {
|
||||
setView: (view: View) => void;
|
||||
};
|
||||
export const AddModelModal = ({ onClose, setView }: AddModelModalProps) => {
|
||||
const { getProviders, upsert, getExtensions, addExtension } = useConfig();
|
||||
const { getProviders, upsert } = useConfig();
|
||||
const { switchModel } = useModel();
|
||||
const [providerOptions, setProviderOptions] = useState([]);
|
||||
const [modelOptions, setModelOptions] = useState([]);
|
||||
@@ -88,8 +88,6 @@ export const AddModelModal = ({ onClose, setView }: AddModelModalProps) => {
|
||||
await changeModel({
|
||||
model: modelObj,
|
||||
writeToConfig: upsert,
|
||||
getExtensions,
|
||||
addExtension,
|
||||
});
|
||||
|
||||
// Update the model context
|
||||
|
||||
Reference in New Issue
Block a user