@ai-sdk/togetherai 3.0.0-beta.4 → 3.0.0-beta.57

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.
@@ -0,0 +1,43 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod/v4';
7
+
8
+ /**
9
+ * Provider options schema for Together AI image generation.
10
+ */
11
+ export const togetheraiImageModelOptionsSchema = lazySchema(() =>
12
+ zodSchema(
13
+ z
14
+ .object({
15
+ /**
16
+ * Number of generation steps. Higher values can improve quality.
17
+ */
18
+ steps: z.number().nullish(),
19
+
20
+ /**
21
+ * Guidance scale for image generation.
22
+ */
23
+ guidance: z.number().nullish(),
24
+
25
+ /**
26
+ * Negative prompt to guide what to avoid.
27
+ */
28
+ negative_prompt: z.string().nullish(),
29
+
30
+ /**
31
+ * Disable the safety checker for image generation.
32
+ * When true, the API will not reject images flagged as potentially NSFW.
33
+ * Not available for Flux Schnell Free and Flux Pro models.
34
+ */
35
+ disable_safety_checker: z.boolean().nullish(),
36
+ })
37
+ .passthrough(),
38
+ ),
39
+ );
40
+
41
+ export type TogetherAIImageModelOptions = InferSchema<
42
+ typeof togetheraiImageModelOptionsSchema
43
+ >;
@@ -1,23 +1,24 @@
1
- import { ImageModelV4, SharedV4Warning } from '@ai-sdk/provider';
1
+ import type { ImageModelV4, SharedV4Warning } from '@ai-sdk/provider';
2
2
  import {
3
3
  combineHeaders,
4
4
  convertImageModelFileToDataUri,
5
5
  createJsonResponseHandler,
6
6
  createJsonErrorResponseHandler,
7
- FetchFunction,
8
- InferSchema,
9
- lazySchema,
10
7
  parseProviderOptions,
11
8
  postJsonToApi,
12
- zodSchema,
9
+ serializeModelOptions,
10
+ WORKFLOW_SERIALIZE,
11
+ WORKFLOW_DESERIALIZE,
12
+ type FetchFunction,
13
13
  } from '@ai-sdk/provider-utils';
14
- import { TogetherAIImageModelId } from './togetherai-image-settings';
14
+ import { togetheraiImageModelOptionsSchema } from './togetherai-image-model-options';
15
+ import type { TogetherAIImageModelId } from './togetherai-image-settings';
15
16
  import { z } from 'zod/v4';
16
17
 
