@friendliai/ai-provider 0.1.25 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @friendliai/ai-provider
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - edc5931: fix parallel tool call
8
+
9
+ ## 0.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - f262011: convert-openai-compatible-components
14
+
15
+ - dedicated, serverless automatic switching
16
+ - /v1/completion available
17
+ - Improved error parsing logic
18
+ - Update dependency packages
19
+ - Liquidate some of the legacy
20
+ - Other minor bug fixes
21
+
22
+ ### Patch Changes
23
+
24
+ - bcdf26e: Convert regex input to RegExp type
25
+
3
26
  ## 0.1.25
4
27
 
5
28
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,115 +1,100 @@
1
- import { ProviderV1, LanguageModelV1 } from '@ai-sdk/provider';
1
+ import { LanguageModelV1 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
+ import { OpenAICompatibleChatSettings } from '@ai-sdk/openai-compatible';
4
+ import { z } from 'zod';
3
5
 
4
- type FriendliAIChatModelId = "meta-llama-3.1-8b-instruct" | "meta-llama-3.1-70b-instruct" | "mixtral-8x7b-instruct-v0-1" | "exaone-3.5-7.8b-instruct" | "exaone-3.5-32b-instruct" | (string & {});
6
+ declare const FriendliAIServerlessModelIds: readonly ["meta-llama-3.1-8b-instruct", "meta-llama-3.1-70b-instruct", "mixtral-8x7b-instruct-v0-1"];
7
+ type FriendliAIServerlessModelId = (typeof FriendliAIServerlessModelIds)[number];
8
+ type FriendliAILanguageModelId = FriendliAIServerlessModelId | (string & {});
5
9
  type FriendliAIBetaChatModelId = "llama-3.2-11b-vision-instruct" | (string & {});
6
- interface FriendliAIChatSettings {
10
+ interface FriendliAISharedSettings {
7
11
  /**
8
- Modify the likelihood of specified tokens appearing in the completion.
9
-
10
- Accepts a JSON object that maps tokens (specified by their token ID in
11
- the GPT tokenizer) to an associated bias value from -100 to 100. You
12
- can use this tokenizer tool to convert text to token IDs. Mathematically,
13
- the bias is added to the logits generated by the model prior to sampling.
14
- The exact effect will vary per model, but values between -1 and 1 should
15
- decrease or increase likelihood of selection; values like -100 or 100
16
- should result in a ban or exclusive selection of the relevant token.
17
-
18
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
19
- token from being generated.
20
- */
21
- logitBias?: Record<number, number>;
22
- /**
23
- Return the log probabilities of the tokens. Including logprobs will increase
24
- the response size and can slow down response times. However, it can
25
- be useful to better understand how the model is behaving.
26
-
27
- Setting to true will return the log probabilities of the tokens that
28
- were generated.
29
-
30
- Setting to a number will return the log probabilities of the top n
31
- tokens that were generated.
32
- */
33
- logprobs?: boolean | number;
34
- /**
35
- Whether to enable parallel function calling during tool use. Default to true.
12
+ * Sets the endpoint to which the request will be sent.
13
+ * auto: automatically selected based on model_id
14
+ * dedicated: Fixed to "/dedicated/v1"
15
+ * serverless: automatically selected as one of "/serverless/beta", "/serverless/v1", or "/serverless/tools/v1"
16
+ * Ignored if baseURL is specified.
36
17
  */
37
- parallelToolCalls?: boolean;
38
- /**
39
- Whether to use structured outputs. Defaults to false.
40
-
41
- When enabled, tool calls and object generation will be strict and follow the provided schema.
42
- */
43
- structuredOutputs?: boolean;
18
+ endpoint?: "auto" | "dedicated" | "serverless";
19
+ }
20
+ interface FriendliAIChatSettings extends FriendliAISharedSettings, OpenAICompatibleChatSettings {
44
21
  /**
45
- BETA FEATURE: Include the model's training loss in the response.
22
+ * BETA FEATURE: Include the model's training loss in the response.
46
23
  */
47
24
  tools?: Array<{
48
25
  type: "web:url" | "web:search" | "math:calendar" | "math:statistics" | "math:calculator" | "code:python-interpreter";
49
- } | {
50
- type: "file:text";
51
- files: Array<string>;
52
26
  }>;
53
27
  /**
54
- BETA FEATURE: You can write a regular expression to force output that satisfies that regular expression.
28
+ * Whether to enable parallel function calling during tool use. Default to true.
55
29
  */
56
- regex?: string;
30
+ parallelToolCalls?: boolean;
57
31
  /**
58
- A unique identifier representing your end-user, which can help FriendliAI to
59
- monitor and detect abuse. Learn more.
60
- */
61
- user?: string;
32
+ * BETA FEATURE: You can write a regular expression to force output that satisfies that regular expression.
33
+ */
34
+ regex?: RegExp;
62
35
  }
63
36
 
64
- interface FriendliAIProvider extends ProviderV1 {
65
- (modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
37
+ interface FriendliAIProviderSettings {
66
38
  /**
67
- * Creates an FriendliAI model for text generation.
39
+ * FriendliAI API key. (FRIENDLI__TOKEN)
68
40
  */
69
- languageModel(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
70
- chat(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
71
- serverless(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
72
- dedicated(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
41
+ apiKey?: string;
73
42
  /**
74
- * A model that has not yet been officially released
43
+ * Base URL for the API calls.
75
44
  */
76
- beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
77
- }
78
- interface FriendliAIProviderSettings {
79
- /**
80
- Base URL for the FriendliAI API calls.
81
- */
82
45
  baseURL?: string;
83
46
  /**
84
- API key for authenticating requests.
85
- */
86
- apiKey?: string;
47
+ * Custom headers to include in the requests.
48
+ */
49
+ headers?: Record<string, string>;
87
50
  /**
88
- FriendliAI Team ID.
51
+ * FriendliAI Team ID.
89
52
  */
90
53
  teamId?: string;
91
54
  /**
92
- Custom headers to include in the requests.
93
- */
94
- headers?: Record<string, string>;
95
- /**
96
- Custom fetch implementation. You can use it as a middleware to intercept requests,
97
- or to provide a custom fetch implementation for e.g. testing.
98
- */
55
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
56
+ * or to provide a custom fetch implementation for e.g. testing.
57
+ */
99
58
  fetch?: FetchFunction;
100
59
  }
60
+ interface FriendliAIProvider {
61
+ /**
62
+ * Creates a model for text generation.
63
+ */
64
+ (modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
65
+ /**
66
+ * A model that has not yet been officially released
67
+ */
68
+ beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
69
+ /**
70
+ * Creates a chat model for text generation.
71
+ */
72
+ chat(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
73
+ chatModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
74
+ /**
75
+ * Creates a completion model for text generation.
76
+ */
77
+ completion(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
78
+ completionModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
79
+ /**
80
+ * Creates a text embedding model for text generation.
81
+ */
82
+ embedding(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
83
+ textEmbeddingModel(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
84
+ }
101
85
  /**
102
86
  Create an FriendliAI provider instance.
103
87
  */
104
88
  declare function createFriendli(options?: FriendliAIProviderSettings): FriendliAIProvider;
105
89
  declare const friendli: FriendliAIProvider;
106
- /**
107
- * @deprecated Use `friendli` instead.
108
- */
109
- declare const friendliai: FriendliAIProvider;
110
- /**
111
- * @deprecated Use `createFriendli` instead.
112
- */
113
- declare const createFriendliAI: typeof createFriendli;
114
90
 
115
- export { type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, createFriendliAI, friendli, friendliai };
91
+ declare const friendliaiErrorSchema: z.ZodObject<{
92
+ message: z.ZodString;
93
+ }, "strip", z.ZodTypeAny, {
94
+ message: string;
95
+ }, {
96
+ message: string;
97
+ }>;
98
+ type FriendliAIErrorData = z.infer<typeof friendliaiErrorSchema>;
99
+
100
+ export { type FriendliAIErrorData, type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, friendli };
package/dist/index.d.ts CHANGED
@@ -1,115 +1,100 @@
1
- import { ProviderV1, LanguageModelV1 } from '@ai-sdk/provider';
1
+ import { LanguageModelV1 } from '@ai-sdk/provider';
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
+ import { OpenAICompatibleChatSettings } from '@ai-sdk/openai-compatible';
4
+ import { z } from 'zod';
3
5
 
4
- type FriendliAIChatModelId = "meta-llama-3.1-8b-instruct" | "meta-llama-3.1-70b-instruct" | "mixtral-8x7b-instruct-v0-1" | "exaone-3.5-7.8b-instruct" | "exaone-3.5-32b-instruct" | (string & {});
6
+ declare const FriendliAIServerlessModelIds: readonly ["meta-llama-3.1-8b-instruct", "meta-llama-3.1-70b-instruct", "mixtral-8x7b-instruct-v0-1"];
7
+ type FriendliAIServerlessModelId = (typeof FriendliAIServerlessModelIds)[number];
8
+ type FriendliAILanguageModelId = FriendliAIServerlessModelId | (string & {});
5
9
  type FriendliAIBetaChatModelId = "llama-3.2-11b-vision-instruct" | (string & {});
6
- interface FriendliAIChatSettings {
10
+ interface FriendliAISharedSettings {
7
11
  /**
8
- Modify the likelihood of specified tokens appearing in the completion.
9
-
10
- Accepts a JSON object that maps tokens (specified by their token ID in
11
- the GPT tokenizer) to an associated bias value from -100 to 100. You
12
- can use this tokenizer tool to convert text to token IDs. Mathematically,
13
- the bias is added to the logits generated by the model prior to sampling.
14
- The exact effect will vary per model, but values between -1 and 1 should
15
- decrease or increase likelihood of selection; values like -100 or 100
16
- should result in a ban or exclusive selection of the relevant token.
17
-
18
- As an example, you can pass {"50256": -100} to prevent the <|endoftext|>
19
- token from being generated.
20
- */
21
- logitBias?: Record<number, number>;
22
- /**
23
- Return the log probabilities of the tokens. Including logprobs will increase
24
- the response size and can slow down response times. However, it can
25
- be useful to better understand how the model is behaving.
26
-
27
- Setting to true will return the log probabilities of the tokens that
28
- were generated.
29
-
30
- Setting to a number will return the log probabilities of the top n
31
- tokens that were generated.
32
- */
33
- logprobs?: boolean | number;
34
- /**
35
- Whether to enable parallel function calling during tool use. Default to true.
12
+ * Sets the endpoint to which the request will be sent.
13
+ * auto: automatically selected based on model_id
14
+ * dedicated: Fixed to "/dedicated/v1"
15
+ * serverless: automatically selected as one of "/serverless/beta", "/serverless/v1", or "/serverless/tools/v1"
16
+ * Ignored if baseURL is specified.
36
17
  */
37
- parallelToolCalls?: boolean;
38
- /**
39
- Whether to use structured outputs. Defaults to false.
40
-
41
- When enabled, tool calls and object generation will be strict and follow the provided schema.
42
- */
43
- structuredOutputs?: boolean;
18
+ endpoint?: "auto" | "dedicated" | "serverless";
19
+ }
20
+ interface FriendliAIChatSettings extends FriendliAISharedSettings, OpenAICompatibleChatSettings {
44
21
  /**
45
- BETA FEATURE: Include the model's training loss in the response.
22
+ * BETA FEATURE: Include the model's training loss in the response.
46
23
  */
47
24
  tools?: Array<{
48
25
  type: "web:url" | "web:search" | "math:calendar" | "math:statistics" | "math:calculator" | "code:python-interpreter";
49
- } | {
50
- type: "file:text";
51
- files: Array<string>;
52
26
  }>;
53
27
  /**
54
- BETA FEATURE: You can write a regular expression to force output that satisfies that regular expression.
28
+ * Whether to enable parallel function calling during tool use. Default to true.
55
29
  */
56
- regex?: string;
30
+ parallelToolCalls?: boolean;
57
31
  /**
58
- A unique identifier representing your end-user, which can help FriendliAI to
59
- monitor and detect abuse. Learn more.
60
- */
61
- user?: string;
32
+ * BETA FEATURE: You can write a regular expression to force output that satisfies that regular expression.
33
+ */
34
+ regex?: RegExp;
62
35
  }
63
36
 
64
- interface FriendliAIProvider extends ProviderV1 {
65
- (modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
37
+ interface FriendliAIProviderSettings {
66
38
  /**
67
- * Creates an FriendliAI model for text generation.
39
+ * FriendliAI API key. (FRIENDLI__TOKEN)
68
40
  */
69
- languageModel(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
70
- chat(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
71
- serverless(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
72
- dedicated(modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
41
+ apiKey?: string;
73
42
  /**
74
- * A model that has not yet been officially released
43
+ * Base URL for the API calls.
75
44
  */
76
- beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
77
- }
78
- interface FriendliAIProviderSettings {
79
- /**
80
- Base URL for the FriendliAI API calls.
81
- */
82
45
  baseURL?: string;
83
46
  /**
84
- API key for authenticating requests.
85
- */
86
- apiKey?: string;
47
+ * Custom headers to include in the requests.
48
+ */
49
+ headers?: Record<string, string>;
87
50
  /**
88
- FriendliAI Team ID.
51
+ * FriendliAI Team ID.
89
52
  */
90
53
  teamId?: string;
91
54
  /**
92
- Custom headers to include in the requests.
93
- */
94
- headers?: Record<string, string>;
95
- /**
96
- Custom fetch implementation. You can use it as a middleware to intercept requests,
97
- or to provide a custom fetch implementation for e.g. testing.
98
- */
55
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
56
+ * or to provide a custom fetch implementation for e.g. testing.
57
+ */
99
58
  fetch?: FetchFunction;
100
59
  }
60
+ interface FriendliAIProvider {
61
+ /**
62
+ * Creates a model for text generation.
63
+ */
64
+ (modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
65
+ /**
66
+ * A model that has not yet been officially released
67
+ */
68
+ beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
69
+ /**
70
+ * Creates a chat model for text generation.
71
+ */
72
+ chat(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
73
+ chatModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
74
+ /**
75
+ * Creates a completion model for text generation.
76
+ */
77
+ completion(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
78
+ completionModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
79
+ /**
80
+ * Creates a text embedding model for text generation.
81
+ */
82
+ embedding(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
83
+ textEmbeddingModel(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
84
+ }
101
85
  /**
102
86
  Create an FriendliAI provider instance.
103
87
  */
104
88
  declare function createFriendli(options?: FriendliAIProviderSettings): FriendliAIProvider;
105
89
  declare const friendli: FriendliAIProvider;
106
- /**
107
- * @deprecated Use `friendli` instead.
108
- */
109
- declare const friendliai: FriendliAIProvider;
110
- /**
111
- * @deprecated Use `createFriendli` instead.
112
- */
113
- declare const createFriendliAI: typeof createFriendli;
114
90
 
115
- export { type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, createFriendliAI, friendli, friendliai };
91
+ declare const friendliaiErrorSchema: z.ZodObject<{
92
+ message: z.ZodString;
93
+ }, "strip", z.ZodTypeAny, {
94
+ message: string;
95
+ }, {
96
+ message: string;
97
+ }>;
98
+ type FriendliAIErrorData = z.infer<typeof friendliaiErrorSchema>;
99
+
100
+ export { type FriendliAIErrorData, type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, friendli };