@friendliai/ai-provider 0.1.24 → 0.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @friendliai/ai-provider
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - f262011: convert-openai-compatible-components
8
+
9
+ - dedicated, serverless automatic switching
10
+ - /v1/completion available
11
+ - Improved error parsing logic
12
+ - Update dependency packages
13
+ - Liquidate some of the legacy
14
+ - Other minor bug fixes
15
+
16
+ ### Patch Changes
17
+
18
+ - bcdf26e: Convert regex input to RegExp type
19
+
20
+ ## 0.1.25
21
+
22
+ ### Patch Changes
23
+
24
+ - 894764d: fix model list
25
+
3
26
  ## 0.1.24
4
27
 
5
28
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,115 +1,96 @@
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" | (string & {});
5
- type FriendliAIBetaChatModelId = "llama-3.2-11b-vision-instruct" | "exaone-3.5-7.8b-instruct" | "exaone-3.5-32b-instruct" | (string & {});
6
- interface FriendliAIChatSettings {
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 & {});
9
+ type FriendliAIBetaChatModelId = "llama-3.2-11b-vision-instruct" | (string & {});
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
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.
55
- */
56
- regex?: string;
57
- /**
58
- A unique identifier representing your end-user, which can help FriendliAI to
59
- monitor and detect abuse. Learn more.
60
- */
61
- user?: string;
28
+ BETA FEATURE: You can write a regular expression to force output that satisfies that regular expression.
29
+ */
30
+ regex?: RegExp;
62
31
  }
63
32
 
