@ai-sdk/openai 1.3.10 → 1.3.12
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 +15 -0
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +112 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -2
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +35 -7
- package/internal/dist/index.d.ts +35 -7
- package/internal/dist/index.js +213 -112
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +213 -108
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1629,7 +1629,7 @@ import {
|
|
|
1629
1629
|
postFormDataToApi
|
|
1630
1630
|
} from "@ai-sdk/provider-utils";
|
|
1631
1631
|
import { z as z6 } from "zod";
|
|
1632
|
-
var
|
|
1632
|
+
var openAIProviderOptionsSchema = z6.object({
|
|
1633
1633
|
include: z6.array(z6.string()).nullish(),
|
|
1634
1634
|
language: z6.string().nullish(),
|
|
1635
1635
|
prompt: z6.string().nullish(),
|
|
@@ -1714,7 +1714,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1714
1714
|
const openAIOptions = parseProviderOptions({
|
|
1715
1715
|
provider: "openai",
|
|
1716
1716
|
providerOptions,
|
|
1717
|
-
schema:
|
|
1717
|
+
schema: openAIProviderOptionsSchema
|
|
1718
1718
|
});
|
|
1719
1719
|
const formData = new FormData();
|
|
1720
1720
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
@@ -2621,6 +2621,110 @@ var openaiTools = {
|
|
|
2621
2621
|
webSearchPreview: webSearchPreviewTool
|
|
2622
2622
|
};
|
|
2623
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
|
+
|
|
2624
2728
|
// src/openai-provider.ts
|
|
2625
2729
|
function createOpenAI(options = {}) {
|
|
2626
2730
|
var _a, _b, _c;
|
|
@@ -2669,6 +2773,12 @@ function createOpenAI(options = {}) {
|
|
|
2669
2773
|
headers: getHeaders,
|
|
2670
2774
|
fetch: options.fetch
|
|
2671
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
|
+
});
|
|
2672
2782
|
const createLanguageModel = (modelId, settings) => {
|
|
2673
2783
|
if (new.target) {
|
|
2674
2784
|
throw new Error(
|
|
@@ -2705,6 +2815,8 @@ function createOpenAI(options = {}) {
|
|
|
2705
2815
|
provider.imageModel = createImageModel;
|
|
2706
2816
|
provider.transcription = createTranscriptionModel;
|
|
2707
2817
|
provider.transcriptionModel = createTranscriptionModel;
|
|
2818
|
+
provider.speech = createSpeechModel;
|
|
2819
|
+
provider.speechModel = createSpeechModel;
|
|
2708
2820
|
provider.tools = openaiTools;
|
|
2709
2821
|
return provider;
|
|
2710
2822
|
}
|