fix together provider issues (#3140)
Maintain Release Merge PR / update-release-pr (push) Has been cancelled
Notify HeyPuter / notify (push) Has been cancelled
release-please / release-please (push) Has been cancelled

This commit is contained in:
ProgrammerIn-wonderland
2026-05-21 08:58:48 -04:00
committed by GitHub
parent 08369d840b
commit 71b7d6367f
3 changed files with 28 additions and 10 deletions
@@ -651,8 +651,18 @@ export class ChatCompletionDriver extends PuterDriver {
// thinking_tokens → output rate fallback
let rate = costs[key];
if (typeof rate !== 'number' || !Number.isFinite(rate)) {
if (key === 'thinking_tokens' && outputRate !== undefined) {
if (isOutputKey(key) && outputRate !== undefined) {
rate = outputRate;
} else if (!isOutputKey(key)) {
const inputRateRaw = costs[inputKey];
if (
typeof inputRateRaw === 'number' &&
Number.isFinite(inputRateRaw)
) {
rate = inputRateRaw;
} else {
continue;
}
} else {
continue;
}
@@ -433,10 +433,10 @@ describe('TogetherAIProvider.complete non-stream output', () => {
completion_tokens: 50,
cached_tokens: 0,
});
// Qwen pricing: input=20, output=20 (per million).
// Qwen pricing: input=20, output=20 (per million, dollars from API → ×100 for cents).
expect(overrides).toMatchObject({
prompt_tokens: 100 * 20,
completion_tokens: 50 * 20,
prompt_tokens: 100 * 20 * 100,
completion_tokens: 50 * 20 * 100,
});
});
});
@@ -484,13 +484,13 @@ describe('TogetherAIProvider.complete streaming', () => {
cached_tokens: 0,
});
// Qwen pricing: input=20, output=20.
// Qwen pricing: input=20, output=20 (dollars from API → ×100 for cents).
expect(recordSpy).toHaveBeenCalledTimes(1);
const [, , prefix, overrides] = recordSpy.mock.calls[0]!;
expect(prefix).toBe('togetherai:Qwen/Qwen2.5-7B-Instruct-Turbo');
expect(overrides).toMatchObject({
prompt_tokens: 4 * 20,
completion_tokens: 2 * 20,
prompt_tokens: 4 * 20 * 100,
completion_tokens: 2 * 20 * 100,
});
});
});
@@ -75,7 +75,11 @@ export class TogetherAIProvider implements IChatProvider {
output_cost_key: 'output',
costs: {
tokens: 1_000_000,
...model.pricing,
...Object.fromEntries(
Object.entries(model.pricing ?? {}).map(
([k, v]) => [k, (v as number) * 100],
),
),
},
max_tokens: model.context_length ?? 8000,
});
@@ -126,9 +130,13 @@ export class TogetherAIProvider implements IChatProvider {
const actor = Context.get('actor');
const models = await this.models();
const modelLower = model.toLowerCase();
const modelUsed =
models.find((m) => [m.id, ...(m.aliases || [])].includes(model)) ||
models.find((m) => m.id === this.getDefaultModel())!;
models.find((m) =>
[m.id, ...(m.aliases || [])].some(
(id) => id.toLowerCase() === modelLower,
),
) || models.find((m) => m.id === this.getDefaultModel())!;
const modelIdForParams = modelUsed.id.startsWith('togetherai:')
? modelUsed.id.slice('togetherai:'.length)
: modelUsed.id;