17
18
  interface TogetherAIImageModelConfig {
18
19
  provider: string;
19
20
  baseURL: string;
20
- headers: () => Record<string, string>;
21
+ headers?: () => Record<string, string>;
21
22
  fetch?: FetchFunction;
22
23
  _internal?: {
23
24
  currentDate?: () => Date;
@@ -32,6 +33,20 @@ export class TogetherAIImageModel implements ImageModelV4 {
32
33
  return this.config.provider;
33
34
  }
34
35
 
36
+ static [WORKFLOW_SERIALIZE](model: TogetherAIImageModel) {
37
+ return serializeModelOptions({
38
+ modelId: model.modelId,
39
+ config: model.config,
40
+ });
41
+ }
42
+
43
+ static [WORKFLOW_DESERIALIZE](options: {
44
+ modelId: TogetherAIImageModelId;
45
+ config: TogetherAIImageModelConfig;
46
+ }) {
47
+ return new TogetherAIImageModel(options.modelId, options.config);
48
+ }
49
+
35
50
  constructor(
36
51
  readonly modelId: TogetherAIImageModelId,
37
52
  private config: TogetherAIImageModelConfig,
@@ -95,11 +110,11 @@ export class TogetherAIImageModel implements ImageModelV4 {
95
110
  // https://docs.together.ai/reference/post_images-generations
96
111
  const { value: response, responseHeaders } = await postJsonToApi({
97
112
  url: `${this.config.baseURL}/images/generations`,
98
- headers: combineHeaders(this.config.headers(), headers),
113
+ headers: combineHeaders(this.config.headers?.(), headers),
99
114
  body: {
100
115
  model: this.modelId,
101
116
  prompt,
102
- seed,
117
+ ...(seed != null ? { seed } : {}),
103
118
  ...(n > 1 ? { n } : {}),
104
119
  ...(splitSize && {
105
120
  width: parseInt(splitSize[0]),
@@ -149,40 +164,3 @@ const togetheraiErrorSchema = z.object({
149
164
  message: z.string(),
150
165
  }),
151
166
  });
152
-
153
- /**
154
- * Provider options schema for Together AI image generation.
155
- */
156
- export const togetheraiImageModelOptionsSchema = lazySchema(() =>
157
- zodSchema(
158
- z
159
- .object({
160
- /**
161
- * Number of generation steps. Higher values can improve quality.
162
- */
163
- steps: z.number().nullish(),
164
-
165
- /**
166
- * Guidance scale for image generation.
167
- */
168
- guidance: z.number().nullish(),
169
-
170
- /**
171
- * Negative prompt to guide what to avoid.
172
- */
173
- negative_prompt: z.string().nullish(),
174
-
175
- /**
176
- * Disable the safety checker for image generation.
177
- * When true, the API will not reject images flagged as potentially NSFW.
178
- * Not available for Flux Schnell Free and Flux Pro models.
179
- */
180
- disable_safety_checker: z.boolean().nullish(),
181
- })
182
- .passthrough(),
183
- ),
184
- );
185
-
186
- export type TogetherAIImageModelOptions = InferSchema<
187
- typeof togetheraiImageModelOptionsSchema
188
- >;
@@ -3,7 +3,7 @@ import {
3
3
  OpenAICompatibleCompletionLanguageModel,
4
4
  OpenAICompatibleEmbeddingModel,
5
5
  } from '@ai-sdk/openai-compatible';
6
- import {
6
+ import type {
7
7
  EmbeddingModelV4,
8
8
  ImageModelV4,
9
9
  LanguageModelV4,
@@ -11,18 +11,18 @@ import {
11
11
  RerankingModelV4,
12
12
  } from '@ai-sdk/provider';
13
13
  import {
14
- FetchFunction,
15
14
  loadApiKey,
16
15
  withoutTrailingSlash,
17
16
  withUserAgentSuffix,
17
+ type FetchFunction,
18
18
  } from '@ai-sdk/provider-utils';
19
19
  import { TogetherAIRerankingModel } from './reranking/togetherai-reranking-model';
20
- import { TogetherAIRerankingModelId } from './reranking/togetherai-reranking-options';
21
- import { TogetherAIChatModelId } from './togetherai-chat-options';
22
- import { TogetherAICompletionModelId } from './togetherai-completion-options';
23
- import { TogetherAIEmbeddingModelId } from './togetherai-embedding-options';
20
+ import type { TogetherAIRerankingModelId } from './reranking/togetherai-reranking-model-options';
21
+ import type { TogetherAIChatModelId } from './togetherai-chat-options';
22
+ import type { TogetherAICompletionModelId } from './togetherai-completion-options';
23
+ import type { TogetherAIEmbeddingModelId } from './togetherai-embedding-options';
24
24
  import { TogetherAIImageModel } from './togetherai-image-model';
25
- import { TogetherAIImageModelId } from './togetherai-image-settings';
25
+ import type { TogetherAIImageModelId } from './togetherai-image-settings';
26
26
  import { VERSION } from './version';
27
27
 
28
28
  export interface TogetherAIProviderSettings {
package/dist/index.d.mts DELETED
@@ -1,103 +0,0 @@
1
- export { OpenAICompatibleErrorData as TogetherAIErrorData } from '@ai-sdk/openai-compatible';
2
- import { ProviderV4, LanguageModelV4, EmbeddingModelV4, ImageModelV4, RerankingModelV4 } from '@ai-sdk/provider';
3
- import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
4
- import { FetchFunction, InferSchema } from '@ai-sdk/provider-utils';
5
-
6
- type TogetherAIRerankingModelId = 'Salesforce/Llama-Rank-v1' | 'mixedbread-ai/Mxbai-Rerank-Large-V2' | (string & {});
7
- type TogetherAIRerankingModelOptions = {
8
- /**
9
- * List of keys in the JSON Object document to rank by.
10
- * Defaults to use all supplied keys for ranking.
11
- *
12
- * @example ["title", "text"]
13
- */
14
- rankFields?: string[];
15
- };
16
-
17
- type TogetherAIChatModelId = 'meta-llama/Llama-3.3-70B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3-8B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3-70B-Instruct-Turbo' | 'meta-llama/Llama-3.2-3B-Instruct-Turbo' | 'meta-llama/Meta-Llama-3-8B-Instruct-Lite' | 'meta-llama/Meta-Llama-3-70B-Instruct-Lite' | 'meta-llama/Llama-3-8b-chat-hf' | 'meta-llama/Llama-3-70b-chat-hf' | 'nvidia/Llama-3.1-Nemotron-70B-Instruct-HF' | 'Qwen/Qwen2.5-Coder-32B-Instruct' | 'Qwen/QwQ-32B-Preview' | 'microsoft/WizardLM-2-8x22B' | 'google/gemma-2-27b-it' | 'google/gemma-2-9b-it' | 'databricks/dbrx-instruct' | 'deepseek-ai/deepseek-llm-67b-chat' | 'deepseek-ai/DeepSeek-V3' | 'google/gemma-2b-it' | 'Gryphe/MythoMax-L2-13b' | 'meta-llama/Llama-2-13b-chat-hf' | 'mistralai/Mistral-7B-Instruct-v0.1' | 'mistralai/Mistral-7B-Instruct-v0.2' | 'mistralai/Mistral-7B-Instruct-v0.3' | 'mistralai/Mixtral-8x7B-Instruct-v0.1' | 'mistralai/Mixtral-8x22B-Instruct-v0.1' | 'NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO' | 'Qwen/Qwen2.5-7B-Instruct-Turbo' | 'Qwen/Qwen2.5-72B-Instruct-Turbo' | 'Qwen/Qwen2-72B-Instruct' | 'upstage/SOLAR-10.7B-Instruct-v1.0' | (string & {});
18
-
19
- type TogetherAICompletionModelId = 'meta-llama/Llama-2-70b-hf' | 'mistralai/Mistral-7B-v0.1' | 'mistralai/Mixtral-8x7B-v0.1' | 'Meta-Llama/Llama-Guard-7b' | 'codellama/CodeLlama-34b-Instruct-hf' | 'Qwen/Qwen2.5-Coder-32B-Instruct' | (string & {});
20
-
21
- type TogetherAIEmbeddingModelId = 'togethercomputer/m2-bert-80M-2k-retrieval' | 'togethercomputer/m2-bert-80M-32k-retrieval' | 'togethercomputer/m2-bert-80M-8k-retrieval' | 'WhereIsAI/UAE-Large-V1' | 'BAAI/bge-large-en-v1.5' | 'BAAI/bge-base-en-v1.5' | 'sentence-transformers/msmarco-bert-base-dot-v5' | 'bert-base-uncased' | (string & {});
22
-
23
- type TogetherAIImageModelId = 'stabilityai/stable-diffusion-xl-base-1.0' | 'black-forest-labs/FLUX.1-dev' | 'black-forest-labs/FLUX.1-dev-lora' | 'black-forest-labs/FLUX.1-schnell' | 'black-forest-labs/FLUX.1-canny' | 'black-forest-labs/FLUX.1-depth' | 'black-forest-labs/FLUX.1-redux' | 'black-forest-labs/FLUX.1.1-pro' | 'black-forest-labs/FLUX.1-pro' | 'black-forest-labs/FLUX.1-schnell-Free' | 'black-forest-labs/FLUX.1-kontext-pro' | 'black-forest-labs/FLUX.1-kontext-max' | 'black-forest-labs/FLUX.1-kontext-dev' | (string & {});
24
-
25
- interface TogetherAIProviderSettings {
26
- /**
27
- * TogetherAI API key.
28
- */
29
- apiKey?: string;
30
- /**
31
- * Base URL for the API calls.
32
- */
33
- baseURL?: string;
34
- /**
35
- * Custom headers to include in the requests.
36
- */
37
- headers?: Record<string, string>;
38
- /**
39
- * Custom fetch implementation. You can use it as a middleware to intercept requests,
40
- * or to provide a custom fetch implementation for e.g. testing.
41
- */
42
- fetch?: FetchFunction;
43
- }
44
- interface TogetherAIProvider extends ProviderV4 {
45
- /**
46
- * Creates a model for text generation.
47
- */
48
- (modelId: TogetherAIChatModelId): LanguageModelV4;
49
- /**
50
- * Creates a chat model for text generation.
51
- */
52
- chatModel(modelId: TogetherAIChatModelId): LanguageModelV4;
53
- /**
54
- * Creates a chat model for text generation.
55
- */
56
- languageModel(modelId: TogetherAIChatModelId): LanguageModelV4;
57
- /**
58
- * Creates a completion model for text generation.
59
- */
60
- completionModel(modelId: TogetherAICompletionModelId): LanguageModelV4;
61
- /**
62
- * Creates a text embedding model for text generation.
63
- */
64
- embeddingModel(modelId: TogetherAIEmbeddingModelId): EmbeddingModelV4;
65
- /**
66
- * @deprecated Use `embeddingModel` instead.
67
- */
68
- textEmbeddingModel(modelId: TogetherAIEmbeddingModelId): EmbeddingModelV4;
69
- /**
70
- * Creates a model for image generation.
71
- */
72
- image(modelId: TogetherAIImageModelId): ImageModelV4;
73
- /**
74
- * Creates a model for image generation.
75
- */
76
- imageModel(modelId: TogetherAIImageModelId): ImageModelV4;
77
- /**
78
- * Creates a model for reranking.
79
- */
80
- reranking(modelId: TogetherAIRerankingModelId): RerankingModelV4;
81
- /**
82
- * Creates a model for reranking.
83
- */
84
- rerankingModel(modelId: TogetherAIRerankingModelId): RerankingModelV4;
85
- }
86
- declare function createTogetherAI(options?: TogetherAIProviderSettings): TogetherAIProvider;
87
- declare const togetherai: TogetherAIProvider;
88
-
89
- /**
90
- * Provider options schema for Together AI image generation.
91
- */
92
- declare const togetheraiImageModelOptionsSchema: _ai_sdk_provider_utils.LazySchema<{
93
- [x: string]: unknown;
94
- steps?: number | null | undefined;
95
- guidance?: number | null | undefined;
96
- negative_prompt?: string | null | undefined;
97
- disable_safety_checker?: boolean | null | undefined;
98
- }>;
99
- type TogetherAIImageModelOptions = InferSchema<typeof togetheraiImageModelOptionsSchema>;
100
-
101
- declare const VERSION: string;
102
-
103
- export { type TogetherAIImageModelOptions, type TogetherAIImageModelOptions as TogetherAIImageProviderOptions, type TogetherAIProvider, type TogetherAIProviderSettings, type TogetherAIRerankingModelOptions, type TogetherAIRerankingModelOptions as TogetherAIRerankingOptions, VERSION, createTogetherAI, togetherai };
package/dist/index.mjs DELETED
@@ -1,354 +0,0 @@
1
- // src/togetherai-provider.ts
2
- import {
3
- OpenAICompatibleChatLanguageModel,
4
- OpenAICompatibleCompletionLanguageModel,
5
- OpenAICompatibleEmbeddingModel
6
- } from "@ai-sdk/openai-compatible";
7
- import {
8
- loadApiKey,
9
- withoutTrailingSlash,
10
- withUserAgentSuffix
11
- } from "@ai-sdk/provider-utils";
12
-
13
- // src/reranking/togetherai-reranking-model.ts
14
- import {
15
- combineHeaders,
16
- createJsonErrorResponseHandler,
17
- createJsonResponseHandler,
18
- parseProviderOptions,
19
- postJsonToApi
20
- } from "@ai-sdk/provider-utils";
21
-
22
- // src/reranking/togetherai-reranking-api.ts
23
- import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
24
- import { z } from "zod/v4";
25
- var togetheraiErrorSchema = lazySchema(
26
- () => zodSchema(
27
- z.object({
28
- error: z.object({
29
- message: z.string()
30
- })
31
- })
32
- )
33
- );
34
- var togetheraiRerankingResponseSchema = lazySchema(
35
- () => zodSchema(
36
- z.object({
37
- id: z.string().nullish(),
38
- model: z.string().nullish(),
39
- results: z.array(
40
- z.object({
41
- index: z.number(),
42
- relevance_score: z.number()
43
- })
44
- ),
45
- usage: z.object({
46
- prompt_tokens: z.number(),
47
- completion_tokens: z.number(),
48
- total_tokens: z.number()
49
- })
50
- })
51
- )
52
- );
53
-
54
- // src/reranking/togetherai-reranking-options.ts
55
- import { lazySchema as lazySchema2, zodSchema as zodSchema2 } from "@ai-sdk/provider-utils";
56
- import { z as z2 } from "zod/v4";
57
- var togetheraiRerankingModelOptionsSchema = lazySchema2(
58
- () => zodSchema2(
59
- z2.object({
60
- rankFields: z2.array(z2.string()).optional()
61
- })
62
- )
63
- );
64
-
65
- // src/reranking/togetherai-reranking-model.ts
66
- var TogetherAIRerankingModel = class {
67
- constructor(modelId, config) {
68
- this.specificationVersion = "v4";
69
- this.modelId = modelId;
70
- this.config = config;
71
- }
72
- get provider() {
73
- return this.config.provider;
74
- }
75
- // see https://docs.together.ai/reference/rerank-1
76
- async doRerank({
77
- documents,
78
- headers,
79
- query,
80
- topN,
81
- abortSignal,
82
- providerOptions
83
- }) {
84
- var _a, _b;
85
- const rerankingOptions = await parseProviderOptions({
86
- provider: "togetherai",
87
- providerOptions,
88
- schema: togetheraiRerankingModelOptionsSchema
89
- });
90
- const {
91
- responseHeaders,
92
- value: response,
93
- rawValue
94
- } = await postJsonToApi({
95
- url: `${this.config.baseURL}/rerank`,
96
- headers: combineHeaders(this.config.headers(), headers),
97
- body: {
98
- model: this.modelId,
99
- documents: documents.values,
100
- query,
101
- top_n: topN,
102
- rank_fields: rerankingOptions == null ? void 0 : rerankingOptions.rankFields,
103
- return_documents: false
104
- // reduce response size
105
- },
106
- failedResponseHandler: createJsonErrorResponseHandler({
107
- errorSchema: togetheraiErrorSchema,
108
- errorToMessage: (data) => data.error.message
109
- }),
110
- successfulResponseHandler: createJsonResponseHandler(
111
- togetheraiRerankingResponseSchema
112
- ),
113
- abortSignal,
114
- fetch: this.config.fetch
115
- });
116
- return {
117
- ranking: response.results.map((result) => ({
118
- index: result.index,
119
- relevanceScore: result.relevance_score
120
- })),
121
- response: {
122
- id: (_a = response.id) != null ? _a : void 0,
123
- modelId: (_b = response.model) != null ? _b : void 0,
124
- headers: responseHeaders,
125
- body: rawValue
126
- }
127
- };
128
- }
129
- };
130
-
131
- // src/togetherai-image-model.ts
132
- import {
133
- combineHeaders as combineHeaders2,
134
- convertImageModelFileToDataUri,
135
- createJsonResponseHandler as createJsonResponseHandler2,
136
- createJsonErrorResponseHandler as createJsonErrorResponseHandler2,
137
- lazySchema as lazySchema3,
138
- parseProviderOptions as parseProviderOptions2,
139
- postJsonToApi as postJsonToApi2,
140
- zodSchema as zodSchema3
141
- } from "@ai-sdk/provider-utils";
142
- import { z as z3 } from "zod/v4";
143
- var TogetherAIImageModel = class {
144
- constructor(modelId, config) {
145
- this.modelId = modelId;
146
- this.config = config;
147
- this.specificationVersion = "v4";
148
- this.maxImagesPerCall = 1;
149
- }
150
- get provider() {
151
- return this.config.provider;
152
- }
153
- async doGenerate({
154
- prompt,
155
- n,
156
- size,
157
- seed,
158
- providerOptions,
159
- headers,
160
- abortSignal,
161
- files,
162
- mask
163
- }) {
164
- var _a, _b, _c;
165
- const warnings = [];
166
- if (mask != null) {
167
- throw new Error(
168
- "Together AI does not support mask-based image editing. Use FLUX Kontext models (e.g., black-forest-labs/FLUX.1-kontext-pro) with a reference image and descriptive prompt instead."
169
- );
170
- }
171
- if (size != null) {
172
- warnings.push({
173
- type: "unsupported",
174
- feature: "aspectRatio",
175
- details: "This model does not support the `aspectRatio` option. Use `size` instead."
176
- });
177
- }
178
- const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
179
- const togetheraiOptions = await parseProviderOptions2({
180
- provider: "togetherai",
181
- providerOptions,
182
- schema: togetheraiImageModelOptionsSchema
183
- });
184
- let imageUrl;
185
- if (files != null && files.length > 0) {
186
- imageUrl = convertImageModelFileToDataUri(files[0]);
187
- if (files.length > 1) {
188
- warnings.push({
189
- type: "other",
190
- message: "Together AI only supports a single input image. Additional images are ignored."
191
- });
192
- }
193
- }
194
- const splitSize = size == null ? void 0 : size.split("x");
195
- const { value: response, responseHeaders } = await postJsonToApi2({
196
- url: `${this.config.baseURL}/images/generations`,
197
- headers: combineHeaders2(this.config.headers(), headers),
198
- body: {
199
- model: this.modelId,
200
- prompt,
201
- seed,
202
- ...n > 1 ? { n } : {},
203
- ...splitSize && {
204
- width: parseInt(splitSize[0]),
205
- height: parseInt(splitSize[1])
206
- },
207
- ...imageUrl != null ? { image_url: imageUrl } : {},
208
- response_format: "base64",
209
- ...togetheraiOptions != null ? togetheraiOptions : {}
210
- },
211
- failedResponseHandler: createJsonErrorResponseHandler2({
212
- errorSchema: togetheraiErrorSchema2,
213
- errorToMessage: (data) => data.error.message
214
- }),
215
- successfulResponseHandler: createJsonResponseHandler2(
216
- togetheraiImageResponseSchema
217
- ),
218
- abortSignal,
219
- fetch: this.config.fetch
220
- });
221
- return {
222
- images: response.data.map((item) => item.b64_json),
223
- warnings,
224
- response: {
225
- timestamp: currentDate,
226
- modelId: this.modelId,
227
- headers: responseHeaders
228
- }
229
- };
230
- }
231
- };
232
- var togetheraiImageResponseSchema = z3.object({
233
- data: z3.array(
234
- z3.object({
235
- b64_json: z3.string()
236
- })
237
- )
238
- });
239
- var togetheraiErrorSchema2 = z3.object({
240
- error: z3.object({
241
- message: z3.string()
242
- })
243
- });
244
- var togetheraiImageModelOptionsSchema = lazySchema3(
245
- () => zodSchema3(
246
- z3.object({
247
- /**
248
- * Number of generation steps. Higher values can improve quality.
249
- */
250
- steps: z3.number().nullish(),
251
- /**
252
- * Guidance scale for image generation.
253
- */
254
- guidance: z3.number().nullish(),
255
- /**
256
- * Negative prompt to guide what to avoid.
257
- */
258
- negative_prompt: z3.string().nullish(),
259
- /**
260
- * Disable the safety checker for image generation.
261
- * When true, the API will not reject images flagged as potentially NSFW.
262
- * Not available for Flux Schnell Free and Flux Pro models.
263
- */
264
- disable_safety_checker: z3.boolean().nullish()
265
- }).passthrough()
266
- )
267
- );
268
-
269
- // src/version.ts
270
- var VERSION = true ? "3.0.0-beta.4" : "0.0.0-test";
271
-
272
- // src/togetherai-provider.ts
273
- function loadDeprecatedApiKey() {
274
- if (typeof process === "undefined") {
275
- return void 0;
276
- }
277
- if (typeof process.env.TOGETHER_API_KEY === "string") {
278
- return void 0;
279
- }
280
- const key = process.env.TOGETHER_AI_API_KEY;
281
- if (typeof key === "string") {
282
- console.warn(
283
- "TOGETHER_AI_API_KEY is deprecated and will be removed in a future release. Please use TOGETHER_API_KEY instead."
284
- );
285
- }
286
- return key;
287
- }
288
- function createTogetherAI(options = {}) {
289
- var _a;
290
- const baseURL = withoutTrailingSlash(
291
- (_a = options.baseURL) != null ? _a : "https://api.together.xyz/v1/"
292
- );
293
- const getHeaders = () => {
294
- var _a2;
295
- return withUserAgentSuffix(
296
- {
297
- Authorization: `Bearer ${loadApiKey({
298
- apiKey: (_a2 = options.apiKey) != null ? _a2 : loadDeprecatedApiKey(),
299
- environmentVariableName: "TOGETHER_API_KEY",
300
- description: "TogetherAI"
301
- })}`,
302
- ...options.headers
303
- },
304
- `ai-sdk/togetherai/${VERSION}`
305
- );
306
- };
307
- const getCommonModelConfig = (modelType) => ({
308
- provider: `togetherai.${modelType}`,
309
- url: ({ path }) => `${baseURL}${path}`,
310
- headers: getHeaders,
311
- fetch: options.fetch
312
- });
313
- const createChatModel = (modelId) => {
314
- return new OpenAICompatibleChatLanguageModel(
315
- modelId,
316
- getCommonModelConfig("chat")
317
- );
318
- };
319
- const createCompletionModel = (modelId) => new OpenAICompatibleCompletionLanguageModel(
320
- modelId,
321
- getCommonModelConfig("completion")
322
- );
323
- const createEmbeddingModel = (modelId) => new OpenAICompatibleEmbeddingModel(
324
- modelId,
325
- getCommonModelConfig("embedding")
326
- );
327
- const createImageModel = (modelId) => new TogetherAIImageModel(modelId, {
328
- ...getCommonModelConfig("image"),
329
- baseURL: baseURL != null ? baseURL : "https://api.together.xyz/v1/"
330
- });
331
- const createRerankingModel = (modelId) => new TogetherAIRerankingModel(modelId, {
332
- ...getCommonModelConfig("reranking"),
333
- baseURL: baseURL != null ? baseURL : "https://api.together.xyz/v1/"
334
- });
335
- const provider = (modelId) => createChatModel(modelId);
336
- provider.specificationVersion = "v4";
337
- provider.completionModel = createCompletionModel;
338
- provider.languageModel = createChatModel;
339
- provider.chatModel = createChatModel;
340
- provider.embeddingModel = createEmbeddingModel;
341
- provider.textEmbeddingModel = createEmbeddingModel;
342
- provider.image = createImageModel;
343
- provider.imageModel = createImageModel;
344
- provider.reranking = createRerankingModel;
345
- provider.rerankingModel = createRerankingModel;
346
- return provider;
347
- }
348
- var togetherai = createTogetherAI();
349
- export {
350
- VERSION,
351
- createTogetherAI,
352
- togetherai
353
- };
354
- //# sourceMappingURL=index.mjs.map