Skip to content

Commit e1a2acb

Browse files
authored
Merge pull request #1045 from unsync/feat/openrouter-support
feat: supports specific openrouter request parameters
2 parents 9645602 + a56116f commit e1a2acb

1 file changed

Lines changed: 31 additions & 3 deletions

File tree

src/providers/openrouter/chatComplete.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = {
4242
min: 0,
4343
max: 2,
4444
},
45+
modalities: {
46+
param: 'modalities',
47+
},
48+
reasoning: {
49+
param: 'reasoning',
50+
},
4551
top_p: {
4652
param: 'top_p',
4753
default: 1,
@@ -54,10 +60,22 @@ export const OpenrouterChatCompleteConfig: ProviderConfig = {
5460
tool_choice: {
5561
param: 'tool_choice',
5662
},
63+
transforms: {
64+
param: 'transforms',
65+
},
66+
provider: {
67+
param: 'provider',
68+
},
69+
models: {
70+
param: 'models',
71+
},
5772
stream: {
5873
param: 'stream',
5974
default: false,
6075
},
76+
response_format: {
77+
param: 'response_format',
78+
},
6179
};
6280

6381
interface OpenrouterChatCompleteResponse extends ChatCompletionResponse {
@@ -143,8 +161,18 @@ export const OpenrouterChatCompleteResponseTransform: (
143161
};
144162

145163
export const OpenrouterChatCompleteStreamChunkTransform: (
146-
response: string
147-
) => string = (responseChunk) => {
164+
response: string,
165+
fallbackId: string,
166+
_streamState: Record<string, boolean>,
167+
_strictOpenAiCompliance: boolean,
168+
gatewayRequest: Params
169+
) => string = (
170+
responseChunk,
171+
fallbackId,
172+
_streamState,
173+
_strictOpenAiCompliance,
174+
gatewayRequest
175+
) => {
148176
let chunk = responseChunk.trim();
149177
chunk = chunk.replace(/^data: /, '');
150178
chunk = chunk.trim();
@@ -154,7 +182,7 @@ export const OpenrouterChatCompleteStreamChunkTransform: (
154182
if (chunk.includes('OPENROUTER PROCESSING')) {
155183
chunk = JSON.stringify({
156184
id: `${Date.now()}`,
157-
model: '',
185+
model: gatewayRequest.model || '',
158186
object: 'chat.completion.chunk',
159187
created: Date.now(),
160188
choices: [

0 commit comments

Comments
 (0)