mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-31 08:29:07 +08:00
test: add tests to verify numeric type conversion for temperature, topP, and custom parameters
Co-authored-by: DeJeune <67425183+DeJeune@users.noreply.github.com>
This commit is contained in:
parent
ba76919fe0
commit
78f2a4c799
@ -158,6 +158,29 @@ describe('modelParameters', () => {
|
||||
|
||||
expect(getTemperature(assistant, model)).toBe(0.8)
|
||||
})
|
||||
|
||||
it('converts string temperature values to numbers', () => {
|
||||
const assistant = createAssistant({ enableTemperature: true, temperature: '2.0' as any })
|
||||
const model = createModel({ id: 'gpt-4o', provider: 'openai', group: 'openai' })
|
||||
|
||||
const result = getTemperature(assistant, model)
|
||||
expect(result).toBe(2.0)
|
||||
expect(typeof result).toBe('number')
|
||||
})
|
||||
|
||||
it('converts string temperature values to numbers and clamps when necessary', () => {
|
||||
const assistant = createAssistant({ enableTemperature: true, temperature: '1.5' as any })
|
||||
const model = createModel({
|
||||
id: 'claude-sonnet-3.5',
|
||||
name: 'Claude 3.5 Sonnet',
|
||||
provider: 'anthropic',
|
||||
group: 'claude'
|
||||
})
|
||||
|
||||
const result = getTemperature(assistant, model)
|
||||
expect(result).toBe(1.0)
|
||||
expect(typeof result).toBe('number')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getTopP', () => {
|
||||
@ -200,6 +223,15 @@ describe('modelParameters', () => {
|
||||
|
||||
expect(getTopP(assistant, model)).toBeUndefined()
|
||||
})
|
||||
|
||||
it('converts string topP values to numbers', () => {
|
||||
const assistant = createAssistant({ enableTopP: true, topP: '0.9' as any })
|
||||
const model = createModel({ id: 'gpt-4o', provider: 'openai', group: 'openai' })
|
||||
|
||||
const result = getTopP(assistant, model)
|
||||
expect(result).toBe(0.9)
|
||||
expect(typeof result).toBe('number')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getTimeout', () => {
|
||||
|
||||
@ -988,5 +988,29 @@ describe('reasoning utils', () => {
|
||||
valid: 'value3'
|
||||
})
|
||||
})
|
||||
|
||||
it('should convert string number values to actual numbers for number type parameters', async () => {
|
||||
const assistant: Assistant = {
|
||||
id: 'test',
|
||||
name: 'Test',
|
||||
settings: {
|
||||
customParameters: [
|
||||
{ name: 'temperature', value: '2.0' as any, type: 'number' },
|
||||
{ name: 'maxTokens', value: '1000' as any, type: 'number' },
|
||||
{ name: 'topP', value: '0.9' as any, type: 'number' }
|
||||
]
|
||||
}
|
||||
} as Assistant
|
||||
|
||||
const result = getCustomParameters(assistant)
|
||||
expect(result).toEqual({
|
||||
temperature: 2.0,
|
||||
maxTokens: 1000,
|
||||
topP: 0.9
|
||||
})
|
||||
expect(typeof result.temperature).toBe('number')
|
||||
expect(typeof result.maxTokens).toBe('number')
|
||||
expect(typeof result.topP).toBe('number')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user