mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-07 00:15:23 +02:00
🔧 fix: Filter urlContext in OpenAI transform and add param tests
Add `urlContext` to the Google-specific tool filter set in `transformToOpenAIConfig` so it doesn't leak into OpenAI-compatible flows. Also adds tests for url_context via defaultParams, addParams, and dropParams. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
8a0307a3ec
commit
f77fda9403
2 changed files with 67 additions and 7 deletions
|
|
@ -682,6 +682,57 @@ describe('getGoogleConfig', () => {
|
|||
expect(result.tools).toContainEqual({ urlContext: {} });
|
||||
expect(result.tools).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should enable url_context via defaultParams', () => {
|
||||
const credentials = {
|
||||
[AuthKeys.GOOGLE_API_KEY]: 'test-api-key',
|
||||
};
|
||||
|
||||
const result = getGoogleConfig(credentials, {
|
||||
modelOptions: {
|
||||
model: 'gemini-2.5-flash',
|
||||
},
|
||||
defaultParams: {
|
||||
url_context: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.tools).toContainEqual({ urlContext: {} });
|
||||
});
|
||||
|
||||
it('should enable url_context via addParams when initially disabled', () => {
|
||||
const credentials = {
|
||||
[AuthKeys.GOOGLE_API_KEY]: 'test-api-key',
|
||||
};
|
||||
|
||||
const result = getGoogleConfig(credentials, {
|
||||
modelOptions: {
|
||||
model: 'gemini-2.5-flash',
|
||||
url_context: false,
|
||||
},
|
||||
addParams: {
|
||||
url_context: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.tools).toContainEqual({ urlContext: {} });
|
||||
});
|
||||
|
||||
it('should disable url_context via dropParams', () => {
|
||||
const credentials = {
|
||||
[AuthKeys.GOOGLE_API_KEY]: 'test-api-key',
|
||||
};
|
||||
|
||||
const result = getGoogleConfig(credentials, {
|
||||
modelOptions: {
|
||||
model: 'gemini-2.5-flash',
|
||||
url_context: true,
|
||||
},
|
||||
dropParams: ['url_context'],
|
||||
});
|
||||
|
||||
expect(result.tools).not.toContainEqual({ urlContext: {} });
|
||||
});
|
||||
});
|
||||
|
||||
describe('Default and Add Parameters', () => {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ const googleExcludeParams = new Set([
|
|||
]);
|
||||
|
||||
/** Google-specific tool types that have no OpenAI-compatible equivalent */
|
||||
const googleToolsToFilter = new Set(['googleSearch']);
|
||||
const googleToolsToFilter = new Set(['googleSearch', 'urlContext']);
|
||||
|
||||
export type ConfigTools = Array<Record<string, unknown>> | Array<GoogleAIToolType>;
|
||||
|
||||
|
|
@ -134,11 +134,13 @@ export function transformToOpenAIConfig({
|
|||
|
||||
/**
|
||||
* Filter out provider-specific tools that have no OpenAI equivalent.
|
||||
* Exception: If web_search was explicitly enabled via addParams or defaultParams,
|
||||
* preserve googleSearch tools (pass through in Google-native format).
|
||||
* Exception: If web_search or url_context was explicitly enabled via addParams or defaultParams,
|
||||
* preserve the corresponding Google-native tools (googleSearch, urlContext).
|
||||
*/
|
||||
const webSearchExplicitlyEnabled =
|
||||
addParams?.web_search === true || defaultParams?.web_search === true;
|
||||
const urlContextExplicitlyEnabled =
|
||||
addParams?.url_context === true || defaultParams?.url_context === true;
|
||||
|
||||
const filterGoogleTool = (tool: unknown): boolean => {
|
||||
if (!isGoogle) {
|
||||
|
|
@ -149,11 +151,18 @@ export function transformToOpenAIConfig({
|
|||
}
|
||||
const toolKeys = Object.keys(tool as Record<string, unknown>);
|
||||
const isGoogleSpecificTool = toolKeys.some((key) => googleToolsToFilter.has(key));
|
||||
/** Preserve googleSearch if web_search was explicitly enabled */
|
||||
if (isGoogleSpecificTool && webSearchExplicitlyEnabled) {
|
||||
return true;
|
||||
if (isGoogleSpecificTool) {
|
||||
const hasGoogleSearch = toolKeys.includes('googleSearch');
|
||||
const hasUrlContext = toolKeys.includes('urlContext');
|
||||
if (hasGoogleSearch && webSearchExplicitlyEnabled) {
|
||||
return true;
|
||||
}
|
||||
if (hasUrlContext && urlContextExplicitlyEnabled) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return !isGoogleSpecificTool;
|
||||
return true;
|
||||
};
|
||||
|
||||
const filteredTools = Array.isArray(tools) ? tools.filter(filterGoogleTool) : [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue