mirror of
https://github.com/enricoros/big-AGI.git
synced 2026-05-10 21:50:14 -07:00
AutoConf w/ rerank of Vendors
This commit is contained in:
@@ -6,8 +6,8 @@ import { findAllModelVendors } from '~/modules/llms/vendors/vendors.registry';
|
||||
import { getBackendCapabilities } from '~/modules/backend/store-backend-capabilities';
|
||||
import { llmsUpdateModelsForServiceOrThrow } from '~/modules/llms/llm.client';
|
||||
|
||||
import type { DModelsService } from '~/common/stores/llms/modelsservice.types';
|
||||
import { llmsStoreState } from '~/common/stores/llms/store-llms';
|
||||
import type { DModelsService, DModelsServiceId } from '~/common/stores/llms/modelsservice.types';
|
||||
import { llmsStoreActions, llmsStoreState } from '~/common/stores/llms/store-llms';
|
||||
|
||||
|
||||
interface AutoConfStore {
|
||||
@@ -50,6 +50,9 @@ const autoConfVanillaStore = createVanillaStore<AutoConfStore>()(persist((_set,
|
||||
let configurableVendors = findAllModelVendors()
|
||||
.filter(vendor => vendor.hasBackendCapKey && backendCaps[vendor.hasBackendCapKey]);
|
||||
|
||||
// List to keep track of the service IDs in order
|
||||
const configuredServiceIds: DModelsServiceId[] = [];
|
||||
|
||||
// Sequentially auto-configure each vendor
|
||||
await configurableVendors.reduce(async (promiseChain, vendor) => {
|
||||
return promiseChain
|
||||
@@ -63,11 +66,14 @@ const autoConfVanillaStore = createVanillaStore<AutoConfStore>()(persist((_set,
|
||||
// create and append the model service, assuming the backend configuration will be successful
|
||||
service = createModelsServiceForVendor(vendor.id, modelsServices);
|
||||
addService(service);
|
||||
// re-find it now what's added
|
||||
// re-find it now that it's added
|
||||
service = llmsStoreState().sources.find(_s => _s.id === service.id)!;
|
||||
} else
|
||||
service = firstServiceForVendor;
|
||||
|
||||
// keep track of the configured service IDs
|
||||
configuredServiceIds.push(service.id);
|
||||
|
||||
// auto-configure this service
|
||||
await llmsUpdateModelsForServiceOrThrow(service.id, true);
|
||||
})
|
||||
@@ -81,6 +87,9 @@ const autoConfVanillaStore = createVanillaStore<AutoConfStore>()(persist((_set,
|
||||
});
|
||||
}, Promise.resolve());
|
||||
|
||||
// Re-rank the LLMs based on the order of configured services
|
||||
llmsStoreActions().rerankLLMsByServices(configuredServiceIds);
|
||||
|
||||
// end configuration
|
||||
_set({ isConfiguring: false, isConfigurationDone: true });
|
||||
},
|
||||
|
||||
@@ -30,6 +30,7 @@ interface LlmsActions {
|
||||
|
||||
setLLMs: (llms: DLLM[], serviceId: DModelsServiceId, deleteExpiredVendorLlms: boolean, keepUserEdits: boolean) => void;
|
||||
removeLLM: (id: DLLMId) => void;
|
||||
rerankLLMsByServices: (serviceIdOrder: DModelsServiceId[]) => void;
|
||||
updateLLM: (id: DLLMId, partial: Partial<DLLM>) => void;
|
||||
updateLLMOptions: <TLLMOptions>(id: DLLMId, partialOptions: Partial<TLLMOptions>) => void;
|
||||
|
||||
@@ -102,6 +103,26 @@ export const useModelsStore = create<LlmsState & LlmsActions>()(persist(
|
||||
};
|
||||
}),
|
||||
|
||||
rerankLLMsByServices: (serviceIdOrder: DModelsServiceId[]) =>
|
||||
set(state => {
|
||||
// Create a mapping of service IDs to their index in the provided order
|
||||
const serviceIdToIndex = serviceIdOrder.reduce((acc, sId, idx) => {
|
||||
acc[sId] = idx;
|
||||
return acc;
|
||||
}, {} as Record<DModelsServiceId, number>);
|
||||
|
||||
// Sort the LLMs based on the order of their service IDs
|
||||
const orderedLlms = [...state.llms].sort((a, b) => {
|
||||
const aIndex = serviceIdToIndex[a.sId] ?? Number.MAX_SAFE_INTEGER;
|
||||
const bIndex = serviceIdToIndex[b.sId] ?? Number.MAX_SAFE_INTEGER;
|
||||
return aIndex - bIndex;
|
||||
});
|
||||
|
||||
return {
|
||||
llms: orderedLlms,
|
||||
};
|
||||
}),
|
||||
|
||||
updateLLM: (id: DLLMId, partial: Partial<DLLM>) =>
|
||||
set(state => ({
|
||||
llms: state.llms.map((llm: DLLM): DLLM =>
|
||||
|
||||
Reference in New Issue
Block a user