@ai-sdk/openai 1.3.8 → 1.3.9

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,15 @@
1
1
  # @ai-sdk/openai
2
2
 
3
+ ## 1.3.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 013faa8: core (ai): change transcription model mimeType to mediaType
8
+ - 013faa8: fix (provider/openai): increase transcription model resilience
9
+ - Updated dependencies [013faa8]
10
+ - @ai-sdk/provider@1.1.2
11
+ - @ai-sdk/provider-utils@2.2.6
12
+
3
13
  ## 1.3.8
4
14
 
5
15
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1687,7 +1687,7 @@ var OpenAITranscriptionModel = class {
1687
1687
  }
1688
1688
  getArgs({
1689
1689
  audio,
1690
- mimeType,
1690
+ mediaType,
1691
1691
  providerOptions
1692
1692
  }) {
1693
1693
  const warnings = [];
@@ -1699,7 +1699,7 @@ var OpenAITranscriptionModel = class {
1699
1699
  const formData = new FormData();
1700
1700
  const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([(0, import_provider_utils7.convertBase64ToUint8Array)(audio)]);
1701
1701
  formData.append("model", this.modelId);
1702
- formData.append("file", new File([blob], "audio", { type: mimeType }));
1702
+ formData.append("file", new File([blob], "audio", { type: mediaType }));
1703
1703
  if (openAIOptions) {
1704
1704
  const transcriptionModelOptions = {
1705
1705
  include: openAIOptions.include,
@@ -1721,10 +1721,14 @@ var OpenAITranscriptionModel = class {
1721
1721
  };
1722
1722
  }
1723
1723
  async doGenerate(options) {
1724
- var _a, _b, _c;
1724
+ var _a, _b, _c, _d, _e, _f;
1725
1725
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1726
1726
  const { formData, warnings } = this.getArgs(options);
1727
- const { value: response, responseHeaders } = await (0, import_provider_utils7.postFormDataToApi)({
1727
+ const {
1728
+ value: response,
1729
+ responseHeaders,
1730
+ rawValue: rawResponse
1731
+ } = await (0, import_provider_utils7.postFormDataToApi)({
1728
1732
  url: this.config.url({
1729
1733
  path: "/audio/transcriptions",
1730
1734
  modelId: this.modelId
@@ -1738,46 +1742,37 @@ var OpenAITranscriptionModel = class {
1738
1742
  abortSignal: options.abortSignal,
1739
1743
  fetch: this.config.fetch
1740
1744
  });
1741
- let language;
1742
- if (response.language && response.language in languageMap) {
1743
- language = languageMap[response.language];
1744
- }
1745
+ const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
1745
1746
  return {
1746
1747
  text: response.text,
1747
- segments: response.words.map((word) => ({
1748
+ segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
1748
1749
  text: word.word,
1749
1750
  startSecond: word.start,
1750
1751
  endSecond: word.end
1751
- })),
1752
+ }))) != null ? _e : [],
1752
1753
  language,
1753
- durationInSeconds: response.duration,
1754
+ durationInSeconds: (_f = response.duration) != null ? _f : void 0,
1754
1755
  warnings,
1755
1756
  response: {
1756
1757
  timestamp: currentDate,
1757
1758
  modelId: this.modelId,
1758
1759
  headers: responseHeaders,
1759
- body: response
1760
- },
1761
- // When using format `verbose_json` on `whisper-1`, OpenAI includes the things like `task` and enhanced `segments` information.
1762
- providerMetadata: {
1763
- openai: {
1764
- transcript: response
1765
- }
1760
+ body: rawResponse
1766
1761
  }
1767
1762
  };
1768
1763
  }
1769
1764
  };
1770
1765
  var openaiTranscriptionResponseSchema = import_zod6.z.object({
1771
1766
  text: import_zod6.z.string(),
1772
- language: import_zod6.z.string().optional(),
1773
- duration: import_zod6.z.number().optional(),
1767
+ language: import_zod6.z.string().nullish(),
1768
+ duration: import_zod6.z.number().nullish(),
1774
1769
  words: import_zod6.z.array(
1775
1770
  import_zod6.z.object({
1776
1771
  word: import_zod6.z.string(),
1777
1772
  start: import_zod6.z.number(),
1778
1773
  end: import_zod6.z.number()
1779
1774
  })
1780
- )
1775
+ ).nullish()
1781
1776
  });
1782
1777
 
1783
1778
  // src/responses/openai-responses-language-model.ts