@ai-sdk/openai 1.3.8 → 1.3.10

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.
@@ -2,7 +2,7 @@ import { LanguageModelV1, EmbeddingModelV1, ImageModelV1, TranscriptionModelV1Ca
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
  import { z } from 'zod';
4
4
 
5
- type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
5
+ type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
6
6
  interface OpenAIChatSettings {
7
7
  /**
8
8
  Modify the likelihood of specified tokens appearing in the completion.
@@ -271,23 +271,23 @@ type OpenAITranscriptionModelOptions = {
271
271
  };
272
272
 
273
273
  declare const OpenAIProviderOptionsSchema: z.ZodObject<{
274
- include: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
275
- language: z.ZodOptional<z.ZodString>;
276
- prompt: z.ZodOptional<z.ZodString>;
277
- temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
278
- timestampGranularities: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodEnum<["word", "segment"]>, "many">>>;
274
+ include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
275
+ language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
276
+ prompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
277
+ temperature: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodNumber>>>;
278
+ timestampGranularities: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<["word", "segment"]>, "many">>>>;
279
279
  }, "strip", z.ZodTypeAny, {
280
- temperature: number;
281
- timestampGranularities: ("word" | "segment")[];
282
- prompt?: string | undefined;
283
- include?: string[] | undefined;
284
- language?: string | undefined;
280
+ temperature: number | null;
281
+ timestampGranularities: ("word" | "segment")[] | null;
282
+ prompt?: string | null | undefined;
283
+ include?: string[] | null | undefined;
284
+ language?: string | null | undefined;
285
285
  }, {
286
- prompt?: string | undefined;
287
- temperature?: number | undefined;
288
- include?: string[] | undefined;
289
- language?: string | undefined;
290
- timestampGranularities?: ("word" | "segment")[] | undefined;
286
+ prompt?: string | null | undefined;
287
+ temperature?: number | null | undefined;
288
+ include?: string[] | null | undefined;
289
+ language?: string | null | undefined;
290
+ timestampGranularities?: ("word" | "segment")[] | null | undefined;
291
291
  }>;
292
292
  type OpenAITranscriptionCallOptions = Omit<TranscriptionModelV1CallOptions, 'providerOptions'> & {
293
293
  providerOptions?: {
@@ -2,7 +2,7 @@ import { LanguageModelV1, EmbeddingModelV1, ImageModelV1, TranscriptionModelV1Ca
2
2
  import { FetchFunction } from '@ai-sdk/provider-utils';
3
3
  import { z } from 'zod';
4
4
 
5
- type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
5
+ type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o1-mini' | 'o1-mini-2024-09-12' | 'o1-preview' | 'o1-preview-2024-09-12' | 'o3-mini' | 'o3-mini-2025-01-31' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-10-01' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4-turbo' | 'gpt-4-turbo-2024-04-09' | 'gpt-4-turbo-preview' | 'gpt-4-0125-preview' | 'gpt-4-1106-preview' | 'gpt-4' | 'gpt-4-0613' | 'gpt-4.5-preview' | 'gpt-4.5-preview-2025-02-27' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'chatgpt-4o-latest' | (string & {});
6
6
  interface OpenAIChatSettings {
7
7
  /**
8
8
  Modify the likelihood of specified tokens appearing in the completion.
@@ -271,23 +271,23 @@ type OpenAITranscriptionModelOptions = {
271
271
  };
272
272
 
273
273
  declare const OpenAIProviderOptionsSchema: z.ZodObject<{
274
- include: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
275
- language: z.ZodOptional<z.ZodString>;
276
- prompt: z.ZodOptional<z.ZodString>;
277
- temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
278
- timestampGranularities: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodEnum<["word", "segment"]>, "many">>>;
274
+ include: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
275
+ language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
276
+ prompt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
277
+ temperature: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodNumber>>>;
278
+ timestampGranularities: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<["word", "segment"]>, "many">>>>;
279
279
  }, "strip", z.ZodTypeAny, {
280
- temperature: number;
281
- timestampGranularities: ("word" | "segment")[];
282
- prompt?: string | undefined;
283
- include?: string[] | undefined;
284
- language?: string | undefined;
280
+ temperature: number | null;
281
+ timestampGranularities: ("word" | "segment")[] | null;
282
+ prompt?: string | null | undefined;
283
+ include?: string[] | null | undefined;
284
+ language?: string | null | undefined;
285
285
  }, {
286
- prompt?: string | undefined;
287
- temperature?: number | undefined;
288
- include?: string[] | undefined;
289
- language?: string | undefined;
290
- timestampGranularities?: ("word" | "segment")[] | undefined;
286
+ prompt?: string | null | undefined;
287
+ temperature?: number | null | undefined;
288
+ include?: string[] | null | undefined;
289
+ language?: string | null | undefined;
290
+ timestampGranularities?: ("word" | "segment")[] | null | undefined;
291
291
  }>;
292
292
  type OpenAITranscriptionCallOptions = Omit<TranscriptionModelV1CallOptions, 'providerOptions'> & {
293
293
  providerOptions?: {
@@ -538,6 +538,15 @@ var OpenAIChatLanguageModel = class {
538
538
  }
539
539
  baseArgs.max_tokens = void 0;
540
540
  }
541
+ } else if (this.modelId.startsWith("gpt-4o-search-preview")) {
542
+ if (baseArgs.temperature != null) {
543
+ baseArgs.temperature = void 0;
544
+ warnings.push({
545
+ type: "unsupported-setting",
546
+ setting: "temperature",
547
+ details: "temperature is not supported for the gpt-4o-search-preview model and has been removed."
548
+ });
549
+ }
541
550
  }
542
551
  switch (type) {
543
552
  case "regular": {
@@ -1607,17 +1616,11 @@ var openaiImageResponseSchema = import_zod5.z.object({
1607
1616
  var import_provider_utils7 = require("@ai-sdk/provider-utils");
1608
1617
  var import_zod6 = require("zod");
1609
1618
  var OpenAIProviderOptionsSchema = import_zod6.z.object({
1610
- include: import_zod6.z.array(import_zod6.z.string()).optional().describe(
1611
- "Additional information to include in the transcription response."
1612
- ),
1613
- language: import_zod6.z.string().optional().describe("The language of the input audio in ISO-639-1 format."),
1614
- prompt: import_zod6.z.string().optional().describe(
1615
- "An optional text to guide the model's style or continue a previous audio segment."
1616
- ),
1617
- temperature: import_zod6.z.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
1618
- timestampGranularities: import_zod6.z.array(import_zod6.z.enum(["word", "segment"])).optional().default(["segment"]).describe(
1619
- "The timestamp granularities to populate for this transcription."
1620
- )
1619
+ include: import_zod6.z.array(import_zod6.z.string()).nullish(),
1620
+ language: import_zod6.z.string().nullish(),
1621
+ prompt: import_zod6.z.string().nullish(),
1622
+ temperature: import_zod6.z.number().min(0).max(1).nullish().default(0),
1623
+ timestampGranularities: import_zod6.z.array(import_zod6.z.enum(["word", "segment"])).nullish().default(["segment"])
1621
1624
  });
1622
1625
  var languageMap = {
1623
1626
  afrikaans: "af",
@@ -1689,9 +1692,10 @@ var OpenAITranscriptionModel = class {
1689
1692
  }
1690
1693
  getArgs({
1691
1694
  audio,
1692
- mimeType,
1695
+ mediaType,
1693
1696
  providerOptions
1694
1697
  }) {
1698
+ var _a, _b, _c, _d, _e;
1695
1699
  const warnings = [];
1696
1700
  const openAIOptions = (0, import_provider_utils7.parseProviderOptions)({
1697
1701
  provider: "openai",
@@ -1701,19 +1705,19 @@ var OpenAITranscriptionModel = class {
1701
1705
  const formData = new FormData();
1702
1706
  const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
1703
1707
  formData.append("model", this.modelId);
1704
- formData.append("file", new File([blob], "audio", { type: mimeType }));
1708
+ formData.append("file", new File([blob], "audio", { type: mediaType }));
1705
1709
  if (openAIOptions) {
1706
1710
  const transcriptionModelOptions = {
1707
- include: openAIOptions.include,
1708
- language: openAIOptions.language,
1709
- prompt: openAIOptions.prompt,
1710
- temperature: openAIOptions.temperature,
1711
- timestamp_granularities: openAIOptions.timestampGranularities
1711
+ include: (_a = openAIOptions.include) != null ? _a : void 0,
1712
+ language: (_b = openAIOptions.language) != null ? _b : void 0,
1713
+ prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
1714
+ temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
1715
+ timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
1712
1716
  };
1713
1717
  for (const key in transcriptionModelOptions) {
1714
1718
  const value = transcriptionModelOptions[key];
1715
1719
  if (value !== void 0) {
1716
- formData.append(key, value);
1720
+ formData.append(key, String(value));
1717
1721
  }
1718
1722
  }
1719
1723
  }
@@ -1723,10 +1727,14 @@ var OpenAITranscriptionModel = class {
1723
1727
  };
1724
1728
  }
1725
1729
  async doGenerate(options) {
1726
- var _a, _b, _c;
1730
+ var _a, _b, _c, _d, _e, _f;
1727
1731
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1728
1732
  const { formData, warnings } = this.getArgs(options);
1729
- const { value: response, responseHeaders } = await (0, import_provider_utils7.postFormDataToApi)({
1733
+ const {
1734
+ value: response,
1735
+ responseHeaders,
1736
+ rawValue: rawResponse
1737
+ } = await (0, import_provider_utils7.postFormDataToApi)({
1730
1738
  url: this.config.url({
1731
1739
  path: "/audio/transcriptions",
1732
1740
  modelId: this.modelId
@@ -1740,46 +1748,37 @@ var OpenAITranscriptionModel = class {
1740
1748
  abortSignal: options.abortSignal,
1741
1749
  fetch: this.config.fetch
1742
1750
  });
1743
- let language;
1744
- if (response.language && response.language in languageMap) {
1745
- language = languageMap[response.language];
1746
- }
1751
+ const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
1747
1752
  return {
1748
1753
  text: response.text,
1749
- segments: response.words.map((word) => ({
1754
+ segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
1750
1755
  text: word.word,
1751
1756
  startSecond: word.start,
1752
1757
  endSecond: word.end
1753
- })),
1758
+ }))) != null ? _e : [],
1754
1759
  language,
1755
- durationInSeconds: response.duration,
1760
+ durationInSeconds: (_f = response.duration) != null ? _f : void 0,
1756
1761
  warnings,
1757
1762
  response: {
1758
1763
  timestamp: currentDate,
1759
1764
  modelId: this.modelId,
1760
1765
  headers: responseHeaders,
1761
- body: response
1762
- },
1763
- // When using format `verbose_json` on `whisper-1`, OpenAI includes the things like `task` and enhanced `segments` information.
1764
- providerMetadata: {
1765
- openai: {
1766
- transcript: response
1767
- }
1766
+ body: rawResponse
1768
1767
  }
1769
1768
  };
1770
1769
  }
1771
1770
  };
1772
1771
  var openaiTranscriptionResponseSchema = import_zod6.z.object({
1773
1772
  text: import_zod6.z.string(),
1774
- language: import_zod6.z.string().optional(),
1775
- duration: import_zod6.z.number().optional(),
1773
+ language: import_zod6.z.string().nullish(),
1774
+ duration: import_zod6.z.number().nullish(),
1776
1775
  words: import_zod6.z.array(
1777
1776
  import_zod6.z.object({
1778
1777
  word: import_zod6.z.string(),
1779
1778
  start: import_zod6.z.number(),
1780
1779
  end: import_zod6.z.number()
1781
1780
  })
1782
- )
1781
+ ).nullish()
1783
1782
  });
1784
1783
 
1785
1784
  // src/responses/openai-responses-language-model.ts