From 68bf2f9e4141d8a99407ff4c6c02d44795c638de Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 4 Feb 2025 14:08:38 -0500 Subject: fixing up gpt and animation panel in presbox. --- src/client/apis/gpt/PresCustomization.ts | 115 ++++---- .../views/nodes/imageEditor/ImageEditorButtons.tsx | 3 +- src/client/views/nodes/trails/PresBox.tsx | 295 +++++++-------------- src/client/views/nodes/trails/SpringUtils.ts | 9 +- 4 files changed, 170 insertions(+), 252 deletions(-) (limited to 'src') diff --git a/src/client/apis/gpt/PresCustomization.ts b/src/client/apis/gpt/PresCustomization.ts index 2262886a2..c465f098f 100644 --- a/src/client/apis/gpt/PresCustomization.ts +++ b/src/client/apis/gpt/PresCustomization.ts @@ -1,3 +1,5 @@ +import { PresEffect, PresEffectDirection } from '../../views/nodes/trails/PresEnums'; +import { AnimationSettingsProperties, easeItems } from '../../views/nodes/trails/SpringUtils'; import { openai } from './setup'; export enum CustomizationType { @@ -10,15 +12,17 @@ interface PromptInfo { } const prompts: { [key: string]: PromptInfo } = { trails: { - description: - 'We are customizing the properties and transition of a slide in a presentation. You are given the current properties of the slide in a json with the fields [title, presentation_transition, presentation_effect, config_zoom, presentation_effectDirection], as well as the prompt for how the user wants to change it. Return a json with the required fields: [title, presentation_transition, presentation_effect, config_zoom, presentation_effectDirection] by applying the changes in the prompt to the current state of the slide.', + description: `We are customizing the properties and transition of a slide in a presentation. + You are given the current properties of the slide in a json with the fields [title, presentation_transition, presentation_effect, config_zoom, presentation_effectDirection], + as well as the prompt for how the user wants to change it. + Return a json with the required fields: [title, presentation_transition, presentation_effect, config_zoom, presentation_effectDirection] by applying the changes in the prompt to the current state of the slide.`, features: [], }, }; // Allows you to register properties that are customizable export const addCustomizationProperty = (type: CustomizationType, name: string, description: string, values?: string[]) => { - values ? prompts[type].features.push({ name, description, values }) : prompts[type].features.push({ name, description }); + prompts[type].features.push({ name, description, ...(values ? { values } : {}) }); }; // All the registered fields, make sure to update during registration, this @@ -41,35 +45,34 @@ export const gptSlideProperties = [ // Registers slide properties const setupPresSlideCustomization = () => { - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'title', 'is the title/name of the slide.'); - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_transition', 'is a number in milliseconds for how long it should take to transition/move to a slide.'); - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_easeFunc', 'is the easing function for the movement to the slide.', ['Ease', 'Ease In', 'Ease Out', 'Ease Out', 'Ease In Out', 'Linear']); - - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_effect', 'is an effect applied to the slide when we transition to it.', ['None', 'Expand', 'Fade in', 'Bounce', 'Flip', 'Rotate', 'Roll']); - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_effectDirection', 'is what direction the effect is applied.', ['Enter from left', 'Enter from right', 'Enter from bottom', 'Enter from Top', 'Enter from center']); - addCustomizationProperty( - CustomizationType.PRES_TRAIL_SLIDE, - 'presentation_effectTiming', - "is a json object of the format: {type: string, stiffness: number, damping: number, mass: number}. Type is always “custom”. Controls the spring-based timing of the presentation effect animation. Stiffness, damping, and mass control the physics-based properties of spring animations. This is used to create a more natural looking timing, bouncy effects, etc. Use spring physics to adjust these parameters to match the user's description of how they want to animate the effect." - ); - - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'config_zoom', 'is a number from 0 to 1.0 indicating the percentage we should zoom into the slide.'); - - // boolean values - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_playAudio', 'is a boolean value indicating if we should play audio when we go to the slide.'); - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_zoomText', 'is a boolean value indicating if we should zoom into text selections when we go to the slide.'); - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_hideBefore', 'is a boolean value indicating if we should hide the slide before going to it.'); - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_hide', 'is a boolean value indicating if we should hide the slide during the presentation.'); - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_hideAfter', 'is a boolean value indicating if we should hide the slide after going to it.'); - addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, 'presentation_openInLightbox', 'is a boolean value indicating if we should open the slide in an overlay or lightbox view during the presentation.'); -}; + const add = (name: string, val:string, opts?:string[]) => addCustomizationProperty(CustomizationType.PRES_TRAIL_SLIDE, name, val, opts); + const addBool = (name: string, val:string) => add(name, 'is a boolean value indicating if we should ' + val); + add('title', 'is the title/name of the slide.'); + add('config_zoom', 'is a number from 0 to 1.0 indicating the percentage we should zoom into the slide.'); + add('presentation_transition', 'is a number in milliseconds for how long it should take to transition/move to a slide.'); + add('presentation_easeFunc', 'is the easing function for the movement to the slide.', easeItems.filter(val => val.text !== 'Custom').map(val => val.text)) + add('presentation_effect', 'is an effect applied to the slide when we transition to it.', Object.keys(PresEffect)); + add('presentation_effectDirection','is what direction the effect is applied.', Object.keys(PresEffectDirection).filter(key => key !== PresEffectDirection.None)); + add('presentation_effectTiming', `is a json object of the format: {type: string, ${AnimationSettingsProperties.stiffness}: number, ${AnimationSettingsProperties.damping}: number, ${AnimationSettingsProperties.mass}: number}. + Type is always “custom”. Controls the spring-based timing of the presentation effect animation. + Stiffness, damping, and mass control the physics-based properties of spring animations. + This is used to create a more natural looking timing, bouncy effects, etc. + Use spring physics to adjust these parameters to match the user's description of how they want to animate the effect.`); + + + addBool('presentation_playAudio', 'play audio when we go to the slide.'); + addBool('presentation_zoomText', 'zoom into text selections when we go to the slide.'); + addBool('presentation_hideBefore', 'hide the slide before going to it.'); + addBool('presentation_hide', 'hide the slide during the presentation.'); + addBool('presentation_hideAfter', 'hide the slide after going to it.'); + addBool('presentation_openInLightbox', 'open the slide in an overlay or lightbox view during the presentation.'); +}; // prettier-ignore setupPresSlideCustomization(); -export const getSlideTransitionSuggestions = async (inputText: string) => { +export const getSlideTransitionSuggestions = (inputText: string) => { /** - * Prompt: Generate an entrance animations from slower and gentler - * to bouncier and more high energy + * Prompt: Generate entrance animations from slower and gentler to bouncier and more high energy * * Format: * { @@ -81,13 +84,19 @@ export const getSlideTransitionSuggestions = async (inputText: string) => { * } */ - const prompt = - "I want to generate four distinct types of slide effect animations. Return a json of the form {effect: string, direction: string, stiffness: number, damping: number, mass: number}[] with four elements. Effect is the type of animation; its only possible values are ['Expand', 'Fade in', 'Bounce', 'Flip', 'Rotate', 'Roll']. Direction is the direction that the animation starts from; its only possible values are ['Enter from left', 'Enter from right', 'Enter from bottom', 'Enter from Top', 'Enter from center']. Stiffness, damping, and mass control the physics-based properties of spring animations. This is used to create a more natural-looking timing, bouncy effects, etc. Use spring physics to adjust these parameters to animate the effect."; + const prompt = `I want to generate four distinct types of slide effect animations. + Return a json of the form { ${AnimationSettingsProperties.effect}: string, ${AnimationSettingsProperties.direction}: string, ${AnimationSettingsProperties.stiffness}: number, ${AnimationSettingsProperties.damping}: number, ${AnimationSettingsProperties.mass}: number}[] with four elements. + ${AnimationSettingsProperties.effect} is the type of animation; its only possible values are [${Object.keys(PresEffect).filter(key => key !== PresEffect.None).join(',')}]. + ${AnimationSettingsProperties.direction} is the direction that the animation starts from; + its only possible values are [${Object.values(PresEffectDirection).filter(key => key !== PresEffectDirection.None).join(',')}]. + ${AnimationSettingsProperties.stiffness}, ${AnimationSettingsProperties.damping}, and ${AnimationSettingsProperties.mass} control the physics-based properties of spring animations. + This is used to create a more natural-looking timing, bouncy effects, etc. + Use spring physics to adjust these parameters to animate the effect.`; // prettier-ignore const customInput = inputText ?? 'Make them as contrasting as possible with different effects and timings ranging from gentle to energetic.'; - try { - const response = await openai.chat.completions.create({ + return openai.chat.completions + .create({ model: 'gpt-4', messages: [ { role: 'system', content: prompt }, @@ -95,39 +104,33 @@ export const getSlideTransitionSuggestions = async (inputText: string) => { ], temperature: 0, max_tokens: 1000, + }) + .then(response => response.choices[0].message?.content ?? '') + .catch(err => { + console.log(err); + return 'Error connecting with API.'; }); - return response.choices[0].message?.content; - } catch (err) { - console.log(err); - return 'Error connecting with API.'; - } }; -export const gptTrailSlideCustomization = async (inputText: string, properties: any | any[]) => { - let prompt = prompts.trails.description; - - prompts.trails.features.forEach(feature => { - prompt += feature.name + ' ' + feature.description; - if (feature.values) { - prompt += `Its only possible values are [${feature.values.join(', ')}].`; - } - }); +export const gptTrailSlideCustomization = (inputText: string, properties: string) => { + const preamble = prompts.trails.description + prompts.trails.features.map(feature => feature.name + ' ' + feature.description + (feature.values ? `Its only possible values are [${feature.values.join(', ')}]` : '')).join('. '); - prompt += 'Set unchanged values to null and make sure you include new properties if they are specified in the prompt even if they do not exist in current properties. Please only return the json with the keys described and their values.'; + const prompt = `Set unchanged values to null and make sure you include new properties if they are specified in the prompt even if they do not exist in current properties. + Please only return the json with the keys described and their values.`; - try { - const response = await openai.chat.completions.create({ + return openai.chat.completions + .create({ model: 'gpt-4', messages: [ - { role: 'system', content: prompt }, - { role: 'user', content: `Prompt: ${inputText}, Current properties: ${JSON.stringify(properties)}` }, + { role: 'system', content: preamble + prompt }, + { role: 'user', content: `Prompt: ${inputText}, Current properties: ${properties}` }, ], temperature: 0, max_tokens: 1000, + }) + .then(response => response.choices[0].message?.content ?? '') + .catch(err => { + console.log(err); + return 'Error connecting with API.'; }); - return response.choices[0].message?.content; - } catch (err) { - console.log(err); - return 'Error connecting with API.'; - } }; diff --git a/src/client/views/nodes/imageEditor/ImageEditorButtons.tsx b/src/client/views/nodes/imageEditor/ImageEditorButtons.tsx index e810881a5..985dc914f 100644 --- a/src/client/views/nodes/imageEditor/ImageEditorButtons.tsx +++ b/src/client/views/nodes/imageEditor/ImageEditorButtons.tsx @@ -53,9 +53,8 @@ export function ApplyFuncButtons({ loading, onClick: getEdit, onReset, btnText } export function ImageToolButton(tool: ImageEditTool, isActive: boolean, selectTool: (type: ImageToolType) => void) { return ( -
+
@@ -1952,16 +1878,16 @@ export class PresBox extends ViewBoxBaseComponent() { style={{ alignSelf: 'flex-start' }} onClick={e => { e.stopPropagation(); - this.setBezierEditorVisibility(!this.showBezierEditor); + this.setBezierEditorVisibility(!this._showBezierEditor); }}> - {`${this.showBezierEditor ? 'Hide' : 'Show'} Timing Editor`} - + {`${this._showBezierEditor ? 'Hide' : 'Show'} Timing Editor`} +
{/* Cubic bezier editor */} - {this.showBezierEditor && ( + {this._showBezierEditor && (

Custom Timing Function @@ -1978,7 +1904,7 @@ export class PresBox extends ViewBoxBaseComponent() { { this.setAnimationChat(e.target.value); }} @@ -1992,7 +1918,7 @@ export class PresBox extends ViewBoxBaseComponent() { style={{ alignSelf: 'flex-end' }} text="Send" type={Type.TERT} - icon={this.isLoading ? : } + icon={this._isLoading ? : } iconPlacement="right" color={SnappingManager.userVariantColor} onClick={this.customizeAnimations} @@ -2107,12 +2033,7 @@ export class PresBox extends ViewBoxBaseComponent() { closeOnSelect items={effectTimings} selectedVal={timingConfig.type} - setSelectedVal={val => { - this.updateEffectTiming(activeItem, { - type: val as SpringType, - ...springMappings[val], - }); - }} + setSelectedVal={val => this.updateEffectTiming(activeItem, { type: val as SpringType, ...springMappings[val] })} dropdownType={DropdownType.SELECT} type={Type.TERT} /> @@ -2120,73 +2041,61 @@ export class PresBox extends ViewBoxBaseComponent() { className="presBox-show-hide-dropdown" onClick={e => { e.stopPropagation(); - this.setSpringEditorVisibility(!this.showSpringEditor); + this.setSpringEditorVisibility(!this._showSpringEditor); }}> - {`${this.showSpringEditor ? 'Hide' : 'Show'} Spring Settings`} - + {`${this._showSpringEditor ? 'Hide' : 'Show'} Spring Settings`} +

- {this.showSpringEditor && ( + {this._showSpringEditor && ( <>
Tension
-
{ - e.stopPropagation(); - }}> - e.stopPropagation()}> + {/* prettier-ignore */} + { - if (!timingConfig) return; - this.updateEffectTiming(activeItem, { ...timingConfig, type: SpringType.CUSTOM, stiffness: val as number }); - }} + onChange={(e, val) => timingConfig && this.updateEffectTiming(activeItem, { ...timingConfig, type: SpringType.CUSTOM, stiffness: val as number })} valueLabelDisplay="auto" />
Damping
-
{ - e.stopPropagation(); - }}> - e.stopPropagation()}> + {/* prettier-ignore */} + { - if (!timingConfig) return; - this.updateEffectTiming(activeItem, { ...timingConfig, type: SpringType.CUSTOM, damping: val as number }); - }} + onChange={(e, val) => timingConfig && this.updateEffectTiming(activeItem, { ...timingConfig, type: SpringType.CUSTOM, damping: val as number })} valueLabelDisplay="auto" />
Mass
-
{ - e.stopPropagation(); - }}> - e.stopPropagation()}> + {/* prettier-ignore */} + { - if (!timingConfig) return; - this.updateEffectTiming(activeItem, { ...timingConfig, type: SpringType.CUSTOM, mass: val as number }); - }} + onChange={(e, val) => timingConfig && this.updateEffectTiming(activeItem, { ...timingConfig, type: SpringType.CUSTOM, mass: val as number })} valueLabelDisplay="auto" />
- Preview Effect -
-
- -
- +
+
{/* presbox chatbox */} - {this.chatActive &&
} + {this._chatActive &&
}
); } diff --git a/src/client/views/nodes/trails/SpringUtils.ts b/src/client/views/nodes/trails/SpringUtils.ts index 73e1e14f1..044afbeb1 100644 --- a/src/client/views/nodes/trails/SpringUtils.ts +++ b/src/client/views/nodes/trails/SpringUtils.ts @@ -22,7 +22,14 @@ export interface SpringSettings { } // Overall config - +// Keeps these settings in sync with the AnimationSettings interface (used by gpt); +export enum AnimationSettingsProperties { + effect = 'effect', + direction = 'direction', + stiffness = 'stiffness', + damping = 'damping', + mass = 'mass', +} export interface AnimationSettings { effect: PresEffect; direction: PresEffectDirection; -- cgit v1.2.3-70-g09d2