@nordlys-labs/nordlys-ai-provider 0.1.0 → 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/dist/index.d.cts CHANGED
@@ -1,16 +1,123 @@
1
+ import { z } from 'zod/v4';
1
2
  import { ProviderV3, LanguageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
2
3
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
4
 
5
+ /**
6
+ * Provider options for Nordlys chat models.
7
+ */
8
+ declare const nordlysProviderOptions: z.ZodObject<{
9
+ model: z.ZodOptional<z.ZodString>;
10
+ logit_bias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
11
+ n: z.ZodOptional<z.ZodNumber>;
12
+ stream: z.ZodOptional<z.ZodBoolean>;
13
+ user: z.ZodOptional<z.ZodString>;
14
+ audio: z.ZodOptional<z.ZodObject<{
15
+ format: z.ZodOptional<z.ZodString>;
16
+ voice: z.ZodOptional<z.ZodString>;
17
+ }, z.core.$strip>>;
18
+ logprobs: z.ZodOptional<z.ZodBoolean>;
19
+ max_completion_tokens: z.ZodOptional<z.ZodNumber>;
20
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
21
+ modalities: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ parallel_tool_calls: z.ZodOptional<z.ZodBoolean>;
23
+ prediction: z.ZodOptional<z.ZodObject<{
24
+ type: z.ZodOptional<z.ZodString>;
25
+ content: z.ZodOptional<z.ZodObject<{
26
+ OfString: z.ZodOptional<z.ZodString>;
27
+ OfArrayOfContentParts: z.ZodOptional<z.ZodArray<z.ZodObject<{
28
+ type: z.ZodLiteral<"text">;
29
+ text: z.ZodString;
30
+ }, z.core.$strip>>>;
31
+ }, z.core.$strip>>;
32
+ }, z.core.$strip>>;
33
+ reasoning_effort: z.ZodOptional<z.ZodString>;
34
+ response_format: z.ZodOptional<z.ZodObject<{
35
+ OfText: z.ZodOptional<z.ZodObject<{
36
+ type: z.ZodString;
37
+ }, z.core.$strip>>;
38
+ OfJSONObject: z.ZodOptional<z.ZodObject<{
39
+ type: z.ZodString;
40
+ }, z.core.$strip>>;
41
+ OfJSONSchema: z.ZodOptional<z.ZodObject<{
42
+ type: z.ZodString;
43
+ json_schema: z.ZodOptional<z.ZodObject<{
44
+ name: z.ZodString;
45
+ schema: z.ZodUnknown;
46
+ description: z.ZodOptional<z.ZodString>;
47
+ strict: z.ZodOptional<z.ZodBoolean>;
48
+ }, z.core.$strip>>;
49
+ }, z.core.$strip>>;
50
+ }, z.core.$strip>>;
51
+ seed: z.ZodOptional<z.ZodNumber>;
52
+ service_tier: z.ZodOptional<z.ZodString>;
53
+ store: z.ZodOptional<z.ZodBoolean>;
54
+ top_logprobs: z.ZodOptional<z.ZodNumber>;
55
+ web_search_options: z.ZodOptional<z.ZodObject<{
56
+ search_context_size: z.ZodOptional<z.ZodString>;
57
+ user_location: z.ZodOptional<z.ZodObject<{
58
+ type: z.ZodOptional<z.ZodString>;
59
+ approximate: z.ZodOptional<z.ZodObject<{
60
+ city: z.ZodOptional<z.ZodString>;
61
+ country: z.ZodOptional<z.ZodString>;
62
+ region: z.ZodOptional<z.ZodString>;
63
+ timezone: z.ZodOptional<z.ZodString>;
64
+ }, z.core.$strip>>;
65
+ }, z.core.$strip>>;
66
+ }, z.core.$strip>>;
67
+ }, z.core.$strip>;
68
+ /**
69
+ * Type for validated Nordlys provider options.
70
+ */
71
+ type NordlysProviderOptions = z.infer<typeof nordlysProviderOptions>;
72
+ /**
73
+ * Settings that can be set at model creation time.
74
+ * These settings will be merged with call-level options, with call-level taking precedence.
75
+ */
76
+ interface NordlysChatSettings {
77
+ /**
78
+ * Temperature setting for the model.
79
+ */
80
+ temperature?: number;
81
+ /**
82
+ * Maximum number of output tokens.
83
+ */
84
+ maxOutputTokens?: number;
85
+ /**
86
+ * Top-p sampling parameter.
87
+ */
88
+ topP?: number;
89
+ /**
90
+ * Top-k sampling parameter.
91
+ */
92
+ topK?: number;
93
+ /**
94
+ * Frequency penalty.
95
+ */
96
+ frequencyPenalty?: number;
97
+ /**
98
+ * Presence penalty.
99
+ */
100
+ presencePenalty?: number;
101
+ /**
102
+ * Stop sequences.
103
+ */
104
+ stopSequences?: string[];
105
+ /**
106
+ * Provider-specific options.
107
+ */
108
+ providerOptions?: NordlysProviderOptions;
109
+ }
110
+
4
111
  interface NordlysProvider extends ProviderV3 {
5
- (modelId: string): LanguageModelV3;
112
+ (modelId: string, settings?: NordlysChatSettings): LanguageModelV3;
6
113
  /**
7
114
  * Creates a model for text generation with Nordlys models.
8
115
  */
9
- languageModel: (modelId: string) => LanguageModelV3;
116
+ languageModel: (modelId: string, settings?: NordlysChatSettings) => LanguageModelV3;
10
117
  /**
11
118
  * Creates a chat model with Nordlys models.
12
119
  */
13
- chat: (modelId: string) => LanguageModelV3;
120
+ chat: (modelId: string, settings?: NordlysChatSettings) => LanguageModelV3;
14
121
  /**
15
122
  * Text embedding is not currently supported by the Nordlys provider.
16
123
  */
@@ -295,4 +402,4 @@ interface V2ChatCompletionStreamOptionsParam {
295
402
  include_obfuscation?: boolean;
296
403
  }
297
404
 
298
- export { type NordlysChatCompletionAssistantMessage, type NordlysChatCompletionContentPart, type NordlysChatCompletionDeveloperMessage, type NordlysChatCompletionMessage, type NordlysChatCompletionMessageToolCall, type NordlysChatCompletionRequest, type NordlysChatCompletionResponse, type NordlysChatCompletionSystemMessage, type NordlysChatCompletionToolMessage, type NordlysChatCompletionUsage, type NordlysChatCompletionUserMessage, type NordlysProvider, type NordlysProviderSettings, type SharedMetadata, type SharedResponseFormatJSONObjectParam, type SharedResponseFormatJSONSchemaJSONSchemaParam, type SharedResponseFormatJSONSchemaParam, type SharedResponseFormatTextParam, type V2ChatCompletionAudioParam, type V2ChatCompletionNewParamsResponseFormatUnion, type V2ChatCompletionNewParamsWebSearchOptions, type V2ChatCompletionNewParamsWebSearchOptionsUserLocation, type V2ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate, type V2ChatCompletionPredictionContentContentUnionParam, type V2ChatCompletionPredictionContentParam, type V2ChatCompletionStreamOptionsParam, createNordlys, nordlys };
405
+ export { type NordlysChatCompletionAssistantMessage, type NordlysChatCompletionContentPart, type NordlysChatCompletionDeveloperMessage, type NordlysChatCompletionMessage, type NordlysChatCompletionMessageToolCall, type NordlysChatCompletionRequest, type NordlysChatCompletionResponse, type NordlysChatCompletionSystemMessage, type NordlysChatCompletionToolMessage, type NordlysChatCompletionUsage, type NordlysChatCompletionUserMessage, type NordlysChatSettings, type NordlysProvider, type NordlysProviderSettings, type SharedMetadata, type SharedResponseFormatJSONObjectParam, type SharedResponseFormatJSONSchemaJSONSchemaParam, type SharedResponseFormatJSONSchemaParam, type SharedResponseFormatTextParam, type V2ChatCompletionAudioParam, type V2ChatCompletionNewParamsResponseFormatUnion, type V2ChatCompletionNewParamsWebSearchOptions, type V2ChatCompletionNewParamsWebSearchOptionsUserLocation, type V2ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate, type V2ChatCompletionPredictionContentContentUnionParam, type V2ChatCompletionPredictionContentParam, type V2ChatCompletionStreamOptionsParam, createNordlys, nordlys };
package/dist/index.d.ts CHANGED
@@ -1,16 +1,123 @@
1
+ import { z } from 'zod/v4';
1
2
  import { ProviderV3, LanguageModelV3, EmbeddingModelV3 } from '@ai-sdk/provider';
2
3
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
4
 
5
+ /**
6
+ * Provider options for Nordlys chat models.
7
+ */
8
+ declare const nordlysProviderOptions: z.ZodObject<{
9
+ model: z.ZodOptional<z.ZodString>;
10
+ logit_bias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
11
+ n: z.ZodOptional<z.ZodNumber>;
12
+ stream: z.ZodOptional<z.ZodBoolean>;
13
+ user: z.ZodOptional<z.ZodString>;
14
+ audio: z.ZodOptional<z.ZodObject<{
15
+ format: z.ZodOptional<z.ZodString>;
16
+ voice: z.ZodOptional<z.ZodString>;
17
+ }, z.core.$strip>>;
18
+ logprobs: z.ZodOptional<z.ZodBoolean>;
19
+ max_completion_tokens: z.ZodOptional<z.ZodNumber>;
20
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
21
+ modalities: z.ZodOptional<z.ZodArray<z.ZodString>>;
22
+ parallel_tool_calls: z.ZodOptional<z.ZodBoolean>;
23
+ prediction: z.ZodOptional<z.ZodObject<{
24
+ type: z.ZodOptional<z.ZodString>;
25
+ content: z.ZodOptional<z.ZodObject<{
26
+ OfString: z.ZodOptional<z.ZodString>;
27
+ OfArrayOfContentParts: z.ZodOptional<z.ZodArray<z.ZodObject<{
28
+ type: z.ZodLiteral<"text">;
29
+ text: z.ZodString;
30
+ }, z.core.$strip>>>;
31
+ }, z.core.$strip>>;
32
+ }, z.core.$strip>>;
33
+ reasoning_effort: z.ZodOptional<z.ZodString>;
34
+ response_format: z.ZodOptional<z.ZodObject<{
35
+ OfText: z.ZodOptional<z.ZodObject<{
36
+ type: z.ZodString;
37
+ }, z.core.$strip>>;
38
+ OfJSONObject: z.ZodOptional<z.ZodObject<{
39
+ type: z.ZodString;
40
+ }, z.core.$strip>>;
41
+ OfJSONSchema: z.ZodOptional<z.ZodObject<{
42
+ type: z.ZodString;
43
+ json_schema: z.ZodOptional<z.ZodObject<{
44
+ name: z.ZodString;
45
+ schema: z.ZodUnknown;
46
+ description: z.ZodOptional<z.ZodString>;
47
+ strict: z.ZodOptional<z.ZodBoolean>;
48
+ }, z.core.$strip>>;
49
+ }, z.core.$strip>>;
50
+ }, z.core.$strip>>;
51
+ seed: z.ZodOptional<z.ZodNumber>;
52
+ service_tier: z.ZodOptional<z.ZodString>;
53
+ store: z.ZodOptional<z.ZodBoolean>;
54
+ top_logprobs: z.ZodOptional<z.ZodNumber>;
55
+ web_search_options: z.ZodOptional<z.ZodObject<{
56
+ search_context_size: z.ZodOptional<z.ZodString>;
57
+ user_location: z.ZodOptional<z.ZodObject<{
58
+ type: z.ZodOptional<z.ZodString>;
59
+ approximate: z.ZodOptional<z.ZodObject<{
60
+ city: z.ZodOptional<z.ZodString>;
61
+ country: z.ZodOptional<z.ZodString>;
62
+ region: z.ZodOptional<z.ZodString>;
63
+ timezone: z.ZodOptional<z.ZodString>;
64
+ }, z.core.$strip>>;
65
+ }, z.core.$strip>>;
66
+ }, z.core.$strip>>;
67
+ }, z.core.$strip>;
68
+ /**
69
+ * Type for validated Nordlys provider options.
70
+ */
71
+ type NordlysProviderOptions = z.infer<typeof nordlysProviderOptions>;
72
+ /**
73
+ * Settings that can be set at model creation time.
74
+ * These settings will be merged with call-level options, with call-level taking precedence.
75
+ */
76
+ interface NordlysChatSettings {
77
+ /**
78
+ * Temperature setting for the model.
79
+ */
80
+ temperature?: number;
81
+ /**
82
+ * Maximum number of output tokens.
83
+ */
84
+ maxOutputTokens?: number;
85
+ /**
86
+ * Top-p sampling parameter.
87
+ */
88
+ topP?: number;
89
+ /**
90
+ * Top-k sampling parameter.
91
+ */
92
+ topK?: number;
93
+ /**
94
+ * Frequency penalty.
95
+ */
96
+ frequencyPenalty?: number;
97
+ /**
98
+ * Presence penalty.
99
+ */
100
+ presencePenalty?: number;
101
+ /**
102
+ * Stop sequences.
103
+ */
104
+ stopSequences?: string[];
105
+ /**
106
+ * Provider-specific options.
107
+ */
108
+ providerOptions?: NordlysProviderOptions;
109
+ }
110
+
4
111
  interface NordlysProvider extends ProviderV3 {
5
- (modelId: string): LanguageModelV3;
112
+ (modelId: string, settings?: NordlysChatSettings): LanguageModelV3;
6
113
  /**
7
114
  * Creates a model for text generation with Nordlys models.
8
115
  */
9
- languageModel: (modelId: string) => LanguageModelV3;
116
+ languageModel: (modelId: string, settings?: NordlysChatSettings) => LanguageModelV3;
10
117
  /**
11
118
  * Creates a chat model with Nordlys models.
12
119
  */
13
- chat: (modelId: string) => LanguageModelV3;
120
+ chat: (modelId: string, settings?: NordlysChatSettings) => LanguageModelV3;
14
121
  /**
15
122
  * Text embedding is not currently supported by the Nordlys provider.
16
123
  */
@@ -295,4 +402,4 @@ interface V2ChatCompletionStreamOptionsParam {
295
402
  include_obfuscation?: boolean;
296
403
  }
297
404
 
298
- export { type NordlysChatCompletionAssistantMessage, type NordlysChatCompletionContentPart, type NordlysChatCompletionDeveloperMessage, type NordlysChatCompletionMessage, type NordlysChatCompletionMessageToolCall, type NordlysChatCompletionRequest, type NordlysChatCompletionResponse, type NordlysChatCompletionSystemMessage, type NordlysChatCompletionToolMessage, type NordlysChatCompletionUsage, type NordlysChatCompletionUserMessage, type NordlysProvider, type NordlysProviderSettings, type SharedMetadata, type SharedResponseFormatJSONObjectParam, type SharedResponseFormatJSONSchemaJSONSchemaParam, type SharedResponseFormatJSONSchemaParam, type SharedResponseFormatTextParam, type V2ChatCompletionAudioParam, type V2ChatCompletionNewParamsResponseFormatUnion, type V2ChatCompletionNewParamsWebSearchOptions, type V2ChatCompletionNewParamsWebSearchOptionsUserLocation, type V2ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate, type V2ChatCompletionPredictionContentContentUnionParam, type V2ChatCompletionPredictionContentParam, type V2ChatCompletionStreamOptionsParam, createNordlys, nordlys };
405
+ export { type NordlysChatCompletionAssistantMessage, type NordlysChatCompletionContentPart, type NordlysChatCompletionDeveloperMessage, type NordlysChatCompletionMessage, type NordlysChatCompletionMessageToolCall, type NordlysChatCompletionRequest, type NordlysChatCompletionResponse, type NordlysChatCompletionSystemMessage, type NordlysChatCompletionToolMessage, type NordlysChatCompletionUsage, type NordlysChatCompletionUserMessage, type NordlysChatSettings, type NordlysProvider, type NordlysProviderSettings, type SharedMetadata, type SharedResponseFormatJSONObjectParam, type SharedResponseFormatJSONSchemaJSONSchemaParam, type SharedResponseFormatJSONSchemaParam, type SharedResponseFormatTextParam, type V2ChatCompletionAudioParam, type V2ChatCompletionNewParamsResponseFormatUnion, type V2ChatCompletionNewParamsWebSearchOptions, type V2ChatCompletionNewParamsWebSearchOptionsUserLocation, type V2ChatCompletionNewParamsWebSearchOptionsUserLocationApproximate, type V2ChatCompletionPredictionContentContentUnionParam, type V2ChatCompletionPredictionContentParam, type V2ChatCompletionStreamOptionsParam, createNordlys, nordlys };
package/dist/index.js CHANGED
@@ -553,13 +553,14 @@ var nordlysChatChunkSchema = z3.union([
553
553
  })
554
554
  ]);
555
555
  var NordlysChatLanguageModel = class {
556
- constructor(modelId, config) {
556
+ constructor(modelId, settings, config) {
557
557
  this.specificationVersion = "v3";
558
558
  this.supportedUrls = {
559
559
  "application/pdf": [/^https:\/\/.*$/]
560
560
  };
561
561
  this.modelId = modelId;
562
562
  this.config = config;
563
+ this.settings = settings;
563
564
  }
564
565
  get provider() {
565
566
  return this.config.provider;
@@ -578,14 +579,28 @@ var NordlysChatLanguageModel = class {
578
579
  tools,
579
580
  toolChoice
580
581
  }) {
582
+ var _a, _b, _c, _d, _e, _f, _g, _h;
581
583
  const warnings = [];
582
- if (topK != null) {
584
+ const mergedMaxOutputTokens = maxOutputTokens != null ? maxOutputTokens : (_a = this.settings) == null ? void 0 : _a.maxOutputTokens;
585
+ const mergedTemperature = temperature != null ? temperature : (_b = this.settings) == null ? void 0 : _b.temperature;
586
+ const mergedTopP = topP != null ? topP : (_c = this.settings) == null ? void 0 : _c.topP;
587
+ const mergedTopK = topK != null ? topK : (_d = this.settings) == null ? void 0 : _d.topK;
588
+ const mergedFrequencyPenalty = frequencyPenalty != null ? frequencyPenalty : (_e = this.settings) == null ? void 0 : _e.frequencyPenalty;
589
+ const mergedPresencePenalty = presencePenalty != null ? presencePenalty : (_f = this.settings) == null ? void 0 : _f.presencePenalty;
590
+ const mergedStopSequences = stopSequences != null ? stopSequences : (_g = this.settings) == null ? void 0 : _g.stopSequences;
591
+ const mergedProviderOptions = {
592
+ ...(_h = this.settings) == null ? void 0 : _h.providerOptions,
593
+ ...providerOptions
594
+ };
595
+ if (mergedTopK != null) {
583
596
  warnings.push({ type: "unsupported", feature: "topK" });
584
597
  }
585
598
  if (responseFormat != null) {
586
599
  warnings.push({ type: "unsupported", feature: "responseFormat" });
587
600
  }
588
- const result = nordlysProviderOptions.safeParse(providerOptions != null ? providerOptions : {});
601
+ const result = nordlysProviderOptions.safeParse(
602
+ mergedProviderOptions != null ? mergedProviderOptions : {}
603
+ );
589
604
  const nordlysOptions = result.success ? result.data : {};
590
605
  const {
591
606
  tools: nordlysTools,
@@ -601,13 +616,13 @@ var NordlysChatLanguageModel = class {
601
616
  const standardizedArgs = {
602
617
  messages,
603
618
  model: this.modelId,
604
- max_tokens: typeof maxOutputTokens === "number" ? maxOutputTokens : void 0,
619
+ max_tokens: typeof mergedMaxOutputTokens === "number" ? mergedMaxOutputTokens : void 0,
605
620
  max_completion_tokens: nordlysOptions.max_completion_tokens,
606
- temperature,
607
- top_p: topP,
608
- stop: stopSequences,
609
- presence_penalty: presencePenalty,
610
- frequency_penalty: frequencyPenalty,
621
+ temperature: mergedTemperature,
622
+ top_p: mergedTopP,
623
+ stop: mergedStopSequences,
624
+ presence_penalty: mergedPresencePenalty,
625
+ frequency_penalty: mergedFrequencyPenalty,
611
626
  user: nordlysOptions.user,
612
627
  tools: nordlysTools,
613
628
  tool_choice: nordlysToolChoice
@@ -1005,19 +1020,19 @@ function createNordlys(options = {}) {
1005
1020
  "Content-Type": "application/json",
1006
1021
  ...options.headers
1007
1022
  });
1008
- const createChatModel = (modelId) => new NordlysChatLanguageModel(modelId, {
1023
+ const createChatModel = (modelId, settings) => new NordlysChatLanguageModel(modelId, settings, {
1009
1024
  provider: "nordlys.chat",
1010
1025
  baseURL,
1011
1026
  headers: getHeaders,
1012
1027
  fetch: options.fetch
1013
1028
  });
1014
- const provider = function(modelId) {
1029
+ const provider = function(modelId, settings) {
1015
1030
  if (new.target) {
1016
1031
  throw new Error(
1017
1032
  "The Nordlys model function cannot be called with the new keyword."
1018
1033
  );
1019
1034
  }
1020
- return createChatModel(modelId);
1035
+ return createChatModel(modelId, settings);
1021
1036
  };
1022
1037
  provider.languageModel = createChatModel;
1023
1038
  provider.chat = createChatModel;