@openrouter/ai-sdk-provider 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -0
- package/dist/index.d.mts +228 -0
- package/dist/index.d.ts +228 -0
- package/dist/index.js +1062 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1056 -0
- package/dist/index.mjs.map +1 -0
- package/internal/dist/index.d.mts +133 -0
- package/internal/dist/index.d.ts +133 -0
- package/internal/dist/index.js +955 -0
- package/internal/dist/index.js.map +1 -0
- package/internal/dist/index.mjs +950 -0
- package/internal/dist/index.mjs.map +1 -0
- package/package.json +70 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { LanguageModelV1 } from '@ai-sdk/provider';
|
|
2
|
+
|
|
3
|
+
type OpenRouterChatModelId = string;
|
|
4
|
+
interface OpenRouterChatSettings {
|
|
5
|
+
/**
|
|
6
|
+
Modify the likelihood of specified tokens appearing in the completion.
|
|
7
|
+
|
|
8
|
+
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
9
|
+
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
10
|
+
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
11
|
+
the bias is added to the logits generated by the model prior to sampling.
|
|
12
|
+
The exact effect will vary per model, but values between -1 and 1 should
|
|
13
|
+
decrease or increase likelihood of selection; values like -100 or 100
|
|
14
|
+
should result in a ban or exclusive selection of the relevant token.
|
|
15
|
+
|
|
16
|
+
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
17
|
+
token from being generated.
|
|
18
|
+
*/
|
|
19
|
+
logitBias?: Record<number, number>;
|
|
20
|
+
/**
|
|
21
|
+
Return the log probabilities of the tokens. Including logprobs will increase
|
|
22
|
+
the response size and can slow down response times. However, it can
|
|
23
|
+
be useful to better understand how the model is behaving.
|
|
24
|
+
|
|
25
|
+
Setting to true will return the log probabilities of the tokens that
|
|
26
|
+
were generated.
|
|
27
|
+
|
|
28
|
+
Setting to a number will return the log probabilities of the top n
|
|
29
|
+
tokens that were generated.
|
|
30
|
+
*/
|
|
31
|
+
logprobs?: boolean | number;
|
|
32
|
+
/**
|
|
33
|
+
Whether to enable parallel function calling during tool use. Default to true.
|
|
34
|
+
*/
|
|
35
|
+
parallelToolCalls?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
A unique identifier representing your end-user, which can help OpenRouter to
|
|
38
|
+
monitor and detect abuse. Learn more.
|
|
39
|
+
*/
|
|
40
|
+
user?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type OpenRouterChatConfig = {
|
|
44
|
+
provider: string;
|
|
45
|
+
compatibility: "strict" | "compatible";
|
|
46
|
+
headers: () => Record<string, string | undefined>;
|
|
47
|
+
url: (options: {
|
|
48
|
+
modelId: string;
|
|
49
|
+
path: string;
|
|
50
|
+
}) => string;
|
|
51
|
+
fetch?: typeof fetch;
|
|
52
|
+
};
|
|
53
|
+
declare class OpenRouterChatLanguageModel implements LanguageModelV1 {
|
|
54
|
+
readonly specificationVersion = "v1";
|
|
55
|
+
readonly defaultObjectGenerationMode = "tool";
|
|
56
|
+
readonly modelId: OpenRouterChatModelId;
|
|
57
|
+
readonly settings: OpenRouterChatSettings;
|
|
58
|
+
private readonly config;
|
|
59
|
+
constructor(modelId: OpenRouterChatModelId, settings: OpenRouterChatSettings, config: OpenRouterChatConfig);
|
|
60
|
+
get provider(): string;
|
|
61
|
+
private getArgs;
|
|
62
|
+
doGenerate(options: Parameters<LanguageModelV1["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doGenerate"]>>>;
|
|
63
|
+
doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type OpenRouterCompletionModelId = "openai/gpt-3.5-turbo-instruct" | (string & {});
|
|
67
|
+
interface OpenRouterCompletionSettings {
|
|
68
|
+
/**
|
|
69
|
+
Echo back the prompt in addition to the completion.
|
|
70
|
+
*/
|
|
71
|
+
echo?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
Modify the likelihood of specified tokens appearing in the completion.
|
|
74
|
+
|
|
75
|
+
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
76
|
+
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
77
|
+
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
78
|
+
the bias is added to the logits generated by the model prior to sampling.
|
|
79
|
+
The exact effect will vary per model, but values between -1 and 1 should
|
|
80
|
+
decrease or increase likelihood of selection; values like -100 or 100
|
|
81
|
+
should result in a ban or exclusive selection of the relevant token.
|
|
82
|
+
|
|
83
|
+
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
84
|
+
token from being generated.
|
|
85
|
+
*/
|
|
86
|
+
logitBias?: Record<number, number>;
|
|
87
|
+
/**
|
|
88
|
+
Return the log probabilities of the tokens. Including logprobs will increase
|
|
89
|
+
the response size and can slow down response times. However, it can
|
|
90
|
+
be useful to better understand how the model is behaving.
|
|
91
|
+
|
|
92
|
+
Setting to true will return the log probabilities of the tokens that
|
|
93
|
+
were generated.
|
|
94
|
+
|
|
95
|
+
Setting to a number will return the log probabilities of the top n
|
|
96
|
+
tokens that were generated.
|
|
97
|
+
*/
|
|
98
|
+
logprobs?: boolean | number;
|
|
99
|
+
/**
|
|
100
|
+
The suffix that comes after a completion of inserted text.
|
|
101
|
+
*/
|
|
102
|
+
suffix?: string;
|
|
103
|
+
/**
|
|
104
|
+
A unique identifier representing your end-user, which can help OpenRouter to
|
|
105
|
+
monitor and detect abuse. Learn more.
|
|
106
|
+
*/
|
|
107
|
+
user?: string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
type OpenRouterCompletionConfig = {
|
|
111
|
+
provider: string;
|
|
112
|
+
compatibility: "strict" | "compatible";
|
|
113
|
+
headers: () => Record<string, string | undefined>;
|
|
114
|
+
url: (options: {
|
|
115
|
+
modelId: string;
|
|
116
|
+
path: string;
|
|
117
|
+
}) => string;
|
|
118
|
+
fetch?: typeof fetch;
|
|
119
|
+
};
|
|
120
|
+
declare class OpenRouterCompletionLanguageModel implements LanguageModelV1 {
|
|
121
|
+
readonly specificationVersion = "v1";
|
|
122
|
+
readonly defaultObjectGenerationMode: undefined;
|
|
123
|
+
readonly modelId: OpenRouterCompletionModelId;
|
|
124
|
+
readonly settings: OpenRouterCompletionSettings;
|
|
125
|
+
private readonly config;
|
|
126
|
+
constructor(modelId: OpenRouterCompletionModelId, settings: OpenRouterCompletionSettings, config: OpenRouterCompletionConfig);
|
|
127
|
+
get provider(): string;
|
|
128
|
+
private getArgs;
|
|
129
|
+
doGenerate(options: Parameters<LanguageModelV1["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doGenerate"]>>>;
|
|
130
|
+
doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface OpenRouterProvider {
|
|
134
|
+
(modelId: "openai/gpt-3.5-turbo-instruct", settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
|
|
135
|
+
(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
|
|
136
|
+
languageModel(modelId: "openai/gpt-3.5-turbo-instruct", settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
|
|
137
|
+
languageModel(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
|
|
138
|
+
/**
|
|
139
|
+
Creates an OpenRouter chat model for text generation.
|
|
140
|
+
*/
|
|
141
|
+
chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
|
|
142
|
+
/**
|
|
143
|
+
Creates an OpenRouter completion model for text generation.
|
|
144
|
+
*/
|
|
145
|
+
completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
|
|
146
|
+
}
|
|
147
|
+
interface OpenRouterProviderSettings {
|
|
148
|
+
/**
|
|
149
|
+
Base URL for the OpenRouter API calls.
|
|
150
|
+
*/
|
|
151
|
+
baseURL?: string;
|
|
152
|
+
/**
|
|
153
|
+
@deprecated Use `baseURL` instead.
|
|
154
|
+
*/
|
|
155
|
+
baseUrl?: string;
|
|
156
|
+
/**
|
|
157
|
+
API key for authenticating requests.
|
|
158
|
+
*/
|
|
159
|
+
apiKey?: string;
|
|
160
|
+
/**
|
|
161
|
+
OpenRouter Organization.
|
|
162
|
+
*/
|
|
163
|
+
organization?: string;
|
|
164
|
+
/**
|
|
165
|
+
OpenRouter project.
|
|
166
|
+
*/
|
|
167
|
+
project?: string;
|
|
168
|
+
/**
|
|
169
|
+
Custom headers to include in the requests.
|
|
170
|
+
*/
|
|
171
|
+
headers?: Record<string, string>;
|
|
172
|
+
/**
|
|
173
|
+
OpenRouter compatibility mode. Should be set to `strict` when using the OpenRouter API,
|
|
174
|
+
and `compatible` when using 3rd party providers. In `compatible` mode, newer
|
|
175
|
+
information such as streamOptions are not being sent. Defaults to 'compatible'.
|
|
176
|
+
*/
|
|
177
|
+
compatibility?: "strict" | "compatible";
|
|
178
|
+
/**
|
|
179
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
180
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
181
|
+
*/
|
|
182
|
+
fetch?: typeof fetch;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
Create an OpenRouter provider instance.
|
|
186
|
+
*/
|
|
187
|
+
declare function createOpenRouter(options?: OpenRouterProviderSettings): OpenRouterProvider;
|
|
188
|
+
/**
|
|
189
|
+
Default OpenRouter provider instance. It uses 'strict' compatibility mode.
|
|
190
|
+
*/
|
|
191
|
+
declare const openrouter: OpenRouterProvider;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
@deprecated Use `createOpenRouter` instead.
|
|
195
|
+
*/
|
|
196
|
+
declare class OpenRouter {
|
|
197
|
+
/**
|
|
198
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
199
|
+
The default prefix is `https://openrouter.ai/api/v1`.
|
|
200
|
+
*/
|
|
201
|
+
readonly baseURL: string;
|
|
202
|
+
/**
|
|
203
|
+
API key that is being send using the `Authorization` header.
|
|
204
|
+
It defaults to the `OPENAI_API_KEY` environment variable.
|
|
205
|
+
*/
|
|
206
|
+
readonly apiKey?: string;
|
|
207
|
+
/**
|
|
208
|
+
OpenRouter Organization.
|
|
209
|
+
*/
|
|
210
|
+
readonly organization?: string;
|
|
211
|
+
/**
|
|
212
|
+
OpenRouter project.
|
|
213
|
+
*/
|
|
214
|
+
readonly project?: string;
|
|
215
|
+
/**
|
|
216
|
+
Custom headers to include in the requests.
|
|
217
|
+
*/
|
|
218
|
+
readonly headers?: Record<string, string>;
|
|
219
|
+
/**
|
|
220
|
+
* Creates a new OpenRouter provider instance.
|
|
221
|
+
*/
|
|
222
|
+
constructor(options?: OpenRouterProviderSettings);
|
|
223
|
+
private get baseConfig();
|
|
224
|
+
chat(modelId: OpenRouterChatModelId, settings?: OpenRouterChatSettings): OpenRouterChatLanguageModel;
|
|
225
|
+
completion(modelId: OpenRouterCompletionModelId, settings?: OpenRouterCompletionSettings): OpenRouterCompletionLanguageModel;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { OpenRouter, type OpenRouterProvider, type OpenRouterProviderSettings, createOpenRouter, openrouter };
|