@llmgateway/ai-sdk-provider 1.0.0
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/LICENSE +201 -0
- package/README.md +187 -0
- package/dist/index.cjs +1398 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +263 -0
- package/dist/index.d.ts +263 -0
- package/dist/index.js +1390 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/index.cjs +1298 -0
- package/dist/internal/index.cjs.map +1 -0
- package/dist/internal/index.d.cts +184 -0
- package/dist/internal/index.d.ts +184 -0
- package/dist/internal/index.js +1291 -0
- package/dist/internal/index.js.map +1 -0
- package/package.json +82 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { LanguageModelV1 } from '@ai-sdk/provider';
|
|
2
|
+
export { LanguageModelV1 } from '@ai-sdk/provider';
|
|
3
|
+
|
|
4
|
+
type LLMGatewayLanguageModel = LanguageModelV1;
|
|
5
|
+
type LLMGatewayProviderOptions = {
|
|
6
|
+
models?: string[];
|
|
7
|
+
/**
|
|
8
|
+
* https://llmgateway.io/docs/use-cases/reasoning-tokens
|
|
9
|
+
* One of `max_tokens` or `effort` is required.
|
|
10
|
+
* If `exclude` is true, reasoning will be removed from the response. Default is false.
|
|
11
|
+
*/
|
|
12
|
+
reasoning?: {
|
|
13
|
+
exclude?: boolean;
|
|
14
|
+
} & ({
|
|
15
|
+
max_tokens: number;
|
|
16
|
+
} | {
|
|
17
|
+
effort: 'high' | 'medium' | 'low';
|
|
18
|
+
});
|
|
19
|
+
/**
|
|
20
|
+
* A unique identifier representing your end-user, which can
|
|
21
|
+
* help LLMGateway to monitor and detect abuse.
|
|
22
|
+
*/
|
|
23
|
+
user?: string;
|
|
24
|
+
};
|
|
25
|
+
type LLMGatewaySharedSettings = LLMGatewayProviderOptions & {
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated use `reasoning` instead
|
|
28
|
+
*/
|
|
29
|
+
includeReasoning?: boolean;
|
|
30
|
+
extraBody?: Record<string, unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* Enable usage accounting to get detailed token usage information.
|
|
33
|
+
* https://llmgateway.io/docs/use-cases/usage-accounting
|
|
34
|
+
*/
|
|
35
|
+
usage?: {
|
|
36
|
+
/**
|
|
37
|
+
* When true, includes token usage information in the response.
|
|
38
|
+
*/
|
|
39
|
+
include: boolean;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Usage accounting response
|
|
44
|
+
* @see https://llmgateway.io/docs/use-cases/usage-accounting
|
|
45
|
+
*/
|
|
46
|
+
type LLMGatewayUsageAccounting = {
|
|
47
|
+
promptTokens: number;
|
|
48
|
+
promptTokensDetails?: {
|
|
49
|
+
cachedTokens: number;
|
|
50
|
+
};
|
|
51
|
+
completionTokens: number;
|
|
52
|
+
completionTokensDetails?: {
|
|
53
|
+
reasoningTokens: number;
|
|
54
|
+
};
|
|
55
|
+
totalTokens: number;
|
|
56
|
+
cost?: number;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type LLMGatewayCompletionModelId = string;
|
|
60
|
+
type LLMGatewayCompletionSettings = {
|
|
61
|
+
/**
|
|
62
|
+
Modify the likelihood of specified tokens appearing in the completion.
|
|
63
|
+
|
|
64
|
+
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
65
|
+
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
66
|
+
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
67
|
+
the bias is added to the logits generated by the model prior to sampling.
|
|
68
|
+
The exact effect will vary per model, but values between -1 and 1 should
|
|
69
|
+
decrease or increase likelihood of selection; values like -100 or 100
|
|
70
|
+
should result in a ban or exclusive selection of the relevant token.
|
|
71
|
+
|
|
72
|
+
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
73
|
+
token from being generated.
|
|
74
|
+
*/
|
|
75
|
+
logitBias?: Record<number, number>;
|
|
76
|
+
/**
|
|
77
|
+
Return the log probabilities of the tokens. Including logprobs will increase
|
|
78
|
+
the response size and can slow down response times. However, it can
|
|
79
|
+
be useful to better understand how the model is behaving.
|
|
80
|
+
|
|
81
|
+
Setting to true will return the log probabilities of the tokens that
|
|
82
|
+
were generated.
|
|
83
|
+
|
|
84
|
+
Setting to a number will return the log probabilities of the top n
|
|
85
|
+
tokens that were generated.
|
|
86
|
+
*/
|
|
87
|
+
logprobs?: boolean | number;
|
|
88
|
+
/**
|
|
89
|
+
The suffix that comes after a completion of inserted text.
|
|
90
|
+
*/
|
|
91
|
+
suffix?: string;
|
|
92
|
+
} & LLMGatewaySharedSettings;
|
|
93
|
+
|
|
94
|
+
type LLMGatewayChatModelId = string;
|
|
95
|
+
type LLMGatewayChatSettings = {
|
|
96
|
+
/**
|
|
97
|
+
Modify the likelihood of specified tokens appearing in the completion.
|
|
98
|
+
|
|
99
|
+
Accepts a JSON object that maps tokens (specified by their token ID in
|
|
100
|
+
the GPT tokenizer) to an associated bias value from -100 to 100. You
|
|
101
|
+
can use this tokenizer tool to convert text to token IDs. Mathematically,
|
|
102
|
+
the bias is added to the logits generated by the model prior to sampling.
|
|
103
|
+
The exact effect will vary per model, but values between -1 and 1 should
|
|
104
|
+
decrease or increase likelihood of selection; values like -100 or 100
|
|
105
|
+
should result in a ban or exclusive selection of the relevant token.
|
|
106
|
+
|
|
107
|
+
As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
|
|
108
|
+
token from being generated.
|
|
109
|
+
*/
|
|
110
|
+
logitBias?: Record<number, number>;
|
|
111
|
+
/**
|
|
112
|
+
Return the log probabilities of the tokens. Including logprobs will increase
|
|
113
|
+
the response size and can slow down response times. However, it can
|
|
114
|
+
be useful to better understand how the model is behaving.
|
|
115
|
+
|
|
116
|
+
Setting to true will return the log probabilities of the tokens that
|
|
117
|
+
were generated.
|
|
118
|
+
|
|
119
|
+
Setting to a number will return the log probabilities of the top n
|
|
120
|
+
tokens that were generated.
|
|
121
|
+
*/
|
|
122
|
+
logprobs?: boolean | number;
|
|
123
|
+
/**
|
|
124
|
+
Whether to enable parallel function calling during tool use. Default to true.
|
|
125
|
+
*/
|
|
126
|
+
parallelToolCalls?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
A unique identifier representing your end-user, which can help LLMGateway to
|
|
129
|
+
monitor and detect abuse. Learn more.
|
|
130
|
+
*/
|
|
131
|
+
user?: string;
|
|
132
|
+
} & LLMGatewaySharedSettings;
|
|
133
|
+
|
|
134
|
+
type LLMGatewayChatConfig = {
|
|
135
|
+
provider: string;
|
|
136
|
+
compatibility: 'strict' | 'compatible';
|
|
137
|
+
headers: () => Record<string, string | undefined>;
|
|
138
|
+
url: (options: {
|
|
139
|
+
modelId: string;
|
|
140
|
+
path: string;
|
|
141
|
+
}) => string;
|
|
142
|
+
fetch?: typeof fetch;
|
|
143
|
+
extraBody?: Record<string, unknown>;
|
|
144
|
+
};
|
|
145
|
+
type DoGenerateOutput = Awaited<ReturnType<LanguageModelV1['doGenerate']>>;
|
|
146
|
+
type DoStreamOutput = Awaited<ReturnType<LanguageModelV1['doStream']>>;
|
|
147
|
+
declare class LLMGatewayChatLanguageModel implements LanguageModelV1 {
|
|
148
|
+
readonly specificationVersion = "v1";
|
|
149
|
+
readonly defaultObjectGenerationMode = "tool";
|
|
150
|
+
readonly modelId: LLMGatewayChatModelId;
|
|
151
|
+
readonly settings: LLMGatewayChatSettings;
|
|
152
|
+
private readonly config;
|
|
153
|
+
constructor(modelId: LLMGatewayChatModelId, settings: LLMGatewayChatSettings, config: LLMGatewayChatConfig);
|
|
154
|
+
get provider(): string;
|
|
155
|
+
private getArgs;
|
|
156
|
+
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<DoGenerateOutput>;
|
|
157
|
+
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<DoStreamOutput>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
type LLMGatewayCompletionConfig = {
|
|
161
|
+
provider: string;
|
|
162
|
+
compatibility: 'strict' | 'compatible';
|
|
163
|
+
headers: () => Record<string, string | undefined>;
|
|
164
|
+
url: (options: {
|
|
165
|
+
modelId: string;
|
|
166
|
+
path: string;
|
|
167
|
+
}) => string;
|
|
168
|
+
fetch?: typeof fetch;
|
|
169
|
+
extraBody?: Record<string, unknown>;
|
|
170
|
+
};
|
|
171
|
+
declare class LLMGatewayCompletionLanguageModel implements LanguageModelV1 {
|
|
172
|
+
readonly specificationVersion = "v1";
|
|
173
|
+
readonly defaultObjectGenerationMode: undefined;
|
|
174
|
+
readonly modelId: LLMGatewayCompletionModelId;
|
|
175
|
+
readonly settings: LLMGatewayCompletionSettings;
|
|
176
|
+
private readonly config;
|
|
177
|
+
constructor(modelId: LLMGatewayCompletionModelId, settings: LLMGatewayCompletionSettings, config: LLMGatewayCompletionConfig);
|
|
178
|
+
get provider(): string;
|
|
179
|
+
private getArgs;
|
|
180
|
+
doGenerate(options: Parameters<LanguageModelV1['doGenerate']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doGenerate']>>>;
|
|
181
|
+
doStream(options: Parameters<LanguageModelV1['doStream']>[0]): Promise<Awaited<ReturnType<LanguageModelV1['doStream']>>>;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
interface LLMGatewayProvider {
|
|
185
|
+
(modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
|
|
186
|
+
(modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
|
|
187
|
+
languageModel(modelId: LLMGatewayChatModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
|
|
188
|
+
languageModel(modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
|
|
189
|
+
/**
|
|
190
|
+
Creates an LLMGateway chat model for text generation.
|
|
191
|
+
*/
|
|
192
|
+
chat(modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
|
|
193
|
+
/**
|
|
194
|
+
Creates an LLMGateway completion model for text generation.
|
|
195
|
+
*/
|
|
196
|
+
completion(modelId: LLMGatewayCompletionModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
|
|
197
|
+
}
|
|
198
|
+
interface LLMGatewayProviderSettings {
|
|
199
|
+
/**
|
|
200
|
+
Base URL for the LLMGateway API calls.
|
|
201
|
+
*/
|
|
202
|
+
baseURL?: string;
|
|
203
|
+
/**
|
|
204
|
+
API key for authenticating requests.
|
|
205
|
+
*/
|
|
206
|
+
apiKey?: string;
|
|
207
|
+
/**
|
|
208
|
+
Custom headers to include in the requests.
|
|
209
|
+
*/
|
|
210
|
+
headers?: Record<string, string>;
|
|
211
|
+
/**
|
|
212
|
+
LLMGateway compatibility mode. Should be set to `strict` when using the LLMGateway API,
|
|
213
|
+
and `compatible` when using 3rd party providers. In `compatible` mode, newer
|
|
214
|
+
information such as streamOptions are not being sent. Defaults to 'compatible'.
|
|
215
|
+
*/
|
|
216
|
+
compatibility?: 'strict' | 'compatible';
|
|
217
|
+
/**
|
|
218
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
219
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
220
|
+
*/
|
|
221
|
+
fetch?: typeof fetch;
|
|
222
|
+
/**
|
|
223
|
+
A JSON object to send as the request body to access LLMGateway features & upstream provider features.
|
|
224
|
+
*/
|
|
225
|
+
extraBody?: Record<string, unknown>;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
Create an LLMGateway provider instance.
|
|
229
|
+
*/
|
|
230
|
+
declare function createLLMGateway(options?: LLMGatewayProviderSettings): LLMGatewayProvider;
|
|
231
|
+
/**
|
|
232
|
+
Default LLMGateway provider instance. It uses 'strict' compatibility mode.
|
|
233
|
+
*/
|
|
234
|
+
declare const llmgateway: LLMGatewayProvider;
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
@deprecated Use `createLLMGateway` instead.
|
|
238
|
+
*/
|
|
239
|
+
declare class LLMGateway {
|
|
240
|
+
/**
|
|
241
|
+
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
242
|
+
The default prefix is `https://api.llmgateway.io/v1`.
|
|
243
|
+
*/
|
|
244
|
+
readonly baseURL: string;
|
|
245
|
+
/**
|
|
246
|
+
API key that is being send using the `Authorization` header.
|
|
247
|
+
It defaults to the `LLMGATEWAY_API_KEY` environment variable.
|
|
248
|
+
*/
|
|
249
|
+
readonly apiKey?: string;
|
|
250
|
+
/**
|
|
251
|
+
Custom headers to include in the requests.
|
|
252
|
+
*/
|
|
253
|
+
readonly headers?: Record<string, string>;
|
|
254
|
+
/**
|
|
255
|
+
* Creates a new LLMGateway provider instance.
|
|
256
|
+
*/
|
|
257
|
+
constructor(options?: LLMGatewayProviderSettings);
|
|
258
|
+
private get baseConfig();
|
|
259
|
+
chat(modelId: LLMGatewayChatModelId, settings?: LLMGatewayChatSettings): LLMGatewayChatLanguageModel;
|
|
260
|
+
completion(modelId: LLMGatewayCompletionModelId, settings?: LLMGatewayCompletionSettings): LLMGatewayCompletionLanguageModel;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export { LLMGateway, type LLMGatewayCompletionSettings, type LLMGatewayLanguageModel, type LLMGatewayProvider, type LLMGatewayProviderOptions, type LLMGatewayProviderSettings, type LLMGatewaySharedSettings, type LLMGatewayUsageAccounting, createLLMGateway, llmgateway };
|