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