@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 +10 -0
- package/dist/index.js +16 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -21
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.js +16 -21
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +16 -21
- package/internal/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/internal/dist/index.mjs
CHANGED
|
@@ -1697,7 +1697,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1697
1697
|
}
|
|
1698
1698
|
getArgs({
|
|
1699
1699
|
audio,
|
|
1700
|
-
|
|
1700
|
+
mediaType,
|
|
1701
1701
|
providerOptions
|
|
1702
1702
|
}) {
|
|
1703
1703
|
const warnings = [];
|
|
@@ -1709,7 +1709,7 @@ var OpenAITranscriptionModel = class {
|
|
|
1709
1709
|
const formData = new FormData();
|
|
1710
1710
|
const blob = audio instanceof Uint8Array ? new Blob([audio]) : new Blob([convertBase64ToUint8Array(audio)]);
|
|
1711
1711
|
formData.append("model", this.modelId);
|
|
1712
|
-
formData.append("file", new File([blob], "audio", { type:
|
|
1712
|
+
formData.append("file", new File([blob], "audio", { type: mediaType }));
|
|
1713
1713
|
if (openAIOptions) {
|
|
1714
1714
|
const transcriptionModelOptions = {
|
|
1715
1715
|
include: openAIOptions.include,
|
|
@@ -1731,10 +1731,14 @@ var OpenAITranscriptionModel = class {
|
|
|
1731
1731
|
};
|
|
1732
1732
|
}
|
|
1733
1733
|
async doGenerate(options) {
|
|
1734
|
-
var _a, _b, _c;
|
|
1734
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1735
1735
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1736
1736
|
const { formData, warnings } = this.getArgs(options);
|
|
1737
|
-
const {
|
|
1737
|
+
const {
|
|
1738
|
+
value: response,
|
|
1739
|
+
responseHeaders,
|
|
1740
|
+
rawValue: rawResponse
|
|
1741
|
+
} = await postFormDataToApi({
|
|
1738
1742
|
url: this.config.url({
|
|
1739
1743
|
path: "/audio/transcriptions",
|
|
1740
1744
|
modelId: this.modelId
|
|
@@ -1748,46 +1752,37 @@ var OpenAITranscriptionModel = class {
|
|
|
1748
1752
|
abortSignal: options.abortSignal,
|
|
1749
1753
|
fetch: this.config.fetch
|
|
1750
1754
|
});
|
|
1751
|
-
|
|
1752
|
-
if (response.language && response.language in languageMap) {
|
|
1753
|
-
language = languageMap[response.language];
|
|
1754
|
-
}
|
|
1755
|
+
const language = response.language != null && response.language in languageMap ? languageMap[response.language] : void 0;
|
|
1755
1756
|
return {
|
|
1756
1757
|
text: response.text,
|
|
1757
|
-
segments: response.words.map((word) => ({
|
|
1758
|
+
segments: (_e = (_d = response.words) == null ? void 0 : _d.map((word) => ({
|
|
1758
1759
|
text: word.word,
|
|
1759
1760
|
startSecond: word.start,
|
|
1760
1761
|
endSecond: word.end
|
|
1761
|
-
})),
|
|
1762
|
+
}))) != null ? _e : [],
|
|
1762
1763
|
language,
|
|
1763
|
-
durationInSeconds: response.duration,
|
|
1764
|
+
durationInSeconds: (_f = response.duration) != null ? _f : void 0,
|
|
1764
1765
|
warnings,
|
|
1765
1766
|
response: {
|
|
1766
1767
|
timestamp: currentDate,
|
|
1767
1768
|
modelId: this.modelId,
|
|
1768
1769
|
headers: responseHeaders,
|
|
1769
|
-
body:
|
|
1770
|
-
},
|
|
1771
|
-
// When using format `verbose_json` on `whisper-1`, OpenAI includes the things like `task` and enhanced `segments` information.
|
|
1772
|
-
providerMetadata: {
|
|
1773
|
-
openai: {
|
|
1774
|
-
transcript: response
|
|
1775
|
-
}
|
|
1770
|
+
body: rawResponse
|
|
1776
1771
|
}
|
|
1777
1772
|
};
|
|
1778
1773
|
}
|
|
1779
1774
|
};
|
|
1780
1775
|
var openaiTranscriptionResponseSchema = z6.object({
|
|
1781
1776
|
text: z6.string(),
|
|
1782
|
-
language: z6.string().
|
|
1783
|
-
duration: z6.number().
|
|
1777
|
+
language: z6.string().nullish(),
|
|
1778
|
+
duration: z6.number().nullish(),
|
|
1784
1779
|
words: z6.array(
|
|
1785
1780
|
z6.object({
|
|
1786
1781
|
word: z6.string(),
|
|
1787
1782
|
start: z6.number(),
|
|
1788
1783
|
end: z6.number()
|
|
1789
1784
|
})
|
|
1790
|
-
)
|
|
1785
|
+
).nullish()
|
|
1791
1786
|
});
|
|
1792
1787
|
|
|
1793
1788
|
// src/responses/openai-responses-language-model.ts
|