mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-28 11:16:31 +08:00
fix: clear stale tenant model ids (#18210)
### Summary Clear the paired tenant model ID when a model selection is explicitly cleared in a whitelisted API request. Replaces #18205. Co-authored-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -201,17 +201,26 @@ export function addTenantParams(data: any, url?: string): any {
|
||||
return data;
|
||||
}
|
||||
|
||||
const llmList = getCachedLlmList();
|
||||
if (!llmList) return data;
|
||||
|
||||
// Handle arrays
|
||||
if (Array.isArray(data)) {
|
||||
return data.map((item) => addTenantParams(item, url));
|
||||
}
|
||||
|
||||
const newData = { ...data };
|
||||
const llmList = getCachedLlmList();
|
||||
|
||||
// Clear the paired tenant ID when a model selection is explicitly cleared.
|
||||
for (const [paramName, tenantParamName] of Object.entries(modelParamMap)) {
|
||||
if (
|
||||
Object.hasOwn(newData, paramName) &&
|
||||
(newData[paramName] === '' || newData[paramName] == null)
|
||||
) {
|
||||
newData[tenantParamName] = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!llmList) return newData;
|
||||
|
||||
// Iterate through model parameters and add corresponding tenant parameters
|
||||
for (const [paramName, tenantParamName] of Object.entries(modelParamMap)) {
|
||||
if (newData[paramName]) {
|
||||
try {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
addTenantParams,
|
||||
buildModelValue,
|
||||
getEmbeddingBaseName,
|
||||
parseModelUuid,
|
||||
@@ -160,3 +161,29 @@ describe('getEmbeddingBaseName — dataset co-selection grouping', () => {
|
||||
expect(getEmbeddingBaseName(undefined)).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('addTenantParams — clearing model selections', () => {
|
||||
test('clears a stale tenant rerank model id when rerank is explicitly cleared', () => {
|
||||
expect(
|
||||
addTenantParams(
|
||||
{
|
||||
rerank_id: '',
|
||||
tenant_rerank_id: 'stale-tenant-model-id',
|
||||
},
|
||||
'/api/v1/chats/chat-id',
|
||||
),
|
||||
).toEqual({
|
||||
rerank_id: '',
|
||||
tenant_rerank_id: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('preserves the tenant rerank model id when rerank is not part of the request', () => {
|
||||
expect(
|
||||
addTenantParams(
|
||||
{ tenant_rerank_id: 'existing-tenant-model-id' },
|
||||
'/api/v1/chats/chat-id',
|
||||
),
|
||||
).toEqual({ tenant_rerank_id: 'existing-tenant-model-id' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user