64
- interface FriendliAIProvider extends ProviderV1 {
65
- (modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
33
+ interface FriendliAIProviderSettings {
66
34
  /**
67
- * Creates an FriendliAI model for text generation.
35
+ * FriendliAI API key. (FRIENDLI__TOKEN)
68
36
  */
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;
37
+ apiKey?: string;
73
38
  /**
74
- * A model that has not yet been officially released
39
+ * Base URL for the API calls.
75
40
  */
76
- beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
77
- }
78
- interface FriendliAIProviderSettings {
79
- /**
80
- Base URL for the FriendliAI API calls.
81
- */
82
41
  baseURL?: string;
83
42
  /**
84
- API key for authenticating requests.
85
- */
86
- apiKey?: string;
43
+ * Custom headers to include in the requests.
44
+ */
45
+ headers?: Record<string, string>;
87
46
  /**
88
- FriendliAI Team ID.
47
+ * FriendliAI Team ID.
89
48
  */
90
49
  teamId?: string;
91
50
  /**
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
- */
51
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
52
+ * or to provide a custom fetch implementation for e.g. testing.
53
+ */
99
54
  fetch?: FetchFunction;
100
55
  }
56
+ interface FriendliAIProvider {
57
+ /**
58
+ * Creates a model for text generation.
59
+ */
60
+ (modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
61
+ /**
62
+ * A model that has not yet been officially released
63
+ */
64
+ beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
65
+ /**
66
+ * Creates a chat model for text generation.
67
+ */
68
+ chat(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
69
+ chatModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
70
+ /**
71
+ * Creates a completion model for text generation.
72
+ */
73
+ completion(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
74
+ completionModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
75
+ /**
76
+ * Creates a text embedding model for text generation.
77
+ */
78
+ embedding(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
79
+ textEmbeddingModel(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
80
+ }
101
81
  /**
102
82
  Create an FriendliAI provider instance.
103
83
  */
104
84
  declare function createFriendli(options?: FriendliAIProviderSettings): FriendliAIProvider;
105
85
  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
86
 
115
- export { type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, createFriendliAI, friendli, friendliai };
87
+ declare const friendliaiErrorSchema: z.ZodObject<{
88
+ message: z.ZodString;
89
+ }, "strip", z.ZodTypeAny, {
90
+ message: string;
91
+ }, {
92
+ message: string;
93
+ }>;
94
+ type FriendliAIErrorData = z.infer<typeof friendliaiErrorSchema>;
95
+
96
+ export { type FriendliAIErrorData, type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, friendli };
package/dist/index.d.ts CHANGED
@@ -1,115 +1,96 @@
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" | (string & {});
5
- type FriendliAIBetaChatModelId = "llama-3.2-11b-vision-instruct" | "exaone-3.5-7.8b-instruct" | "exaone-3.5-32b-instruct" | (string & {});
6
- interface FriendliAIChatSettings {
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 & {});
9
+ type FriendliAIBetaChatModelId = "llama-3.2-11b-vision-instruct" | (string & {});
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
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.
55
- */
56
- regex?: string;
57
- /**
58
- A unique identifier representing your end-user, which can help FriendliAI to
59
- monitor and detect abuse. Learn more.
60
- */
61
- user?: string;
28
+ BETA FEATURE: You can write a regular expression to force output that satisfies that regular expression.
29
+ */
30
+ regex?: RegExp;
62
31
  }
63
32
 
64
- interface FriendliAIProvider extends ProviderV1 {
65
- (modelId: FriendliAIChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
33
+ interface FriendliAIProviderSettings {
66
34
  /**
67
- * Creates an FriendliAI model for text generation.
35
+ * FriendliAI API key. (FRIENDLI__TOKEN)
68
36
  */
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;
37
+ apiKey?: string;
73
38
  /**
74
- * A model that has not yet been officially released
39
+ * Base URL for the API calls.
75
40
  */
76
- beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
77
- }
78
- interface FriendliAIProviderSettings {
79
- /**
80
- Base URL for the FriendliAI API calls.
81
- */
82
41
  baseURL?: string;
83
42
  /**
84
- API key for authenticating requests.
85
- */
86
- apiKey?: string;
43
+ * Custom headers to include in the requests.
44
+ */
45
+ headers?: Record<string, string>;
87
46
  /**
88
- FriendliAI Team ID.
47
+ * FriendliAI Team ID.
89
48
  */
90
49
  teamId?: string;
91
50
  /**
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
- */
51
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
52
+ * or to provide a custom fetch implementation for e.g. testing.
53
+ */
99
54
  fetch?: FetchFunction;
100
55
  }
56
+ interface FriendliAIProvider {
57
+ /**
58
+ * Creates a model for text generation.
59
+ */
60
+ (modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
61
+ /**
62
+ * A model that has not yet been officially released
63
+ */
64
+ beta(modelId: FriendliAIBetaChatModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
65
+ /**
66
+ * Creates a chat model for text generation.
67
+ */
68
+ chat(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
69
+ chatModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
70
+ /**
71
+ * Creates a completion model for text generation.
72
+ */
73
+ completion(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
74
+ completionModel(modelId: FriendliAILanguageModelId, settings?: FriendliAIChatSettings): LanguageModelV1;
75
+ /**
76
+ * Creates a text embedding model for text generation.
77
+ */
78
+ embedding(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
79
+ textEmbeddingModel(modelId: string & {}, settings?: FriendliAIChatSettings): LanguageModelV1;
80
+ }
101
81
  /**
102
82
  Create an FriendliAI provider instance.
103
83
  */
104
84
  declare function createFriendli(options?: FriendliAIProviderSettings): FriendliAIProvider;
105
85
  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
86
 
115
- export { type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, createFriendliAI, friendli, friendliai };
87
+ declare const friendliaiErrorSchema: z.ZodObject<{
88
+ message: z.ZodString;
89
+ }, "strip", z.ZodTypeAny, {
90
+ message: string;
91
+ }, {
92
+ message: string;
93
+ }>;
94
+ type FriendliAIErrorData = z.infer<typeof friendliaiErrorSchema>;
95
+
96
+ export { type FriendliAIErrorData, type FriendliAIProvider, type FriendliAIProviderSettings, createFriendli, friendli };