Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/backend/drivers/ai-chat/ChatCompletionDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});
});
Expand Down Expand Up @@ -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,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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;
Expand Down
Loading