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:
lawrence
2026-08-19 19:05:03 +08:00
committed by GitHub
parent 371d83c2d8
commit c917d8b4e3
2 changed files with 40 additions and 4 deletions

View File

@@ -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 {

View File

@@ -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' });
});
});