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
8 changes: 4 additions & 4 deletions packages/api/src/llm/open-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const request = {
};

// The body of the request made to OpenRouter.
function sent(): {model: string; messages: unknown[]; tools: unknown[]; max_tokens: number; provider: {data_collection: string}} {
function sent(): {model: string; messages: unknown[]; tools: unknown[]; max_tokens: number; provider: Record<string, unknown>} {
return JSON.parse(String(fetchSpy.mock.calls[0]?.[1]?.body));
}

Expand All @@ -48,14 +48,14 @@ describe('askForTurn', () => {
expect(body.messages).toEqual(request.messages);
expect(body.tools).toEqual([{type: 'function', function: {name: 'read', description: 'Reads', parameters: {type: 'object', properties: {}}}}]);
expect(body.max_tokens).toBe(100);
expect(body.provider.data_collection).toBe('deny');
expect(body.provider).toEqual({data_collection: 'deny'});
});

test('asks GLM 5.3 for a persona switched to it', async () => {
test('asks GLM 5.3 for a persona switched to it, only of the hosts chosen, and only where they keep nothing', async () => {
await askForTurn({...request, model: 'glm'});

expect(sent().model).toBe('z-ai/glm-5.3');
expect(sent().provider.data_collection).toBe('deny');
expect(sent().provider).toEqual({only: ['together', 'fireworks', 'deepinfra', 'baseten'], data_collection: 'deny', zdr: true});
});

test('reads the calls the model made, with their arguments as it wrote them', async () => {
Expand Down
15 changes: 11 additions & 4 deletions packages/api/src/llm/open-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ export type ModelTool = {name: string; description: string; parameters: object};
export type {ModelMessage};

// Which hosts of the model OpenRouter may send the request to.
type ProviderPolicy = {order?: string[]; allow_fallbacks?: boolean; data_collection: 'deny'; zdr?: boolean};
type ProviderPolicy = {order?: string[]; only?: string[]; allow_fallbacks?: boolean; data_collection: 'deny'; zdr?: boolean};

// Only a host that neither keeps prompts nor trains on them: the conversation is the person's,
// and what their email and notes say is in it. GLM is open, served by dozens of hosts, the
// cheapest of them the least known: it goes only to these, American, and only where OpenRouter
// records them as keeping nothing, not even for a while to check for abuse.
const TURN_PROVIDERS: Record<ChatModel, ProviderPolicy> = {
claude: {data_collection: 'deny'},
glm: {only: ['together', 'fireworks', 'deepinfra', 'baseten'], data_collection: 'deny', zdr: true},
};

// What is sent to OpenRouter.
type CompletionBody = {
Expand Down Expand Up @@ -206,9 +215,7 @@ export function askForTurn(request: TurnRequest): Promise<Result<ModelTurn, ApiE
messages: request.messages,
tools: request.tools.map((tool) => ({type: 'function', function: {name: tool.name, description: tool.description, parameters: tool.parameters}})),
max_tokens: request.maxTokens,
// Only a host that neither keeps prompts nor trains on them: the conversation is
// the person's, and what their email and notes say is in it.
provider: {data_collection: 'deny'},
provider: TURN_PROVIDERS[request.model],
},
request.timeoutMs,
{model: request.model, purpose: 'turn'},
Expand Down
Loading