@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.
package/dist/index.mjs CHANGED
@@ -526,6 +526,15 @@ var OpenAIChatLanguageModel = class {
526
526
  }
527
527
  baseArgs.max_tokens = void 0;
528
528
  }
529
+ } else if (this.modelId.startsWith("gpt-4o-search-preview")) {
530
+ if (baseArgs.temperature != null) {
531
+ baseArgs.temperature = void 0;
532
+ warnings.push({
533
+ type: "unsupported-setting",
534
+ setting: "temperature",
535
+ details: "temperature is not supported for the gpt-4o-search-preview model and has been removed."
536
+ });
537
+ }
529
538
  }
530
539
  switch (type) {
531
540
  case "regular": {
@@ -1621,17 +1630,11 @@ import {
1621
1630
  } from "@ai-sdk/provider-utils";
1622
1631
  import { z as z6 } from "zod";
1623
1632
  var OpenAIProviderOptionsSchema = z6.object({
1624
- include: z6.array(z6.string()).optional().describe(
1625
- "Additional information to include in the transcription response."
1626
- ),
1627
- language: z6.string().optional().describe("The language of the input audio in ISO-639-1 format."),
1628
- prompt: z6.string().optional().describe(
1629
- "An optional text to guide the model's style or continue a previous audio segment."
1630
- ),
1631
- temperature: z6.number().min(0).max(1).optional().default(0).describe("The sampling temperature, between 0 and 1."),
1632
- timestampGranularities: z6.array(z6.enum(["word", "segment"])).optional().default(["segment"]).describe(
1633
- "The timestamp granularities to populate for this transcription."
1634
- )
1633
+ include: z6.array(z6.string()).nullish(),
1634
+ language: z6.string().nullish(),
1635
+ prompt: z6.string().nullish(),
1636
+ temperature: z6.number().min(0).max(1).nullish().default(0),
1637
+ timestampGranularities: z6.array(z6.enum(["word", "segment"])).nullish().default(["segment"])
1635
1638
  });
1636
1639
  var languageMap = {
1637
1640
  afrikaans: "af",
@@ -1703,9 +1706,10 @@ var OpenAITranscriptionModel = class {
1703
1706
  }
1704
1707
  getArgs({
1705
1708
  audio,
1706
- mimeType,
1709
+ mediaType,
1707
1710
  providerOptions
1708
1711
  }) {
1712
+ var _a, _b, _c, _d, _e;
1709
1713
  const warnings = [];
1710
1714
  const openAIOptions = parseProviderOptions({
1711
1715
  provider: "openai",
@@ -1715,19 +1719,19 @@ var OpenAITranscriptionModel = class {
1715
1719
  const formData = new FormData();
1716
1720
  const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
1717
1721
  formData.append("model", this.modelId);
1718
- formData.append("file", new File([blob], "audio", { type: mimeType }));
1722
+ formData.append("file", new File([blob], "audio", { type: mediaType }));
1719
1723
  if (openAIOptions) {
1720
1724
  const transcriptionModelOptions = {
1721
- include: openAIOptions.include,
1722
- language: openAIOptions.language,
1723
- prompt: openAIOptions.prompt,
1724
- temperature: openAIOptions.temperature,
1725
- timestamp_granularities: openAIOptions.timestampGranularities
1725
+ include: (_a = openAIOptions.include) != null ? _a : void 0,
1726
+ language: (_b = openAIOptions.language) != null ? _b : void 0,
1727
+ prompt: (_c = openAIOptions.prompt) != null ? _c : void 0,
1728
+ temperature: (_d = openAIOptions.temperature) != null ? _d : void 0,
1729
+ timestamp_granularities: (_e = openAIOptions.timestampGranularities) != null ? _e : void 0
1726
1730
  };
1727
1731
  for (const key in transcriptionModelOptions) {
1728
1732
  const value = transcriptionModelOptions[key];
1729
1733
  if (value !== void 0) {
1730
- formData.append(key, value);
1734
+ formData.append(key, String(value));
1731
1735
  }
1732
1736
  }
1733
1737
  }
@@ -1737,10 +1741,14 @@ var OpenAITranscriptionModel = class {
1737
1741
  };
1738
1742
  }
1739
1743
  async doGenerate(options) {
1740
- var _a, _b, _c;
1744
+ var _a, _b, _c, _d, _e, _f;
1741
1745
  const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
1742
1746
  const { formData, warnings } = this.getArgs(options);
1743
- const { value: response, responseHeaders } = await postFormDataToApi({
1747
+ const {
1748
+ value: response,
1749
+ responseHeaders,
1750
+ rawValue: rawResponse
1751
+ } = await postFormDataToApi({
1744
1752
  url: this.config.url({
1745
1753
  path: "/audio/transcriptions",
1746
1754
  modelId: this.modelId
@@ -1754,46 +1762,37 @@ var OpenAITranscriptionModel = class {
1754
1762
  abortSignal: options.abortSignal,
1755
1763
  fetch: this.config.fetch
1756
1764
  });
1757
- let language;
1758
- if (response.language && response.language in languageMap) {
1759
- language = languageMap[response.language];
1760
- }
1765
+ const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
1761
1766
  return {
1762
1767
  text: response.text,
1763
- segments: response.words.map((word) => ({
1768
+ segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
1764
1769
  text: word.word,
1765
1770
  startSecond: word.start,
1766
1771
  endSecond: word.end
1767
- })),
1772
+ }))) != null ? _e : [],
1768
1773
  language,
1769
- durationInSeconds: response.duration,
1774
+ durationInSeconds: (_f = response.duration) != null ? _f : void 0,
1770
1775
  warnings,
1771
1776
  response: {
1772
1777
  timestamp: currentDate,
1773
1778
  modelId: this.modelId,
1774
1779
  headers: responseHeaders,
1775
- body: response
1776
- },
1777
- // When using format `verbose_json` on `whisper-1`, OpenAI includes the things like `task` and enhanced `segments` information.
1778
- providerMetadata: {
1779
- openai: {
1780
- transcript: response
1781
- }
1780
+ body: rawResponse
1782
1781
  }
1783
1782
  };
1784
1783
  }
1785
1784
  };
1786
1785
  var openaiTranscriptionResponseSchema = z6.object({
1787
1786
  text: z6.string(),
1788
- language: z6.string().optional(),
1789
- duration: z6.number().optional(),
1787
+ language: z6.string().nullish(),
1788
+ duration: z6.number().nullish(),
1790
1789
  words: z6.array(
1791
1790
  z6.object({
1792
1791
  word: z6.string(),
1793
1792
  start: z6.number(),
1794
1793
  end: z6.number()
1795
1794
  })
1796
- )
1795
+ ).nullish()
1797
1796
  });
1798
1797
 
1799
1798
  // src/responses/openai-responses-language-model.ts