Skip to content

Commit

Permalink
feat: init support openai o1 model (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
himself65 authored Sep 12, 2024
1 parent 68ac7fd commit 5d2111a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/llamaindex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"md-utils-ts": "^2.0.0",
"mongodb": "^6.7.0",
"notion-md-crawler": "^1.0.0",
"openai": "^4.57.0",
"openai": "^4.60.0",
"papaparse": "^5.4.1",
"pathe": "^1.1.2",
"portkey-ai": "0.1.16",
Expand Down
22 changes: 21 additions & 1 deletion packages/llamaindex/src/llm/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export function getOpenAISession(
}

export const GPT4_MODELS = {
"chatgpt-4o-latest": {
contextWindow: 128000,
},
"gpt-4": { contextWindow: 8192 },
"gpt-4-32k": { contextWindow: 32768 },
"gpt-4-32k-0613": { contextWindow: 32768 },
Expand Down Expand Up @@ -129,12 +132,28 @@ export const GPT35_MODELS = {
"gpt-3.5-turbo-0301": { contextWindow: 16385 },
};

export const O1_MODELS = {
"o1-preview": {
contextWindow: 128000,
},
"o1-preview-2024-09-12": {
contextWindow: 128000,
},
"o1-mini": {
contextWindow: 128000,
},
"o1-mini-2024-09-12": {
contextWindow: 128000,
},
};

/**
* We currently support GPT-3.5 and GPT-4 models
*/
export const ALL_AVAILABLE_OPENAI_MODELS = {
...GPT4_MODELS,
...GPT35_MODELS,
...O1_MODELS,
} satisfies Record<ChatModel, { contextWindow: number }>;

export function isFunctionCallingModel(llm: LLM): llm is OpenAI {
Expand All @@ -148,7 +167,8 @@ export function isFunctionCallingModel(llm: LLM): llm is OpenAI {
}
const isChatModel = Object.keys(ALL_AVAILABLE_OPENAI_MODELS).includes(model);
const isOld = model.includes("0314") || model.includes("0301");
return isChatModel && !isOld;
const isO1 = model.startsWith("o1");
return isChatModel && !isOld && !isO1;
}

export type OpenAIAdditionalMetadata = {};
Expand Down
67 changes: 51 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5d2111a

Please sign in to comment.