mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
chore: add configurable cache control (#498)
* chore: add configurable cache control * fix: ci/cd
This commit is contained in:
@@ -523,6 +523,41 @@ export const SETTINGS_SCHEMA = {
|
|||||||
default: undefined as Record<string, unknown> | undefined,
|
default: undefined as Record<string, unknown> | undefined,
|
||||||
description: 'Content generator settings.',
|
description: 'Content generator settings.',
|
||||||
showInDialog: false,
|
showInDialog: false,
|
||||||
|
properties: {
|
||||||
|
timeout: {
|
||||||
|
type: 'number',
|
||||||
|
label: 'Timeout',
|
||||||
|
category: 'Content Generator',
|
||||||
|
requiresRestart: false,
|
||||||
|
default: undefined as number | undefined,
|
||||||
|
description: 'Request timeout in milliseconds.',
|
||||||
|
parentKey: 'contentGenerator',
|
||||||
|
childKey: 'timeout',
|
||||||
|
showInDialog: true,
|
||||||
|
},
|
||||||
|
maxRetries: {
|
||||||
|
type: 'number',
|
||||||
|
label: 'Max Retries',
|
||||||
|
category: 'Content Generator',
|
||||||
|
requiresRestart: false,
|
||||||
|
default: undefined as number | undefined,
|
||||||
|
description: 'Maximum number of retries for failed requests.',
|
||||||
|
parentKey: 'contentGenerator',
|
||||||
|
childKey: 'maxRetries',
|
||||||
|
showInDialog: true,
|
||||||
|
},
|
||||||
|
disableCacheControl: {
|
||||||
|
type: 'boolean',
|
||||||
|
label: 'Disable Cache Control',
|
||||||
|
category: 'Content Generator',
|
||||||
|
requiresRestart: false,
|
||||||
|
default: false,
|
||||||
|
description: 'Disable cache control for DashScope providers.',
|
||||||
|
parentKey: 'contentGenerator',
|
||||||
|
childKey: 'disableCacheControl',
|
||||||
|
showInDialog: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
enableOpenAILogging: {
|
enableOpenAILogging: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ export interface ConfigParameters {
|
|||||||
contentGenerator?: {
|
contentGenerator?: {
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
maxRetries?: number;
|
maxRetries?: number;
|
||||||
|
disableCacheControl?: boolean;
|
||||||
samplingParams?: {
|
samplingParams?: {
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
};
|
};
|
||||||
@@ -302,6 +303,7 @@ export class Config {
|
|||||||
private readonly contentGenerator?: {
|
private readonly contentGenerator?: {
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
maxRetries?: number;
|
maxRetries?: number;
|
||||||
|
disableCacheControl?: boolean;
|
||||||
samplingParams?: Record<string, unknown>;
|
samplingParams?: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
private readonly cliVersion?: string;
|
private readonly cliVersion?: string;
|
||||||
@@ -801,6 +803,10 @@ export class Config {
|
|||||||
return this.contentGenerator?.maxRetries;
|
return this.contentGenerator?.maxRetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getContentGeneratorDisableCacheControl(): boolean | undefined {
|
||||||
|
return this.contentGenerator?.disableCacheControl;
|
||||||
|
}
|
||||||
|
|
||||||
getContentGeneratorSamplingParams(): ContentGeneratorConfig['samplingParams'] {
|
getContentGeneratorSamplingParams(): ContentGeneratorConfig['samplingParams'] {
|
||||||
return this.contentGenerator?.samplingParams as
|
return this.contentGenerator?.samplingParams as
|
||||||
| ContentGeneratorConfig['samplingParams']
|
| ContentGeneratorConfig['samplingParams']
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ describe('createContentGeneratorConfig', () => {
|
|||||||
getSamplingParams: vi.fn().mockReturnValue(undefined),
|
getSamplingParams: vi.fn().mockReturnValue(undefined),
|
||||||
getContentGeneratorTimeout: vi.fn().mockReturnValue(undefined),
|
getContentGeneratorTimeout: vi.fn().mockReturnValue(undefined),
|
||||||
getContentGeneratorMaxRetries: vi.fn().mockReturnValue(undefined),
|
getContentGeneratorMaxRetries: vi.fn().mockReturnValue(undefined),
|
||||||
|
getContentGeneratorDisableCacheControl: vi.fn().mockReturnValue(undefined),
|
||||||
getContentGeneratorSamplingParams: vi.fn().mockReturnValue(undefined),
|
getContentGeneratorSamplingParams: vi.fn().mockReturnValue(undefined),
|
||||||
getCliVersion: vi.fn().mockReturnValue('1.0.0'),
|
getCliVersion: vi.fn().mockReturnValue('1.0.0'),
|
||||||
} as unknown as Config;
|
} as unknown as Config;
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ export type ContentGeneratorConfig = {
|
|||||||
timeout?: number;
|
timeout?: number;
|
||||||
// Maximum retries for failed requests
|
// Maximum retries for failed requests
|
||||||
maxRetries?: number;
|
maxRetries?: number;
|
||||||
|
// Disable cache control for DashScope providers
|
||||||
|
disableCacheControl?: boolean;
|
||||||
samplingParams?: {
|
samplingParams?: {
|
||||||
top_p?: number;
|
top_p?: number;
|
||||||
top_k?: number;
|
top_k?: number;
|
||||||
@@ -99,6 +101,7 @@ export function createContentGeneratorConfig(
|
|||||||
enableOpenAILogging: config.getEnableOpenAILogging(),
|
enableOpenAILogging: config.getEnableOpenAILogging(),
|
||||||
timeout: config.getContentGeneratorTimeout(),
|
timeout: config.getContentGeneratorTimeout(),
|
||||||
maxRetries: config.getContentGeneratorMaxRetries(),
|
maxRetries: config.getContentGeneratorMaxRetries(),
|
||||||
|
disableCacheControl: config.getContentGeneratorDisableCacheControl(),
|
||||||
samplingParams: config.getContentGeneratorSamplingParams(),
|
samplingParams: config.getContentGeneratorSamplingParams(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -212,6 +212,17 @@ export class OpenAIContentGenerator implements ContentGenerator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if cache control should be disabled based on configuration.
|
||||||
|
*
|
||||||
|
* @returns true if cache control should be disabled, false otherwise
|
||||||
|
*/
|
||||||
|
private shouldDisableCacheControl(): boolean {
|
||||||
|
return (
|
||||||
|
this.config.getContentGeneratorConfig()?.disableCacheControl === true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build metadata object for OpenAI API requests.
|
* Build metadata object for OpenAI API requests.
|
||||||
*
|
*
|
||||||
@@ -242,7 +253,7 @@ export class OpenAIContentGenerator implements ContentGenerator {
|
|||||||
|
|
||||||
// Add cache control to system and last messages for DashScope providers
|
// Add cache control to system and last messages for DashScope providers
|
||||||
// Only add cache control to system message for non-streaming requests
|
// Only add cache control to system message for non-streaming requests
|
||||||
if (this.isDashScopeProvider()) {
|
if (this.isDashScopeProvider() && !this.shouldDisableCacheControl()) {
|
||||||
messages = this.addDashScopeCacheControl(
|
messages = this.addDashScopeCacheControl(
|
||||||
messages,
|
messages,
|
||||||
streaming ? 'both' : 'system',
|
streaming ? 'both' : 'system',
|
||||||
|
|||||||
Reference in New Issue
Block a user