From 80109e92a54a4d7cc01301cd6863ffbf4d020cd1 Mon Sep 17 00:00:00 2001 From: Ian Arawjo Date: Thu, 23 Oct 2025 11:57:55 -0400 Subject: [PATCH] Add OpenAI GPT5 models and auto-retry for Gemini empty responses. --- .../react-server/src/LLMListComponent.tsx | 6 ++-- .../react-server/src/ModelSettingSchemas.tsx | 27 ++++++++++++++-- .../src/RequestClarificationModal.tsx | 1 - chainforge/react-server/src/backend/models.ts | 6 ++++ chainforge/react-server/src/backend/utils.ts | 31 ++++++++++++++++++ chainforge/react-server/src/store.tsx | 32 +++++++++++++++++-- setup.py | 2 +- 7 files changed, 96 insertions(+), 9 deletions(-) diff --git a/chainforge/react-server/src/LLMListComponent.tsx b/chainforge/react-server/src/LLMListComponent.tsx index 105980fa1..e54cd94e7 100644 --- a/chainforge/react-server/src/LLMListComponent.tsx +++ b/chainforge/react-server/src/LLMListComponent.tsx @@ -31,8 +31,10 @@ import { deepcopy, ensureUniqueName } from "./backend/utils"; import NestedMenu, { NestedMenuItemProps } from "./NestedMenu"; // The LLM(s) to include by default on a PromptNode whenever one is created. -// Defaults to ChatGPT (GPT3.5) when running locally, and HF-hosted falcon-7b for online version since it's free. -const DEFAULT_INIT_LLMS = [initLLMProviders[0]]; +// Defaults to a cheap non-reasoning OpenAI model. +const DEFAULT_INIT_LLMS = [ + initLLMProviders.find((m) => m.model === "gpt-4o-mini")!, +]; // Helper funcs /** Get position CSS style below and left-aligned to the input element */ diff --git a/chainforge/react-server/src/ModelSettingSchemas.tsx b/chainforge/react-server/src/ModelSettingSchemas.tsx index e53d2431c..596a84b41 100644 --- a/chainforge/react-server/src/ModelSettingSchemas.tsx +++ b/chainforge/react-server/src/ModelSettingSchemas.tsx @@ -55,6 +55,12 @@ const ChatGPTSettings: ModelSettingsDict = { description: "Select an OpenAI model to query. For more details on the differences, see the OpenAI API documentation.", enum: [ + "gpt-5", + "gpt-5-mini", + "gpt-5-nano", + "gpt-5-chat-latest", + "o3", + "o3-mini", "gpt-4.1", "gpt-4.1-mini", "gpt-4.1-nano", @@ -64,7 +70,6 @@ const ChatGPTSettings: ModelSettingsDict = { "o1", "o1-mini", "o1-pro", - "o3-mini", "gpt-4.5-preview", "gpt-3.5-turbo", "gpt-4o-2024-05-13", @@ -105,12 +110,28 @@ const ChatGPTSettings: ModelSettingsDict = { type: "number", title: "temperature", description: - "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", + "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. NOTE: GPT-5 models will ignore this parameter.", default: 1, minimum: 0, maximum: 2, multipleOf: 0.01, }, + reasoning_effort: { + type: "string", + title: "reasoning.effort", + description: + "A parameter specific to o1+ and GPT-5+ models that controls the amount of reasoning effort the model expends when generating a response. NOTE: Currently, only GPT-5 supports the 'minimal' option.", + enum: ["minimal", "low", "medium", "high"], + default: "medium", // TODO: Add reasoning.summary option to visualize reasoning tokens in UI. + }, + verbosity: { + type: "string", + title: "verbosity", + description: + "A parameter specific to GPT-5+ models that determines how many output tokens are generated. Lowering the number of tokens reduces overall latency.", + enum: ["low", "medium", "high"], + default: "medium", + }, response_format: { type: "string", title: "response_format", @@ -547,7 +568,7 @@ const GPTImage1Settings: ModelSettingsDict = { title: "Model Version", description: "Select an OpenAI image model to query in the GPT Image series.", - enum: ["gpt-image-1"], + enum: ["gpt-image-1", "gpt-image-1-mini"], default: "gpt-image-1", }, size: { diff --git a/chainforge/react-server/src/RequestClarificationModal.tsx b/chainforge/react-server/src/RequestClarificationModal.tsx index bbc4161c7..239d1a60d 100644 --- a/chainforge/react-server/src/RequestClarificationModal.tsx +++ b/chainforge/react-server/src/RequestClarificationModal.tsx @@ -62,7 +62,6 @@ const RequestClarificationModal: React.FC = ({ withCloseButton={false} title={title} centered - style={{ position: "relative", left: "-4%" }} >
= max_retries) { + throw new Error( + "Maximum retries reached: Google Gemini is returning empty text responses. This happens occasionally due to ongoing issues with Google's API and the fix is unknown.", + ); + } + num_retries += 1; + console.warn( + "Received empty response from Google Gemini; retrying once more...", + ); + continue; + } + responses.push({ text: chat_response.text, candidates: chat_response.candidates, @@ -1782,6 +1812,7 @@ function _extract_google_ai_responses( * Extracts the text part of a 'EnhancedGenerateContentResponse' object from Google Gemini `sendChat` or `chat`. */ function _extract_gemini_responses(completions: Array): Array { + console.log("Extracting Gemini responses from: ", completions); return completions.map((c: Dict) => c.text); } diff --git a/chainforge/react-server/src/store.tsx b/chainforge/react-server/src/store.tsx index 763a0a429..5c1d47dfe 100644 --- a/chainforge/react-server/src/store.tsx +++ b/chainforge/react-server/src/store.tsx @@ -101,6 +101,27 @@ export const initLLMProviderMenu: (LLMSpec | LLMGroup)[] = [ group: "OpenAI", emoji: "🤖", items: [ + { + name: "GPT-5", + emoji: "🚀", + model: "gpt-5", + base_model: "gpt-4", + temp: 1.0, + }, + { + name: "GPT-5-mini", + emoji: "🔬", + model: "gpt-5-mini", + base_model: "gpt-4", + temp: 1.0, + }, + { + name: "GPT-5-nano", + emoji: "🪲", + model: "gpt-5-nano", + base_model: "gpt-4", + temp: 1.0, + }, { name: "GPT-4o-mini", emoji: "🔬", @@ -130,9 +151,9 @@ export const initLLMProviderMenu: (LLMSpec | LLMGroup)[] = [ temp: 1.0, }, { - name: "o1", + name: "o3", emoji: "⭕", - model: "o1", + model: "o3", base_model: "gpt-4", temp: 1.0, }, @@ -143,6 +164,13 @@ export const initLLMProviderMenu: (LLMSpec | LLMGroup)[] = [ base_model: "gpt-4", temp: 1.0, }, + { + name: "o1", + emoji: "⭕", + model: "o1", + base_model: "gpt-4", + temp: 1.0, + }, { name: "GPT-3.5", emoji: "🤖", diff --git a/setup.py b/setup.py index de1388b75..aea90c5d4 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ def readme(): setup( name="chainforge", - version="0.3.6.3", + version="0.3.6.4", packages=find_packages(), author="Ian Arawjo", description="A Visual Programming Environment for Prompt Engineering",