From 1fc69a3c6a5e29fae9ee738be4cf0b0561e86810 Mon Sep 17 00:00:00 2001 From: Henry Fontanier Date: Mon, 23 Dec 2024 11:33:00 +0100 Subject: [PATCH] feat: add support for o1 high reasoning --- front/lib/api/assistant/agent.ts | 3 ++ front/lib/api/assistant/global_agents.ts | 54 +++++++++++++++++++++++- sdks/js/src/types.ts | 1 + types/src/front/lib/assistant.ts | 26 +++++++++++- types/src/shared/feature_flags.ts | 1 + 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/front/lib/api/assistant/agent.ts b/front/lib/api/assistant/agent.ts index f3774019603d..94f2848afba9 100644 --- a/front/lib/api/assistant/agent.ts +++ b/front/lib/api/assistant/agent.ts @@ -492,6 +492,9 @@ async function* runMultiActionsAgent( config.MODEL.provider_id = model.providerId; config.MODEL.model_id = model.modelId; config.MODEL.temperature = agentConfiguration.model.temperature; + if (agentConfiguration.model.reasoningEffort) { + config.MODEL.reasoning_effort = agentConfiguration.model.reasoningEffort; + } const res = await runActionStreamed( auth, diff --git a/front/lib/api/assistant/global_agents.ts b/front/lib/api/assistant/global_agents.ts index 846aef1b058f..93a4092fda42 100644 --- a/front/lib/api/assistant/global_agents.ts +++ b/front/lib/api/assistant/global_agents.ts @@ -29,6 +29,7 @@ import { MISTRAL_LARGE_MODEL_CONFIG, MISTRAL_MEDIUM_MODEL_CONFIG, MISTRAL_SMALL_MODEL_CONFIG, + O1_HIGH_REASONING_MODEL_CONFIG, O1_MINI_MODEL_CONFIG, O1_MODEL_CONFIG, } from "@dust-tt/types"; @@ -308,7 +309,7 @@ function _getGPT4GlobalAgent({ requestedGroupIds: [], }; } -function _getO1PreviewGlobalAgent({ +function _getO1GlobalAgent({ auth, settings, }: { @@ -387,6 +388,47 @@ function _getO1MiniGlobalAgent({ }; } +function _getO1HighReasoningGlobalAgent({ + auth, + settings, +}: { + auth: Authenticator; + settings: GlobalAgentSettings | null; +}): AgentConfigurationType { + let status = settings?.status ?? "active"; + if (!auth.isUpgraded()) { + status = "disabled_free_workspace"; + } + + return { + id: -1, + sId: GLOBAL_AGENTS_SID.O1_HIGH_REASONING, + version: 0, + versionCreatedAt: null, + versionAuthorId: null, + name: "o1-high-reasoning", + description: O1_HIGH_REASONING_MODEL_CONFIG.description, + instructions: null, + pictureUrl: "https://dust.tt/static/systemavatar/o1_avatar_full.png", + status, + scope: "global", + userFavorite: false, + model: { + providerId: O1_HIGH_REASONING_MODEL_CONFIG.providerId, + modelId: O1_HIGH_REASONING_MODEL_CONFIG.modelId, + temperature: 1, // 1 is forced for O1 + reasoningEffort: O1_HIGH_REASONING_MODEL_CONFIG.reasoningEffort, + }, + actions: [], + maxStepsPerRun: 3, + visualizationEnabled: false, + templateId: null, + // TODO(2024-11-04 flav) `groupId` clean-up. + groupIds: [], + requestedGroupIds: [], + }; +} + function _getClaudeInstantGlobalAgent({ settings, }: { @@ -1228,11 +1270,14 @@ function getGlobalAgent( agentConfiguration = _getGPT4GlobalAgent({ auth, settings }); break; case GLOBAL_AGENTS_SID.O1: - agentConfiguration = _getO1PreviewGlobalAgent({ auth, settings }); + agentConfiguration = _getO1GlobalAgent({ auth, settings }); break; case GLOBAL_AGENTS_SID.O1_MINI: agentConfiguration = _getO1MiniGlobalAgent({ auth, settings }); break; + case GLOBAL_AGENTS_SID.O1_HIGH_REASONING: + agentConfiguration = _getO1HighReasoningGlobalAgent({ auth, settings }); + break; case GLOBAL_AGENTS_SID.CLAUDE_INSTANT: agentConfiguration = _getClaudeInstantGlobalAgent({ settings }); break; @@ -1388,6 +1433,11 @@ export async function getGlobalAgents( (sId) => sId !== GLOBAL_AGENTS_SID.O1_MINI ); } + if (!flags.includes("openai_o1_high_reasoning_feature")) { + agentsIdsToFetch = agentsIdsToFetch.filter( + (sId) => sId !== GLOBAL_AGENTS_SID.O1_HIGH_REASONING + ); + } // For now we retrieve them all // We will store them in the database later to allow admin enable them or not diff --git a/sdks/js/src/types.ts b/sdks/js/src/types.ts index 34945340b3a0..09f989994224 100644 --- a/sdks/js/src/types.ts +++ b/sdks/js/src/types.ts @@ -655,6 +655,7 @@ const WhitelistableFeaturesSchema = FlexibleEnumSchema< | "use_app_for_header_detection" | "openai_o1_feature" | "openai_o1_mini_feature" + | "openai_o1_high_reasoning_feature" | "snowflake_connector_feature" | "index_private_slack_channel" | "conversations_jit_actions" diff --git a/types/src/front/lib/assistant.ts b/types/src/front/lib/assistant.ts index 314fde0a0309..3b0c4b0afea9 100644 --- a/types/src/front/lib/assistant.ts +++ b/types/src/front/lib/assistant.ts @@ -1,4 +1,7 @@ -import { LightAgentConfigurationType } from "../../front/assistant/agent"; +import { + AgentReasoningEffort, + LightAgentConfigurationType, +} from "../../front/assistant/agent"; import { GenerationTokensEvent } from "../../front/assistant/generation"; import { WorkspaceType } from "../../front/user"; import { ExtractSpecificKeys } from "../../shared/typescipt_utils"; @@ -190,6 +193,9 @@ export type ModelConfigurationType = { toolUseMetaPrompt?: string; supportsVision: boolean; + + // Only used for O-series OpenAI models. + reasoningEffort?: AgentReasoningEffort; }; // Should be used for all Open AI models older than gpt-4o-2024-08-06 to prevent issues @@ -279,7 +285,22 @@ export const O1_MODEL_CONFIG: ModelConfigurationType = { "OpenAI's reasoning model designed to solve hard problems across domains (Limited preview access).", shortDescription: "OpenAI's reasoning model.", isLegacy: false, - supportsVision: false, + supportsVision: true, +}; +export const O1_HIGH_REASONING_MODEL_CONFIG: ModelConfigurationType = { + providerId: "openai", + modelId: O1_MODEL_ID, + displayName: "O1", + contextSize: 200_000, + recommendedTopK: 32, + recommendedExhaustiveTopK: 128, // 65_536 + largeModel: true, + description: + "OpenAI's reasoning model designed to solve hard problems across domains (Limited preview access). High reasoning effort.", + shortDescription: "OpenAI's reasoning model (high effort).", + isLegacy: false, + supportsVision: true, + reasoningEffort: "high", }; export const O1_MINI_MODEL_CONFIG: ModelConfigurationType = { providerId: "openai", @@ -656,6 +677,7 @@ export enum GLOBAL_AGENTS_SID { GPT4 = "gpt-4", O1 = "o1", O1_MINI = "o1-mini", + O1_HIGH_REASONING = "o1_high", CLAUDE_3_OPUS = "claude-3-opus", CLAUDE_3_SONNET = "claude-3-sonnet", CLAUDE_3_HAIKU = "claude-3-haiku", diff --git a/types/src/shared/feature_flags.ts b/types/src/shared/feature_flags.ts index fd55ee9cfe48..c1e489248e0b 100644 --- a/types/src/shared/feature_flags.ts +++ b/types/src/shared/feature_flags.ts @@ -8,6 +8,7 @@ export const WHITELISTABLE_FEATURES = [ "use_app_for_header_detection", "openai_o1_feature", "openai_o1_mini_feature", + "openai_o1_high_reasoning_feature", "index_private_slack_channel", "conversations_jit_actions", "labs_trackers",