Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature-sc-64229-ll…
Browse files Browse the repository at this point in the history
…m-sdk-support-audio-id-for-openai
  • Loading branch information
hoangvvo committed Dec 6, 2024
2 parents cf24deb + 681e7e8 commit 107c627
Show file tree
Hide file tree
Showing 31 changed files with 3,949 additions and 6,353 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A unified LLM API.

## Specification

The specification serves as the basis to implement the unified LLM SDK in different programming languages. The specification is expressed using JSON schema and can be found in [openapi.json](../schemas/openapi.json).
The specification serves as the basis to implement the unified LLM SDK in different programming languages. The specification is expressed using JSON schema and can be found in [schema.json](../schema/schema.json).

Implementations in different programming languages should adhere to this specification but may adapt it to the idioms of the respective language or provide additional functionalities.

Expand Down
2 changes: 1 addition & 1 deletion javascript/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default [
globals: { ...globals.browser, ...globals.node },
parserOptions: {
projectService: {
allowDefaultProject: ["*.js", "*.mjs", "openapi-ts.config.ts"],
allowDefaultProject: ["*.js", "*.mjs"],
},
tsconfigRootDir: import.meta.dirname,
},
Expand Down
80 changes: 80 additions & 0 deletions javascript/examples/generate-audio-multiturn.ts
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();
}
19 changes: 19 additions & 0 deletions javascript/generate.js
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);
12 changes: 0 additions & 12 deletions javascript/openapi-ts.config.ts

This file was deleted.

21 changes: 16 additions & 5 deletions javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"type": "module",
"name": "@firefliesai/llm-sdk",
"version": "0.1.6",
"version": "0.1.7",
"description": "A unified LLM SDK",
"scripts": {
"generate": "npx @hey-api/openapi-ts",
"build": "tshy",
"generate": "node generate.js",
"build": "tshy && cp src/schema/schema.json dist/esm/schema/schema.json && cp src/schema/schema.json dist/commonjs/schema/schema.json",
"lint": "eslint src",
"test": "tsx --test --experimental-test-coverage --env-file=../.env \"**/*.test.ts\""
},
Expand Down Expand Up @@ -83,7 +83,17 @@
"default": "./dist/commonjs/utils/index.js"
}
},
"./package.json": "./package.json"
"./package.json": "./package.json",
"./schema/schema.json": {
"import": {
"types": "./dist/esm/schema/schema.json",
"default": "./dist/esm/schema/schema.json"
},
"require": {
"types": "./dist/commonjs/schema/schema.json",
"default": "./dist/commonjs/schema/schema.json"
}
}
},
"main": "./dist/commonjs/index.js",
"types": "./dist/commonjs/index.d.ts",
Expand All @@ -108,7 +118,8 @@
"./cohere": "./src/cohere/index.ts",
"./mistral": "./src/mistral/index.ts",
"./utils": "./src/utils/index.ts",
"./package.json": "./package.json"
"./package.json": "./package.json",
"./schema/schema.json": "./src/schema/schema.json"
},
"project": "tsconfig.build.json"
},
Expand Down
Loading

0 comments on commit 107c627

Please sign in to comment.