@ai-sdk/alibaba 1.0.24 → 1.0.26

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.
@@ -1,4 +1,5 @@
1
1
  import {
2
+ type EmbeddingModelV3,
2
3
  type Experimental_VideoModelV3,
3
4
  type LanguageModelV3,
4
5
  NoSuchModelError,
@@ -12,6 +13,8 @@ import {
12
13
  } from '@ai-sdk/provider-utils';
13
14
  import { AlibabaLanguageModel } from './alibaba-chat-language-model';
14
15
  import type { AlibabaChatModelId } from './alibaba-chat-options';
16
+ import { AlibabaEmbeddingModel } from './alibaba-embedding-model';
17
+ import type { AlibabaEmbeddingModelId } from './alibaba-embedding-options';
15
18
  import { AlibabaVideoModel } from './alibaba-video-model';
16
19
  import type { AlibabaVideoModelId } from './alibaba-video-settings';
17
20
  import { VERSION } from './version';
@@ -34,6 +37,30 @@ export interface AlibabaProvider extends ProviderV3 {
34
37
  */
35
38
  chatModel(modelId: AlibabaChatModelId): LanguageModelV3;
36
39
 
40
+ /**
41
+ * Creates a model for text embeddings.
42
+ */
43
+ embedding(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
44
+
45
+ /**
46
+ * Creates a model for text embeddings.
47
+ */
48
+ embeddingModel(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
49
+
50
+ /**
51
+ * Creates a model for text embeddings.
52
+ *
53
+ * @deprecated Use `embedding` instead.
54
+ */
55
+ textEmbedding(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
56
+
57
+ /**
58
+ * Creates a model for text embeddings.
59
+ *
60
+ * @deprecated Use `embeddingModel` instead.
61
+ */
62
+ textEmbeddingModel(modelId: AlibabaEmbeddingModelId): EmbeddingModelV3;
63
+
37
64
  /**
38
65
  * Creates a model for video generation.
39
66
  */
@@ -59,6 +86,13 @@ export interface AlibabaProviderSettings {
59
86
  */
60
87
  videoBaseURL?: string;
61
88
 
89
+ /**
90
+ * Use a different URL prefix for embedding API calls.
91
+ * The embedding API uses the DashScope native endpoint (not the OpenAI-compatible endpoint).
92
+ * The default prefix is `https://dashscope-intl.aliyuncs.com/api/v1`.
93
+ */
94
+ embeddingBaseURL?: string;
95
+
62
96
  /**
63
97
  * API key that is being sent using the `Authorization` header.
64
98
  * It defaults to the `ALIBABA_API_KEY` environment variable.
@@ -99,6 +133,10 @@ export function createAlibaba(
99
133
  withoutTrailingSlash(options.videoBaseURL) ??
100
134
  'https://dashscope-intl.aliyuncs.com';
101
135
 
136
+ const embeddingBaseURL =
137
+ withoutTrailingSlash(options.embeddingBaseURL) ??
138
+ 'https://dashscope-intl.aliyuncs.com/api/v1';
139
+
102
140
  const getHeaders = () =>
103
141
  withUserAgentSuffix(
104
142
  {
@@ -121,6 +159,14 @@ export function createAlibaba(
121
159
  includeUsage: options.includeUsage ?? true,
122
160
  });
123
161
 
162
+ const createEmbeddingModel = (modelId: AlibabaEmbeddingModelId) =>
163
+ new AlibabaEmbeddingModel(modelId, {
164
+ provider: 'alibaba.embedding',
165
+ baseURL: embeddingBaseURL,
166
+ headers: getHeaders,
167
+ fetch: options.fetch,
168
+ });
169
+
124
170
  const createVideoModel = (modelId: AlibabaVideoModelId) =>
125
171
  new AlibabaVideoModel(modelId, {
126
172
  provider: 'alibaba.video',
@@ -142,6 +188,10 @@ export function createAlibaba(
142
188
  provider.specificationVersion = 'v3' as const;
143
189
  provider.languageModel = createLanguageModel;
144
190
  provider.chatModel = createLanguageModel;
191
+ provider.embedding = createEmbeddingModel;
192
+ provider.embeddingModel = createEmbeddingModel;
193
+ provider.textEmbedding = createEmbeddingModel;
194
+ provider.textEmbeddingModel = createEmbeddingModel;
145
195
  provider.video = createVideoModel;
146
196
  provider.videoModel = createVideoModel;
147
197
 
@@ -149,10 +199,6 @@ export function createAlibaba(
149
199
  throw new NoSuchModelError({ modelId, modelType: 'imageModel' });
150
200
  };
151
201
 
152
- provider.embeddingModel = (modelId: string) => {
153
- throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });
154
- };
155
-
156
202
  return provider;
157
203
  }
158
204
 
package/src/index.ts CHANGED
@@ -5,6 +5,10 @@ export type {
5
5
  AlibabaLanguageModelOptions as AlibabaProviderOptions,
6
6
  } from './alibaba-chat-options';
7
7
  export type { AlibabaCacheControl } from './alibaba-chat-prompt';
8
+ export type {
9
+ AlibabaEmbeddingModelId,
10
+ AlibabaEmbeddingModelOptions,
11
+ } from './alibaba-embedding-options';
8
12
  export {
9
13
  type AlibabaProvider,
10
14
  type AlibabaProviderSettings,