mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 16:57:46 +00:00
chore: add configurable cache control (#498)
* chore: add configurable cache control * fix: ci/cd
This commit is contained in:
@@ -217,6 +217,7 @@ export interface ConfigParameters {
|
||||
contentGenerator?: {
|
||||
timeout?: number;
|
||||
maxRetries?: number;
|
||||
disableCacheControl?: boolean;
|
||||
samplingParams?: {
|
||||
[key: string]: unknown;
|
||||
};
|
||||
@@ -302,6 +303,7 @@ export class Config {
|
||||
private readonly contentGenerator?: {
|
||||
timeout?: number;
|
||||
maxRetries?: number;
|
||||
disableCacheControl?: boolean;
|
||||
samplingParams?: Record<string, unknown>;
|
||||
};
|
||||
private readonly cliVersion?: string;
|
||||
@@ -801,6 +803,10 @@ export class Config {
|
||||
return this.contentGenerator?.maxRetries;
|
||||
}
|
||||
|
||||
getContentGeneratorDisableCacheControl(): boolean | undefined {
|
||||
return this.contentGenerator?.disableCacheControl;
|
||||
}
|
||||
|
||||
getContentGeneratorSamplingParams(): ContentGeneratorConfig['samplingParams'] {
|
||||
return this.contentGenerator?.samplingParams as
|
||||
| ContentGeneratorConfig['samplingParams']
|
||||
|
||||
@@ -121,6 +121,7 @@ describe('createContentGeneratorConfig', () => {
|
||||
getSamplingParams: vi.fn().mockReturnValue(undefined),
|
||||
getContentGeneratorTimeout: vi.fn().mockReturnValue(undefined),
|
||||
getContentGeneratorMaxRetries: vi.fn().mockReturnValue(undefined),
|
||||
getContentGeneratorDisableCacheControl: vi.fn().mockReturnValue(undefined),
|
||||
getContentGeneratorSamplingParams: vi.fn().mockReturnValue(undefined),
|
||||
getCliVersion: vi.fn().mockReturnValue('1.0.0'),
|
||||
} as unknown as Config;
|
||||
|
||||
@@ -62,6 +62,8 @@ export type ContentGeneratorConfig = {
|
||||
timeout?: number;
|
||||
// Maximum retries for failed requests
|
||||
maxRetries?: number;
|
||||
// Disable cache control for DashScope providers
|
||||
disableCacheControl?: boolean;
|
||||
samplingParams?: {
|
||||
top_p?: number;
|
||||
top_k?: number;
|
||||
@@ -99,6 +101,7 @@ export function createContentGeneratorConfig(
|
||||
enableOpenAILogging: config.getEnableOpenAILogging(),
|
||||
timeout: config.getContentGeneratorTimeout(),
|
||||
maxRetries: config.getContentGeneratorMaxRetries(),
|
||||
disableCacheControl: config.getContentGeneratorDisableCacheControl(),
|
||||
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.
|
||||
*
|
||||
@@ -242,7 +253,7 @@ export class OpenAIContentGenerator implements ContentGenerator {
|
||||
|
||||
// Add cache control to system and last messages for DashScope providers
|
||||
// Only add cache control to system message for non-streaming requests
|
||||
if (this.isDashScopeProvider()) {
|
||||
if (this.isDashScopeProvider() && !this.shouldDisableCacheControl()) {
|
||||
messages = this.addDashScopeCacheControl(
|
||||
messages,
|
||||
streaming ? 'both' : 'system',
|
||||
|
||||
Reference in New Issue
Block a user