@ai-sdk/openai 1.3.9 → 1.3.11

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": {
@@ -1620,18 +1629,12 @@ import {
1620
1629
  postFormDataToApi
1621
1630
  } from "@ai-sdk/provider-utils";
1622
1631
  import { z as z6 } from "zod";
1623
- 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
- )
1632
+ var openAIProviderOptionsSchema = z6.object({
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",
@@ -1706,11 +1709,12 @@ var OpenAITranscriptionModel = class {
1706
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",
1712
1716
  providerOptions,
1713
- schema: OpenAIProviderOptionsSchema
1717
+ schema: openAIProviderOptionsSchema
1714
1718
  });
1715
1719
  const formData = new FormData();
1716
1720
  const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
@@ -1718,16 +1722,16 @@ var OpenAITranscriptionModel = class {
1718
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
  }
@@ -2617,6 +2621,110 @@ var openaiTools = {
2617
2621
  webSearchPreview: webSearchPreviewTool
2618
2622
  };
2619
2623
 
2624
+ // src/openai-speech-model.ts
2625
+ import {
2626
+ combineHeaders as combineHeaders7,
2627
+ createBinaryResponseHandler,
2628
+ parseProviderOptions as parseProviderOptions3,
2629
+ postJsonToApi as postJsonToApi6
2630
+ } from "@ai-sdk/provider-utils";
2631
+ import { z as z9 } from "zod";
2632
+ var OpenAIProviderOptionsSchema = z9.object({
2633
+ instructions: z9.string().nullish(),
2634
+ speed: z9.number().min(0.25).max(4).default(1).nullish()
2635
+ });
2636
+ var OpenAISpeechModel = class {
2637
+ constructor(modelId, config) {
2638
+ this.modelId = modelId;
2639
+ this.config = config;
2640
+ this.specificationVersion = "v1";
2641
+ }
2642
+ get provider() {
2643
+ return this.config.provider;
2644
+ }
2645
+ getArgs({
2646
+ text,
2647
+ voice = "alloy",
2648
+ outputFormat = "mp3",
2649
+ speed,
2650
+ instructions,
2651
+ providerOptions
2652
+ }) {
2653
+ const warnings = [];
2654
+ const openAIOptions = parseProviderOptions3({
2655
+ provider: "openai",
2656
+ providerOptions,
2657
+ schema: OpenAIProviderOptionsSchema
2658
+ });
2659
+ const requestBody = {
2660
+ model: this.modelId,
2661
+ input: text,
2662
+ voice,
2663
+ response_format: "mp3",
2664
+ speed,
2665
+ instructions
2666
+ };
2667
+ if (outputFormat) {
2668
+ if (["mp3", "opus", "aac", "flac", "wav", "pcm"].includes(outputFormat)) {
2669
+ requestBody.response_format = outputFormat;
2670
+ } else {
2671
+ warnings.push({
2672
+ type: "unsupported-setting",
2673
+ setting: "outputFormat",
2674
+ details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
2675
+ });
2676
+ }
2677
+ }
2678
+ if (openAIOptions) {
2679
+ const speechModelOptions = {};
2680
+ for (const key in speechModelOptions) {
2681
+ const value = speechModelOptions[key];
2682
+ if (value !== void 0) {
2683
+ requestBody[key] = value;
2684
+ }
2685
+ }
2686
+ }
2687
+ return {
2688
+ requestBody,
2689
+ warnings
2690
+ };
2691
+ }
2692
+ async doGenerate(options) {
2693
+ var _a, _b, _c;
2694
+ const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
2695
+ const { requestBody, warnings } = this.getArgs(options);
2696
+ const {
2697
+ value: audio,
2698
+ responseHeaders,
2699
+ rawValue: rawResponse
2700
+ } = await postJsonToApi6({
2701
+ url: this.config.url({
2702
+ path: "/audio/speech",
2703
+ modelId: this.modelId
2704
+ }),
2705
+ headers: combineHeaders7(this.config.headers(), options.headers),
2706
+ body: requestBody,
2707
+ failedResponseHandler: openaiFailedResponseHandler,
2708
+ successfulResponseHandler: createBinaryResponseHandler(),
2709
+ abortSignal: options.abortSignal,
2710
+ fetch: this.config.fetch
2711
+ });
2712
+ return {
2713
+ audio,
2714
+ warnings,
2715
+ request: {
2716
+ body: JSON.stringify(requestBody)
2717
+ },
2718
+ response: {
2719
+ timestamp: currentDate,
2720
+ modelId: this.modelId,
2721
+ headers: responseHeaders,
2722
+ body: rawResponse
2723
+ }
2724
+ };
2725
+ }
2726
+ };
2727
+
2620
2728
  // src/openai-provider.ts
2621
2729
  function createOpenAI(options = {}) {
2622
2730
  var _a, _b, _c;
@@ -2665,6 +2773,12 @@ function createOpenAI(options = {}) {
2665
2773
  headers: getHeaders,
2666
2774
  fetch: options.fetch
2667
2775
  });
2776
+ const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
2777
+ provider: `${providerName}.speech`,
2778
+ url: ({ path }) => `${baseURL}${path}`,
2779
+ headers: getHeaders,
2780
+ fetch: options.fetch
2781
+ });
2668
2782
  const createLanguageModel = (modelId, settings) => {
2669
2783
  if (new.target) {
2670
2784
  throw new Error(
@@ -2701,6 +2815,8 @@ function createOpenAI(options = {}) {
2701
2815
  provider.imageModel = createImageModel;
2702
2816
  provider.transcription = createTranscriptionModel;
2703
2817
  provider.transcriptionModel = createTranscriptionModel;
2818
+ provider.speech = createSpeechModel;
2819
+ provider.speechModel = createSpeechModel;
2704
2820
  provider.tools = openaiTools;
2705
2821
  return provider;
2706
2822
  }