mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-07-09 17:19:02 +00:00
fix(core): preserve invalid schema length strings (#5312)
This commit is contained in:
parent
41efcf0ff6
commit
5a73dcfc84
2 changed files with 39 additions and 2 deletions
|
|
@ -4186,6 +4186,38 @@ describe('OpenAIContentConverter', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('should not truncate non-integer length constraints', () => {
|
||||
const params = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
text: {
|
||||
type: 'string',
|
||||
minLength: '1.5',
|
||||
maxLength: ' ',
|
||||
},
|
||||
items: {
|
||||
type: 'array',
|
||||
minItems: '10px',
|
||||
maxItems: '1.5',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const result = converter.convertGeminiToolParametersToOpenAI(params);
|
||||
const properties = result?.['properties'] as Record<string, unknown>;
|
||||
|
||||
expect(properties?.['text']).toEqual({
|
||||
type: 'string',
|
||||
minLength: '1.5',
|
||||
maxLength: ' ',
|
||||
});
|
||||
expect(properties?.['items']).toEqual({
|
||||
type: 'array',
|
||||
minItems: '10px',
|
||||
maxItems: '1.5',
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle nested objects', () => {
|
||||
const params = {
|
||||
type: 'object',
|
||||
|
|
|
|||
|
|
@ -285,8 +285,13 @@ export function convertGeminiToolParametersToOpenAI(
|
|||
key === 'maxItems'
|
||||
) {
|
||||
// Ensure length constraints are integers, not strings
|
||||
if (typeof value === 'string' && !isNaN(Number(value))) {
|
||||
result[key] = parseInt(value, 10);
|
||||
const numberValue = typeof value === 'string' ? Number(value) : NaN;
|
||||
if (
|
||||
typeof value === 'string' &&
|
||||
value.trim() !== '' &&
|
||||
Number.isInteger(numberValue)
|
||||
) {
|
||||
result[key] = numberValue;
|
||||
} else {
|
||||
result[key] = value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue