|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | + |
| 3 | +import { |
| 4 | + CUSTOM_STEPS, |
| 5 | + OAUTH_STEPS, |
| 6 | + OLLAMA_STEPS, |
| 7 | + PRESET_STEPS, |
| 8 | + nextSamplingStepIndex, |
| 9 | + previousSamplingStepIndex, |
| 10 | + skipTopPWhenTemperatureSet, |
| 11 | + topPAfterTemperatureAdvance, |
| 12 | +} from "./steps.js"; |
| 13 | + |
| 14 | +const temperatureIndex = CUSTOM_STEPS.indexOf("temperature"); |
| 15 | +const topPIndex = CUSTOM_STEPS.indexOf("topP"); |
| 16 | +const effortsIndex = CUSTOM_STEPS.indexOf("efforts"); |
| 17 | +const maxTokensIndex = CUSTOM_STEPS.indexOf("maxTokens"); |
| 18 | +const defaultEffortIndex = CUSTOM_STEPS.indexOf("defaultEffort"); |
| 19 | + |
| 20 | +describe("custom provider sampling-step skip", () => { |
| 21 | + test("CUSTOM_STEPS includes sampling and effort steps", () => { |
| 22 | + expect(temperatureIndex).toBeGreaterThanOrEqual(0); |
| 23 | + expect(topPIndex).toBeGreaterThanOrEqual(0); |
| 24 | + expect(effortsIndex).toBeGreaterThanOrEqual(0); |
| 25 | + expect(maxTokensIndex).toBeGreaterThanOrEqual(0); |
| 26 | + expect(defaultEffortIndex).toBeGreaterThanOrEqual(0); |
| 27 | + }); |
| 28 | + |
| 29 | + test("nextSamplingStepIndex skips topP when temperature is set", () => { |
| 30 | + expect(nextSamplingStepIndex(CUSTOM_STEPS, temperatureIndex, "0.7")).toBe( |
| 31 | + effortsIndex, |
| 32 | + ); |
| 33 | + expect(nextSamplingStepIndex(CUSTOM_STEPS, temperatureIndex, "0")).toBe( |
| 34 | + effortsIndex, |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + test("nextSamplingStepIndex does not skip topP when temperature is blank", () => { |
| 39 | + expect(nextSamplingStepIndex(CUSTOM_STEPS, temperatureIndex, "")).toBe( |
| 40 | + topPIndex, |
| 41 | + ); |
| 42 | + expect(nextSamplingStepIndex(CUSTOM_STEPS, temperatureIndex, " ")).toBe( |
| 43 | + topPIndex, |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + test("nextSamplingStepIndex advances from topP to efforts", () => { |
| 48 | + expect(nextSamplingStepIndex(CUSTOM_STEPS, topPIndex, "")).toBe( |
| 49 | + effortsIndex, |
| 50 | + ); |
| 51 | + expect(nextSamplingStepIndex(CUSTOM_STEPS, topPIndex, "0.7")).toBe( |
| 52 | + effortsIndex, |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + test("nextSamplingStepIndex does not skip the temperature step", () => { |
| 57 | + expect(nextSamplingStepIndex(CUSTOM_STEPS, maxTokensIndex, "0.7")).toBe( |
| 58 | + temperatureIndex, |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + test("nextSamplingStepIndex is +1 on lists without sampling steps", () => { |
| 63 | + expect(nextSamplingStepIndex(PRESET_STEPS, 0, "0.7")).toBe(1); |
| 64 | + expect(nextSamplingStepIndex(OAUTH_STEPS, 0, "0.7")).toBe(1); |
| 65 | + expect(nextSamplingStepIndex(OLLAMA_STEPS, 0, "0.7")).toBe(1); |
| 66 | + }); |
| 67 | + |
| 68 | + test("previousSamplingStepIndex skips topP when temperature is set", () => { |
| 69 | + expect(previousSamplingStepIndex(CUSTOM_STEPS, effortsIndex, "0.7")).toBe( |
| 70 | + temperatureIndex, |
| 71 | + ); |
| 72 | + expect(previousSamplingStepIndex(CUSTOM_STEPS, effortsIndex, "0")).toBe( |
| 73 | + temperatureIndex, |
| 74 | + ); |
| 75 | + }); |
| 76 | + |
| 77 | + test("previousSamplingStepIndex does not skip topP when temperature is blank", () => { |
| 78 | + expect(previousSamplingStepIndex(CUSTOM_STEPS, effortsIndex, "")).toBe( |
| 79 | + topPIndex, |
| 80 | + ); |
| 81 | + expect(previousSamplingStepIndex(CUSTOM_STEPS, effortsIndex, " ")).toBe( |
| 82 | + topPIndex, |
| 83 | + ); |
| 84 | + }); |
| 85 | + |
| 86 | + test("previousSamplingStepIndex from topP lands on temperature", () => { |
| 87 | + expect(previousSamplingStepIndex(CUSTOM_STEPS, topPIndex, "0.7")).toBe( |
| 88 | + temperatureIndex, |
| 89 | + ); |
| 90 | + expect(previousSamplingStepIndex(CUSTOM_STEPS, topPIndex, "")).toBe( |
| 91 | + temperatureIndex, |
| 92 | + ); |
| 93 | + }); |
| 94 | + |
| 95 | + test("previousSamplingStepIndex does not skip two steps", () => { |
| 96 | + expect( |
| 97 | + previousSamplingStepIndex(CUSTOM_STEPS, defaultEffortIndex, "0.7"), |
| 98 | + ).toBe(effortsIndex); |
| 99 | + }); |
| 100 | + |
| 101 | + test("previousSamplingStepIndex floors at 0", () => { |
| 102 | + expect(previousSamplingStepIndex(CUSTOM_STEPS, 0, "0.7")).toBe(0); |
| 103 | + }); |
| 104 | + |
| 105 | + test("topPAfterTemperatureAdvance clears topP only when temperature is set", () => { |
| 106 | + expect(topPAfterTemperatureAdvance("0.7", "0.9")).toBe(""); |
| 107 | + expect(topPAfterTemperatureAdvance("0", "0.9")).toBe(""); |
| 108 | + expect(topPAfterTemperatureAdvance("", "0.9")).toBe("0.9"); |
| 109 | + expect(topPAfterTemperatureAdvance(" ", "0.9")).toBe("0.9"); |
| 110 | + }); |
| 111 | + |
| 112 | + test("skipTopPWhenTemperatureSet treats 0 as set and whitespace as unset", () => { |
| 113 | + expect(skipTopPWhenTemperatureSet("0")).toBe(true); |
| 114 | + expect(skipTopPWhenTemperatureSet("0.7")).toBe(true); |
| 115 | + expect(skipTopPWhenTemperatureSet("")).toBe(false); |
| 116 | + expect(skipTopPWhenTemperatureSet(" ")).toBe(false); |
| 117 | + }); |
| 118 | +}); |
0 commit comments