@friendliai/ai-provider 0.1.1

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 ADDED
@@ -0,0 +1,44 @@
1
+ # @friendliai/ai-provider
2
+
3
+ Vercel AI SDK Provider for FriendliAI
4
+
5
+ ## Installation
6
+
7
+ You can install the package via npm:
8
+
9
+ ```bash
10
+ npm i @friendliai/ai-provider
11
+ ```
12
+
13
+ ## Provider Instance
14
+
15
+ You can import the default provider instance `friendliai` from `@friendliai/ai-provider`:
16
+
17
+ ```ts
18
+ import { friendliai } from "@friendliai/ai-provider";
19
+ ```
20
+
21
+ If you need a customized setup, you can import `createFriendliAI` from `@friendliai/ai-provider` and create a provider instance with your settings:
22
+
23
+ ```ts
24
+ import { createFriendliAI } from "@friendliai/ai-provider";
25
+
26
+ const friendliai = createFriendliAI({
27
+ // custom settings
28
+ });
29
+ ```
30
+
31
+ You can use the following optional settings to customize the FriendliAI provider instance:
32
+
33
+ - **baseURL** _string_
34
+
35
+ Use a different URL prefix for API calls, e.g. to use proxy servers.
36
+ The default prefix is `https://inference.friendli.ai/v1`.
37
+
38
+ - **teamId** _string_
39
+
40
+ The team ID to use for the requests.
41
+
42
+ - **headers** _Record<string,string>_
43
+
44
+ Custom headers to include in the requests.
@@ -0,0 +1,257 @@
1
+ import { LanguageModelV1, ProviderV1 } from '@ai-sdk/provider';
2
+ import { FetchFunction } from '@ai-sdk/provider-utils';
3
+
4
+ type FriendliAIChatModelId = "meta-llama-3.1-8b-instruct" | "meta-llama-3.1-70b-instruct" | "mixtral-8x7b-instruct-v0-1" | (string & {});
5
+ interface FriendliAIChatSettings {
6
+ /**
7
+ Modify the likelihood of specified tokens appearing in the completion.
8
+
9
+ Accepts a JSON object that maps tokens (specified by their token ID in
10
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
11
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
12
+ the bias is added to the logits generated by the model prior to sampling.
13
+ The exact effect will vary per model, but values between -1 and 1 should
14
+ decrease or increase likelihood of selection; values like -100 or 100
15
+ should result in a ban or exclusive selection of the relevant token.
16
+
17
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
18
+ token from being generated.
19
+ */
20
+ logitBias?: Record<number, number>;
21
+ /**
22
+ Return the log probabilities of the tokens. Including logprobs will increase
23
+ the response size and can slow down response times. However, it can
24
+ be useful to better understand how the model is behaving.
25
+
26
+ Setting to true will return the log probabilities of the tokens that
27
+ were generated.
28
+
29
+ Setting to a number will return the log probabilities of the top n
30
+ tokens that were generated.
31
+ */
32
+ logprobs?: boolean | number;
33
+ /**
34
+ Whether to enable parallel function calling during tool use. Default to true.
35
+ */
36
+ parallelToolCalls?: boolean;
37
+ /**
38
+ Whether to use structured outputs. Defaults to false.
39
+
40
+ When enabled, tool calls and object generation will be strict and follow the provided schema.
41
+ */
42
+ structuredOutputs?: boolean;
43
+ /**
44
+ BETA FEATURE: Include the model's training loss in the response.
45
+ */
46
+ tools?: Array<{
47
+ type: "web:site" | "web:search" | "math:calendar" | "math:statistics" | "math:calculator" | "code:python-interpreter";
48
+ }>;
49
+ /**
50
+ Whether to use legacy function calling. Defaults to false.
51
+
52
+ Required by some open source inference engines which do not support the `tools` API. May also
53
+ provide a workaround for `parallelToolCalls` resulting in the provider buffering tool calls,
54
+ which causes `streamObject` to be non-streaming.
55
+
56
+ Prefer setting `parallelToolCalls: false` over this option.
57
+
58
+ @deprecated this API is supported but deprecated by FriendliAI.
59
+ */
60
+ useLegacyFunctionCalling?: boolean;
61
+ /**
62
+ A unique identifier representing your end-user, which can help FriendliAI to
63
+ monitor and detect abuse. Learn more.
64
+ */
65
+ user?: string;
66
+ }
67
+
68
+ type FriendliAIChatConfig = {
69
+ provider: string;
70
+ compatibility: "strict" | "compatible";
71
+ headers: () => Record<string, string | undefined>;
72
+ url: (options: {
73
+ modelId: string;
74
+ path: string;
75
+ }) => string;
76
+ fetch?: FetchFunction;
77
+ };
78
+ declare class FriendliAIChatLanguageModel implements LanguageModelV1 {
79
+ readonly specificationVersion = "v1";
80
+ readonly modelId: FriendliAIChatModelId;
81
+ readonly settings: FriendliAIChatSettings;
82
+ private readonly config;
83
+ constructor(modelId: FriendliAIChatModelId, settings: FriendliAIChatSettings, config: FriendliAIChatConfig);
84
+ get supportsStructuredOutputs(): boolean;
85
+ get defaultObjectGenerationMode(): "tool" | "json";
86
+ get provider(): string;
87
+ private getArgs;
88
+ doGenerate(options: Parameters<LanguageModelV1["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doGenerate"]>>>;
89
+ doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
90
+ }
91
+
92
+ type FriendliAICompletionModelId = "meta-llama-3.1-70b-instruct" | "meta-llama-3.1-8b-instruct" | "mixtral-8x7b-instruct-v0-1" | (string & {});
93
+ interface FriendliAICompletionSettings {
94
+ /**
95
+ Echo back the prompt in addition to the completion.
96
+ */
97
+ echo?: boolean;
98
+ /**
99
+ Modify the likelihood of specified tokens appearing in the completion.
100
+
101
+ Accepts a JSON object that maps tokens (specified by their token ID in
102
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
103
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
104
+ the bias is added to the logits generated by the model prior to sampling.
105
+ The exact effect will vary per model, but values between -1 and 1 should
106
+ decrease or increase likelihood of selection; values like -100 or 100
107
+ should result in a ban or exclusive selection of the relevant token.
108
+
109
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
110
+ token from being generated.
111
+ */
112
+ logitBias?: Record<number, number>;
113
+ /**
114
+ Return the log probabilities of the tokens. Including logprobs will increase
115
+ the response size and can slow down response times. However, it can
116
+ be useful to better understand how the model is behaving.
117
+
118
+ Setting to true will return the log probabilities of the tokens that
119
+ were generated.
120
+
121
+ Setting to a number will return the log probabilities of the top n
122
+ tokens that were generated.
123
+ */
124
+ logprobs?: boolean | number;
125
+ /**
126
+ The suffix that comes after a completion of inserted text.
127
+ */
128
+ suffix?: string;
129
+ /**
130
+ A unique identifier representing your end-user, which can help FriendliAI to
131
+ monitor and detect abuse. Learn more.
132
+ */
133
+ user?: string;
134
+ }
135
+
136
+ type FriendliAICompletionConfig = {
137
+ provider: string;
138
+ compatibility: "strict" | "compatible";
139
+ headers: () => Record<string, string | undefined>;
140
+ url: (options: {
141
+ modelId: string;
142
+ path: string;
143
+ }) => string;
144
+ fetch?: FetchFunction;
145
+ };
146
+ declare class FriendliAICompletionLanguageModel implements LanguageModelV1 {
147
+ readonly specificationVersion = "v1";
148
+ readonly defaultObjectGenerationMode: undefined;
149
+ readonly modelId: FriendliAICompletionModelId;
150
+ readonly settings: FriendliAICompletionSettings;
151
+ private readonly config;
152
+ constructor(modelId: FriendliAICompletionModelId, settings: FriendliAICompletionSettings, config: FriendliAICompletionConfig);
153
+ get provider(): string;
154
+ private getArgs;
155
+ doGenerate(options: Parameters<LanguageModelV1["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doGenerate"]>>>;
156
+ doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
157
+ }
158
+
159
+ interface FriendliAIProvider extends ProviderV1 {
160
+ (modelId: "meta-llama-3.1-8b-instruct", settings?: FriendliAICompletionSettings): FriendliAICompletionLanguageModel;
161
+ (modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
162
+ /**
163
+ Creates an FriendliAI model for text generation.
164
+ */
165
+ languageModel(modelId: "meta-llama-3.1-8b-instruct", settings?: FriendliAICompletionSettings): FriendliAICompletionLanguageModel;
166
+ languageModel(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
167
+ /**
168
+ Creates an FriendliAI chat model for text generation.
169
+ */
170
+ chat(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
171
+ /**
172
+ Creates an FriendliAI completion model for text generation.
173
+ */
174
+ completion(modelId: FriendliAICompletionModelId, settings?: FriendliAICompletionSettings): LanguageModelV1;
175
+ }
176
+ interface FriendliAIProviderSettings {
177
+ /**
178
+ Base URL for the FriendliAI API calls.
179
+ */
180
+ baseURL?: string;
181
+ /**
182
+ @deprecated Use `baseURL` instead.
183
+ */
184
+ baseUrl?: string;
185
+ /**
186
+ API key for authenticating requests.
187
+ */
188
+ apiKey?: string;
189
+ /**
190
+ FriendliAI Team ID.
191
+ */
192
+ teamId?: string;
193
+ /**
194
+ FriendliAI project.
195
+ */
196
+ project?: string;
197
+ /**
198
+ Custom headers to include in the requests.
199
+ */
200
+ headers?: Record<string, string>;
201
+ /**
202
+ FriendliAI compatibility mode. Should be set to `strict` when using the FriendliAI API,
203
+ and `compatible` when using 3rd party providers. In `compatible` mode, newer
204
+ information such as streamOptions are not being sent. Defaults to 'compatible'.
205
+ */
206
+ compatibility?: "strict" | "compatible";
207
+ /**
208
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
209
+ or to provide a custom fetch implementation for e.g. testing.
210
+ */
211
+ fetch?: FetchFunction;
212
+ }
213
+ /**
214
+ Create an FriendliAI provider instance.
215
+ */
216
+ declare function createFriendliAI(options?: FriendliAIProviderSettings): FriendliAIProvider;
217
+ /**
218
+ Default FriendliAI provider instance. It uses 'strict' compatibility mode.
219
+ */
220
+ declare const friendliai: FriendliAIProvider;
221
+
222
+ /**
223
+ @deprecated Use `createFriendliAI` instead.
224
+ */
225
+ declare class FriendliAI {
226
+ /**
227
+ Use a different URL prefix for API calls, e.g. to use proxy servers.
228
+ The default prefix is `https://api.friendliai.com/v1`.
229
+ */
230
+ readonly baseURL: string;
231
+ /**
232
+ API key that is being send using the `Authorization` header.
233
+ It defaults to the `FRIEDNLI_API_KEY` environment variable.
234
+ */
235
+ readonly apiKey?: string;
236
+ /**
237
+ FriendliAI Team ID.
238
+ */
239
+ teamId?: string;
240
+ /**
241
+ FriendliAI project.
242
+ */
243
+ readonly project?: string;
244
+ /**
245
+ Custom headers to include in the requests.
246
+ */
247
+ readonly headers?: Record<string, string>;
248
+ /**
249
+ * Creates a new FriendliAI provider instance.
250
+ */
251
+ constructor(options?: FriendliAIProviderSettings);
252
+ private get baseConfig();
253
+ chat(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): FriendliAIChatLanguageModel;
254
+ completion(modelId: FriendliAICompletionModelId, settings?: FriendliAICompletionSettings): FriendliAICompletionLanguageModel;
255
+ }
256
+
257
+ export { FriendliAI, type FriendliAIProvider, type FriendliAIProviderSettings, createFriendliAI, friendliai };
@@ -0,0 +1,257 @@
1
+ import { LanguageModelV1, ProviderV1 } from '@ai-sdk/provider';
2
+ import { FetchFunction } from '@ai-sdk/provider-utils';
3
+
4
+ type FriendliAIChatModelId = "meta-llama-3.1-8b-instruct" | "meta-llama-3.1-70b-instruct" | "mixtral-8x7b-instruct-v0-1" | (string & {});
5
+ interface FriendliAIChatSettings {
6
+ /**
7
+ Modify the likelihood of specified tokens appearing in the completion.
8
+
9
+ Accepts a JSON object that maps tokens (specified by their token ID in
10
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
11
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
12
+ the bias is added to the logits generated by the model prior to sampling.
13
+ The exact effect will vary per model, but values between -1 and 1 should
14
+ decrease or increase likelihood of selection; values like -100 or 100
15
+ should result in a ban or exclusive selection of the relevant token.
16
+
17
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
18
+ token from being generated.
19
+ */
20
+ logitBias?: Record<number, number>;
21
+ /**
22
+ Return the log probabilities of the tokens. Including logprobs will increase
23
+ the response size and can slow down response times. However, it can
24
+ be useful to better understand how the model is behaving.
25
+
26
+ Setting to true will return the log probabilities of the tokens that
27
+ were generated.
28
+
29
+ Setting to a number will return the log probabilities of the top n
30
+ tokens that were generated.
31
+ */
32
+ logprobs?: boolean | number;
33
+ /**
34
+ Whether to enable parallel function calling during tool use. Default to true.
35
+ */
36
+ parallelToolCalls?: boolean;
37
+ /**
38
+ Whether to use structured outputs. Defaults to false.
39
+
40
+ When enabled, tool calls and object generation will be strict and follow the provided schema.
41
+ */
42
+ structuredOutputs?: boolean;
43
+ /**
44
+ BETA FEATURE: Include the model's training loss in the response.
45
+ */
46
+ tools?: Array<{
47
+ type: "web:site" | "web:search" | "math:calendar" | "math:statistics" | "math:calculator" | "code:python-interpreter";
48
+ }>;
49
+ /**
50
+ Whether to use legacy function calling. Defaults to false.
51
+
52
+ Required by some open source inference engines which do not support the `tools` API. May also
53
+ provide a workaround for `parallelToolCalls` resulting in the provider buffering tool calls,
54
+ which causes `streamObject` to be non-streaming.
55
+
56
+ Prefer setting `parallelToolCalls: false` over this option.
57
+
58
+ @deprecated this API is supported but deprecated by FriendliAI.
59
+ */
60
+ useLegacyFunctionCalling?: boolean;
61
+ /**
62
+ A unique identifier representing your end-user, which can help FriendliAI to
63
+ monitor and detect abuse. Learn more.
64
+ */
65
+ user?: string;
66
+ }
67
+
68
+ type FriendliAIChatConfig = {
69
+ provider: string;
70
+ compatibility: "strict" | "compatible";
71
+ headers: () => Record<string, string | undefined>;
72
+ url: (options: {
73
+ modelId: string;
74
+ path: string;
75
+ }) => string;
76
+ fetch?: FetchFunction;
77
+ };
78
+ declare class FriendliAIChatLanguageModel implements LanguageModelV1 {
79
+ readonly specificationVersion = "v1";
80
+ readonly modelId: FriendliAIChatModelId;
81
+ readonly settings: FriendliAIChatSettings;
82
+ private readonly config;
83
+ constructor(modelId: FriendliAIChatModelId, settings: FriendliAIChatSettings, config: FriendliAIChatConfig);
84
+ get supportsStructuredOutputs(): boolean;
85
+ get defaultObjectGenerationMode(): "tool" | "json";
86
+ get provider(): string;
87
+ private getArgs;
88
+ doGenerate(options: Parameters<LanguageModelV1["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doGenerate"]>>>;
89
+ doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
90
+ }
91
+
92
+ type FriendliAICompletionModelId = "meta-llama-3.1-70b-instruct" | "meta-llama-3.1-8b-instruct" | "mixtral-8x7b-instruct-v0-1" | (string & {});
93
+ interface FriendliAICompletionSettings {
94
+ /**
95
+ Echo back the prompt in addition to the completion.
96
+ */
97
+ echo?: boolean;
98
+ /**
99
+ Modify the likelihood of specified tokens appearing in the completion.
100
+
101
+ Accepts a JSON object that maps tokens (specified by their token ID in
102
+ the GPT tokenizer) to an associated bias value from -100 to 100. You
103
+ can use this tokenizer tool to convert text to token IDs. Mathematically,
104
+ the bias is added to the logits generated by the model prior to sampling.
105
+ The exact effect will vary per model, but values between -1 and 1 should
106
+ decrease or increase likelihood of selection; values like -100 or 100
107
+ should result in a ban or exclusive selection of the relevant token.
108
+
109
+ As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
110
+ token from being generated.
111
+ */
112
+ logitBias?: Record<number, number>;
113
+ /**
114
+ Return the log probabilities of the tokens. Including logprobs will increase
115
+ the response size and can slow down response times. However, it can
116
+ be useful to better understand how the model is behaving.
117
+
118
+ Setting to true will return the log probabilities of the tokens that
119
+ were generated.
120
+
121
+ Setting to a number will return the log probabilities of the top n
122
+ tokens that were generated.
123
+ */
124
+ logprobs?: boolean | number;
125
+ /**
126
+ The suffix that comes after a completion of inserted text.
127
+ */
128
+ suffix?: string;
129
+ /**
130
+ A unique identifier representing your end-user, which can help FriendliAI to
131
+ monitor and detect abuse. Learn more.
132
+ */
133
+ user?: string;
134
+ }
135
+
136
+ type FriendliAICompletionConfig = {
137
+ provider: string;
138
+ compatibility: "strict" | "compatible";
139
+ headers: () => Record<string, string | undefined>;
140
+ url: (options: {
141
+ modelId: string;
142
+ path: string;
143
+ }) => string;
144
+ fetch?: FetchFunction;
145
+ };
146
+ declare class FriendliAICompletionLanguageModel implements LanguageModelV1 {
147
+ readonly specificationVersion = "v1";
148
+ readonly defaultObjectGenerationMode: undefined;
149
+ readonly modelId: FriendliAICompletionModelId;
150
+ readonly settings: FriendliAICompletionSettings;
151
+ private readonly config;
152
+ constructor(modelId: FriendliAICompletionModelId, settings: FriendliAICompletionSettings, config: FriendliAICompletionConfig);
153
+ get provider(): string;
154
+ private getArgs;
155
+ doGenerate(options: Parameters<LanguageModelV1["doGenerate"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doGenerate"]>>>;
156
+ doStream(options: Parameters<LanguageModelV1["doStream"]>[0]): Promise<Awaited<ReturnType<LanguageModelV1["doStream"]>>>;
157
+ }
158
+
159
+ interface FriendliAIProvider extends ProviderV1 {
160
+ (modelId: "meta-llama-3.1-8b-instruct", settings?: FriendliAICompletionSettings): FriendliAICompletionLanguageModel;
161
+ (modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
162
+ /**
163
+ Creates an FriendliAI model for text generation.
164
+ */
165
+ languageModel(modelId: "meta-llama-3.1-8b-instruct", settings?: FriendliAICompletionSettings): FriendliAICompletionLanguageModel;
166
+ languageModel(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
167
+ /**
168
+ Creates an FriendliAI chat model for text generation.
169
+ */
170
+ chat(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
171
+ /**
172
+ Creates an FriendliAI completion model for text generation.
173
+ */
174
+ completion(modelId: FriendliAICompletionModelId, settings?: FriendliAICompletionSettings): LanguageModelV1;
175
+ }
176
+ interface FriendliAIProviderSettings {
177
+ /**
178
+ Base URL for the FriendliAI API calls.
179
+ */
180
+ baseURL?: string;
181
+ /**
182
+ @deprecated Use `baseURL` instead.
183
+ */
184
+ baseUrl?: string;
185
+ /**
186
+ API key for authenticating requests.
187
+ */
188
+ apiKey?: string;
189
+ /**
190
+ FriendliAI Team ID.
191
+ */
192
+ teamId?: string;
193
+ /**
194
+ FriendliAI project.
195
+ */
196
+ project?: string;
197
+ /**
198
+ Custom headers to include in the requests.
199
+ */
200
+ headers?: Record<string, string>;
201
+ /**
202
+ FriendliAI compatibility mode. Should be set to `strict` when using the FriendliAI API,
203
+ and `compatible` when using 3rd party providers. In `compatible` mode, newer
204
+ information such as streamOptions are not being sent. Defaults to 'compatible'.
205
+ */
206
+ compatibility?: "strict" | "compatible";
207
+ /**
208
+ Custom fetch implementation. You can use it as a middleware to intercept requests,
209
+ or to provide a custom fetch implementation for e.g. testing.
210
+ */
211
+ fetch?: FetchFunction;
212
+ }
213
+ /**
214
+ Create an FriendliAI provider instance.
215
+ */
216
+ declare function createFriendliAI(options?: FriendliAIProviderSettings): FriendliAIProvider;
217
+ /**
218
+ Default FriendliAI provider instance. It uses 'strict' compatibility mode.
219
+ */
220
+ declare const friendliai: FriendliAIProvider;
221
+
222
+ /**
223
+ @deprecated Use `createFriendliAI` instead.
224
+ */
225
+ declare class FriendliAI {
226
+ /**
227
+ Use a different URL prefix for API calls, e.g. to use proxy servers.
228
+ The default prefix is `https://api.friendliai.com/v1`.
229
+ */
230
+ readonly baseURL: string;
231
+ /**
232
+ API key that is being send using the `Authorization` header.
233
+ It defaults to the `FRIEDNLI_API_KEY` environment variable.
234
+ */
235
+ readonly apiKey?: string;
236
+ /**
237
+ FriendliAI Team ID.
238
+ */
239
+ teamId?: string;
240
+ /**
241
+ FriendliAI project.
242
+ */
243
+ readonly project?: string;
244
+ /**
245
+ Custom headers to include in the requests.
246
+ */
247
+ readonly headers?: Record<string, string>;
248
+ /**
249
+ * Creates a new FriendliAI provider instance.
250
+ */
251
+ constructor(options?: FriendliAIProviderSettings);
252
+ private get baseConfig();
253
+ chat(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): FriendliAIChatLanguageModel;
254
+ completion(modelId: FriendliAICompletionModelId, settings?: FriendliAICompletionSettings): FriendliAICompletionLanguageModel;
255
+ }
256
+
257
+ export { FriendliAI, type FriendliAIProvider, type FriendliAIProviderSettings, createFriendliAI, friendliai };