From 1a3bc4f666902459de2d76eb40f7db663c5ced87 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Mon, 25 Mar 2024 12:20:03 -0700 Subject: [PATCH] Beam: move instructions --- src/modules/beam/beam.config.ts | 1 - src/modules/beam/gather/BeamGatherInput.tsx | 2 +- src/modules/beam/gather/BeamGatherPane.tsx | 4 ++-- src/modules/beam/gather/beam.gather.ts | 14 ++++++------- .../instructions/ChatGenerateInstruction.tsx | 2 +- .../UserInputChecklistInstruction.tsx | 6 ++---- .../beam.gather.execution.tsx} | 19 +++++------------- .../beam.gather.factories.ts | 20 +++++++++---------- 8 files changed, 27 insertions(+), 41 deletions(-) rename src/modules/beam/gather/{beam.gather.instructions.tsx => instructions/beam.gather.execution.tsx} (87%) rename src/modules/beam/gather/{ => instructions}/beam.gather.factories.ts (96%) diff --git a/src/modules/beam/beam.config.ts b/src/modules/beam/beam.config.ts index 926482885..15841fcc3 100644 --- a/src/modules/beam/beam.config.ts +++ b/src/modules/beam/beam.config.ts @@ -21,7 +21,6 @@ export const SCATTER_RAY_SHOW_DRAG_HANDLE = false; // BEAM Gather configuration export const GATHER_COLOR = 'success' as const; -export const GATHER_DEBUG_EXECUTION_CHAIN = true; export const GATHER_DEFAULT_TO_FIRST_FUSION = true; export const GATHER_PLACEHOLDER = '📦 ...'; export const GATHER_SHOW_SYSTEM_PROMPT = false; diff --git a/src/modules/beam/gather/BeamGatherInput.tsx b/src/modules/beam/gather/BeamGatherInput.tsx index f8529640f..25d97fee5 100644 --- a/src/modules/beam/gather/BeamGatherInput.tsx +++ b/src/modules/beam/gather/BeamGatherInput.tsx @@ -8,7 +8,7 @@ import EditRoundedIcon from '@mui/icons-material/EditRounded'; import { InlineTextarea } from '~/common/components/InlineTextarea'; import type { ChatGenerateInstruction } from './instructions/ChatGenerateInstruction'; -import type { Instruction } from './beam.gather.instructions'; +import type { Instruction } from './instructions/beam.gather.execution'; import { BeamStoreApi, useBeamStore } from '../store-beam.hooks'; import { GATHER_SHOW_SYSTEM_PROMPT } from '../beam.config'; import { fusionIsEditable } from './beam.gather'; diff --git a/src/modules/beam/gather/BeamGatherPane.tsx b/src/modules/beam/gather/BeamGatherPane.tsx index f74fe8d49..241d26323 100644 --- a/src/modules/beam/gather/BeamGatherPane.tsx +++ b/src/modules/beam/gather/BeamGatherPane.tsx @@ -19,7 +19,7 @@ import { useScrollToBottom } from '~/common/scroll-to-bottom/useScrollToBottom'; import { BEAM_BTN_SX, GATHER_COLOR } from '../beam.config'; import { BeamGatherDropdown } from './BeamGatherPaneDropdown'; import { BeamStoreApi, useBeamStore } from '../store-beam.hooks'; -import { FUSION_FACTORIES } from './beam.gather.factories'; +import { FUSION_FACTORIES } from './instructions/beam.gather.factories'; import { beamPaneSx } from '../BeamCard'; import { fusionIsFusing, fusionIsUsableOutput } from './beam.gather'; import { useModuleBeamStore } from '../store-module-beam'; @@ -39,7 +39,7 @@ const gatherPaneSx: SxProps = { boxShadow: `0px 6px 20px -8px rgb(var(--joy-palette-neutral-darkChannel) / 30%)`, [`&.${gatherPaneClasses.ready}`]: { backgroundColor: 'background.popup', - boxShadow: `0px 6px 16px -8px rgb(var(--joy-palette-${/*GATHER_COLOR*/ 'neutral'}-darkChannel) / 40%)`, + boxShadow: `0px 6px 16px -8px rgb(var(--joy-palette-neutral-darkChannel) / 40%)`, }, [`&.${gatherPaneClasses.busy}`]: { animation: `${animationShadowLimey} 2s linear infinite`, diff --git a/src/modules/beam/gather/beam.gather.ts b/src/modules/beam/gather/beam.gather.ts index 1dcf42868..ee8a0c42c 100644 --- a/src/modules/beam/gather/beam.gather.ts +++ b/src/modules/beam/gather/beam.gather.ts @@ -5,9 +5,9 @@ import type { StateCreator } from 'zustand/vanilla'; import type { DLLMId } from '~/modules/llms/store-llms'; import type { DMessage } from '~/common/state/store-chats'; -import { FUSION_FACTORIES } from './beam.gather.factories'; +import { FUSION_FACTORIES } from './instructions/beam.gather.factories'; import { GATHER_DEFAULT_TO_FIRST_FUSION, GATHER_PLACEHOLDER } from '../beam.config'; -import { gatherStartFusion, gatherStopFusion, Instruction } from './beam.gather.instructions'; +import { gatherStartFusion, gatherStopFusion, Instruction } from './instructions/beam.gather.execution'; /// Gather Store > BFusion /// @@ -39,7 +39,7 @@ export interface BFusion { fusingInstructionComponent?: React.ReactNode; } -export const createBFusion = (factoryId: string, instructions: Instruction[]): BFusion => ({ +const createBFusion = (factoryId: string, instructions: Instruction[]): BFusion => ({ // const fusionId: uuidv4(), factoryId, @@ -98,7 +98,7 @@ export const reInitGatherStateSlice = (prevFusions: BFusion[]): GatherStateSlice prevFusions.forEach(gatherStopFusion); // fully use new fusions - const newFusions = FUSION_FACTORIES.map(spec => spec.factory()); + const newFusions = FUSION_FACTORIES.map(factory => createBFusion(factory.id, factory.createInstructions())); return { gatherLlmId: null, // will be re-set during open() of the Beam Store @@ -177,10 +177,8 @@ export const createGatherSlice: StateCreator { - if (GATHER_DEBUG_EXECUTION_CHAIN) - console.log('All instructions executed for fusion:', fusionId); onUpdateBFusion({ stage: 'success', errorText: undefined, @@ -133,8 +128,6 @@ export function gatherStartFusion( .catch((error) => { // User abort: no need to show an error if (inputState.chainAbortController.signal.aborted) { - if (GATHER_DEBUG_EXECUTION_CHAIN) - console.log('Fusion aborted:', fusionId); return onUpdateBFusion({ stage: 'stopped', errorText: 'Merge Canceled.', @@ -143,8 +136,6 @@ export function gatherStartFusion( } // Error handling - if (GATHER_DEBUG_EXECUTION_CHAIN) - console.error('Error executing instructions:', error, fusionId); onUpdateBFusion({ stage: 'error', errorText: 'Issue: ' + (error?.message || error?.toString() || 'Unknown error'), diff --git a/src/modules/beam/gather/beam.gather.factories.ts b/src/modules/beam/gather/instructions/beam.gather.factories.ts similarity index 96% rename from src/modules/beam/gather/beam.gather.factories.ts rename to src/modules/beam/gather/instructions/beam.gather.factories.ts index 6aa1ce893..7e640091d 100644 --- a/src/modules/beam/gather/beam.gather.factories.ts +++ b/src/modules/beam/gather/instructions/beam.gather.factories.ts @@ -4,7 +4,7 @@ import CheckBoxOutlinedIcon from '@mui/icons-material/CheckBoxOutlined'; import MediationOutlinedIcon from '@mui/icons-material/MediationOutlined'; import TableViewRoundedIcon from '@mui/icons-material/TableViewRounded'; -import { BFusion, createBFusion } from './beam.gather'; +import type { Instruction } from './beam.gather.execution'; interface FusionFactorySpec { @@ -13,7 +13,7 @@ interface FusionFactorySpec { Icon?: React.FunctionComponent; description: string; isDev?: boolean; - factory: () => BFusion; + createInstructions: () => Instruction[]; } @@ -25,7 +25,7 @@ export const FUSION_FACTORIES: FusionFactorySpec[] = [ Icon: CheckBoxOutlinedIcon, description: 'A brainstorming session with AI, where you first pick your favorite ideas from a list it generates, and then the AI combines those picks into a tailored solution.', // description: 'This approach employs a two-stage, interactive process where an AI first generates a checklist of insights from a conversation for user selection, then synthesizes those selections into a tailored, comprehensive response, integrating user preferences with AI analysis and creativity.', - factory: () => createBFusion('guided', [ + createInstructions: () => [ { type: 'chat-generate', label: 'Generating Checklist', @@ -77,7 +77,7 @@ Given the user preferences below, synthesize the {{N}} response alternatives abo Ensure the synthesis is coherent, integrating the response alternatives in a clear manner. The final output should reflect a deep understanding of the user's preferences and the conversation's context.`.trim(), }, - ]), + ], }, // 2: Fuse @@ -86,7 +86,7 @@ The final output should reflect a deep understanding of the user's preferences a label: 'Fuse', Icon: MediationOutlinedIcon, description: 'AI combines conversation details and various AI-generated ideas into one clear, comprehensive answer, making sense of diverse insights for you.', - factory: () => createBFusion('fuse', [ + createInstructions: () => [ { type: 'chat-generate', label: 'Syntesizing Fusion', @@ -103,7 +103,7 @@ Synthesize the perfect response that merges the key insights and provides clear Synthesize the perfect cohesive response to my last message that merges the collective intelligence of the {{N}} alternatives above.`.trim(), // evalPrompt: `Evaluate the synthesized response provided by the AI synthesizer. Consider its relevance to the original query, the coherence of the integration of different perspectives, and its completeness in addressing the objectives or questions raised throughout the conversation.`.trim(), }, - ]), + ], }, // 3: Eval @@ -113,7 +113,7 @@ Synthesize the perfect cohesive response to my last message that merges the coll Icon: TableViewRoundedIcon, description: 'Analyzes and ranks AI responses, offering a clear, comparative overview to support your choice of answer.', isDev: true, - factory: () => createBFusion('eval', [ + createInstructions: () => [ { type: 'chat-generate', label: 'Evaluation', @@ -147,7 +147,7 @@ Complete this table to offer a structured and detailed comparison of the {{N}} o Only work with the provided {{N}} responses. Begin with listing the criteria.`.trim(), }, - ]), + ], }, // 4: Custom (this may be overwritten by other factories, if editing those) @@ -156,7 +156,7 @@ Only work with the provided {{N}} responses. Begin with listing the criteria.`.t label: 'Custom', // Icon: BuildCircleOutlinedIcon, description: 'Define your own fusion prompt.', - factory: () => createBFusion('custom', [ + createInstructions: () => [ { type: 'chat-generate', label: 'Executing Your Merge Strategy', @@ -169,7 +169,7 @@ Based on the {{N}} alternatives provided, synthesize a single, comprehensive res // userPrompt: 'Answer again using the best elements from the {{N}} answers above. Be truthful, honest, reliable.', // userPrompt: 'Based on the {{N}} alternatives provided, synthesize a single, comprehensive response that effectively addresses the query or problem at hand.', }, - ]), + ], }, // ... future ...