Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add gpt4o mini #347

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ export const OPENAI_CHAT_MODEL_COSTS = {
promptTokenCostInMillicents: 0.3,
completionTokenCostInMillicents: 0.4,
},
"gpt-4o": {
promptTokenCostInMillicents: 2,
completionTokenCostInMillicents: 4,
},
"gpt-4o-mini": {
promptTokenCostInMillicents: 0.015,
completionTokenCostInMillicents: 0.06,
},
} as const;

export type OpenAIChatResponse = {
Expand All @@ -86,6 +94,8 @@ export type OpenAIChatResponse = {
type FineTuneableOpenAIChatModelType =
| `gpt-3.5-turbo`
| `gpt-3.5-turbo-0613`
| `gpt-4o`
| `gpt-4o-mini`
| `gpt-4-0613`;

type FineTunedOpenAIChatModelType =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
export class MediaSourceAppender {
private readonly mediaSource = new MediaSource();
private readonly mediaSource = this.getMediaSource();
private readonly audioChunks: ArrayBuffer[] = [];

private sourceBuffer?: SourceBuffer;

private getMediaSource() {
const anyWindow = (window as any).X;

if (anyWindow.ManagedMediaSource) {
return new anyWindow.ManagedMediaSource();
}
if (anyWindow.MediaSource) {
return new anyWindow.MediaSource();
}

throw "No MediaSource API available";
}

constructor(type: string) {
this.mediaSource.addEventListener("sourceopen", async () => {
this.sourceBuffer = this.mediaSource.addSourceBuffer(type);

this.sourceBuffer.addEventListener("updateend", () => {
this.sourceBuffer?.addEventListener("updateend", () => {
this.tryAppendNextChunk();
});
});
Expand Down
14 changes: 12 additions & 2 deletions packages/modelfusion/src/model-provider/openai/OpenAIChatModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { countOpenAIChatPromptTokens } from "./countOpenAIChatMessageTokens";
// Open AI base chat models and their context window sizes.
export const CHAT_MODEL_CONTEXT_WINDOW_SIZES = {
"gpt-4": 8192,
"gpt-4o": 128000,
"gpt-4o-mini": 128000,
"gpt-4-0314": 8192,
"gpt-4-0613": 8192,
"gpt-4-turbo-preview": 128000,
Expand Down Expand Up @@ -66,7 +68,13 @@ export function getOpenAIChatModelInformation(model: OpenAIChatModelType): {
const [_, baseModel, ___, ____, _____] = model.split(":");

if (
["gpt-3.5-turbo", "gpt-3.5-turbo-0613", "gpt-4-0613"].includes(baseModel)
[
"gpt-3.5-turbo",
"gpt-3.5-turbo-0613",
"gpt-4-0613",
"gpt-4o",
"gpt-4o-mini",
].includes(baseModel)
) {
const contextWindowSize =
CHAT_MODEL_CONTEXT_WINDOW_SIZES[
Expand All @@ -86,7 +94,9 @@ export function getOpenAIChatModelInformation(model: OpenAIChatModelType): {
type FineTuneableOpenAIChatModelType =
| `gpt-3.5-turbo`
| `gpt-3.5-turbo-0613`
| `gpt-4-0613`;
| `gpt-4-0613`
| `gpt-4o`
| `gpt-4o-mini`;

type FineTunedOpenAIChatModelType =
`ft:${FineTuneableOpenAIChatModelType}:${string}:${string}:${string}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ function getTiktokenBPE(
case "gpt-3.5-turbo-16k-0613":
case "gpt-3.5-turbo-instruct":
case "gpt-4":
case "gpt-4o":
case "gpt-4o-mini":
case "gpt-4-0314":
case "gpt-4-0613":
case "gpt-4-turbo-preview":
Expand Down
Loading