Llms: vector ops

This commit is contained in:
Enrico Ros
2025-11-12 10:56:42 -08:00
parent b9840c2074
commit 0bde01a85f
2 changed files with 25 additions and 10 deletions
+15 -1
View File
@@ -37,6 +37,7 @@ interface LlmsRootActions {
removeLLM: (id: DLLMId) => void;
rerankLLMsByServices: (serviceIdOrder: DModelsServiceId[]) => void;
updateLLM: (id: DLLMId, partial: Partial<DLLM>) => void;
updateLLMs: (updates: Array<{ id: DLLMId; partial: Partial<DLLM> }>) => void;
updateLLMUserParameters: (id: DLLMId, partial: Partial<DModelParameterValues>) => void;
deleteLLMUserParameter: (id: DLLMId, parameterId: DModelParameterId) => void;
resetLLMUserParameters: (id: DLLMId) => void;
@@ -141,6 +142,19 @@ export const useModelsStore = create<LlmsStore>()(persist(
),
})),
updateLLMs: (updates: Array<{ id: DLLMId; partial: Partial<DLLM> }>) =>
set(state => {
// Create a map of updates for efficient lookup
const updatesMap = new Map(updates.map(u => [u.id, u.partial]));
return {
llms: state.llms.map((llm: DLLM): DLLM => {
const partial = updatesMap.get(llm.id);
return partial ? { ...llm, ...partial } : llm;
}),
};
}),
updateLLMUserParameters: (id: DLLMId, partialUserParameters: Partial<DModelParameterValues>) =>
set(({ llms }) => ({
llms: llms.map((llm: DLLM): DLLM =>
@@ -252,7 +266,7 @@ export const useModelsStore = create<LlmsStore>()(persist(
* 2: large changes on all LLMs, and reset chat/fast/func LLMs
* 3: big-AGI v2.x upgrade
* 4: migrate .options to .initialParameters/.userParameters
* 4B: we changed from .chatLLMId/.fastLLMId to modelAssignments: {}, without expicit migration (done on rehydrate, and for no particular reason)
* 4B: we changed from .chatLLMId/.fastLLMId to modelAssignments: {}, without explicit migration (done on rehydrate, and for no particular reason)
*/
version: 4,
migrate: (_state: any, fromVersion: number): LlmsStore => {
@@ -48,22 +48,23 @@ export function OpenRouterServiceSetup(props: { serviceId: DModelsServiceId }) {
// ...bye / see you soon at the callback location...
};
const handleRemoveNonFreeLLMs = () => {
// A bit of a hack
const handleHIdeNonFreeLLMs = () => {
const { llms } = llmsStoreState();
const { updateLLM } = llmsStoreActions();
llms
const { updateLLMs } = llmsStoreActions();
const updates = llms
.filter(llm => llm.sId === props.serviceId)
.filter(llm => getLLMPricing(llm)?.chat?._isFree === false)
.forEach(llm => updateLLM(llm.id, { userHidden: true }));
.map(llm => ({ id: llm.id, partial: { userHidden: true } }));
updateLLMs(updates);
};
const handleSetVisibilityAll = React.useCallback((visible: boolean) => {
const { llms } = llmsStoreState();
const { updateLLM } = llmsStoreActions();
llms
const { updateLLMs } = llmsStoreActions();
const updates = llms
.filter(llm => llm.sId === props.serviceId)
.forEach(llm => updateLLM(llm.id, { userHidden: !visible }));
.map(llm => ({ id: llm.id, partial: { userHidden: !visible } }));
updateLLMs(updates);
}, [props.serviceId]);
return <>
@@ -112,7 +113,7 @@ export function OpenRouterServiceSetup(props: { serviceId: DModelsServiceId }) {
</Button>
<Button
color='neutral' variant='outlined' size='sm'
onClick={handleRemoveNonFreeLLMs}
onClick={handleHIdeNonFreeLLMs}
>
Only Free 🎁
</Button>