forked from hoangvvo/llm-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into feature-sc-64229-ll…
…m-sdk-support-audio-id-for-openai
- Loading branch information
Showing
31 changed files
with
3,949 additions
and
6,353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import audioContext from "audio-context"; | ||
import decodeAudio from "audio-decode"; | ||
import play from "audio-play"; | ||
import { openaiAudioModel } from "./model.js"; | ||
|
||
const response = await openaiAudioModel.generate({ | ||
extra: { | ||
audio: { | ||
voice: "alloy", | ||
format: "mp3", | ||
}, | ||
}, | ||
modalities: ["text", "audio"], | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Is a golden retriever a good family dog?", | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
console.dir(response, { depth: null }); | ||
|
||
const response2 = await openaiAudioModel.generate({ | ||
extra: { | ||
audio: { | ||
voice: "alloy", | ||
format: "mp3", | ||
}, | ||
}, | ||
modalities: ["text", "audio"], | ||
messages: [ | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "Is a golden retriever a good family dog?", | ||
}, | ||
], | ||
}, | ||
{ | ||
role: "assistant", | ||
content: response.content, | ||
}, | ||
{ | ||
role: "user", | ||
content: [ | ||
{ | ||
type: "text", | ||
text: "What about a labrador?", | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
console.dir(response2, { depth: null }); | ||
|
||
const audioPart2 = response2.content.find((part) => part.type === "audio"); | ||
|
||
if (audioPart2) { | ||
const audioBuffer2 = await decodeAudio( | ||
Buffer.from(audioPart2.audioData, "base64"), | ||
); | ||
const playback2 = play( | ||
audioBuffer2, | ||
{ | ||
// @ts-expect-error: it works ok? | ||
context: audioContext, | ||
}, | ||
() => {}, | ||
); | ||
playback2.play(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { copyFile, writeFile } from "fs/promises"; | ||
import { compileFromFile } from "json-schema-to-typescript"; | ||
import { join } from "path"; | ||
|
||
const __dirname = import.meta.dirname; | ||
|
||
const originalSchemaPath = join(__dirname, "..", "schema", "schema.json"); | ||
|
||
await copyFile( | ||
originalSchemaPath, | ||
join(__dirname, "src", "schema", "schema.json"), | ||
); | ||
|
||
// Generate typescript | ||
const ts = await compileFromFile(originalSchemaPath, { | ||
bannerComment: false, | ||
unreachableDefinitions: true, | ||
}); | ||
await writeFile(join(__dirname, "src", "schema", "schema.ts"), ts); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.