1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
import { PresEffect, PresEffectDirection } from '../../views/nodes/trails/PresEnums';
import { AnimationSettingsProperties, easeItems } from '../../views/nodes/trails/SpringUtils';
import { openai } from './setup';
export enum CustomizationType {
PRES_TRAIL_SLIDE = 'trails',
}
interface PromptInfo {
description: string;
features: { name: string; description: string; values?: string[] }[];
}
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.`,
features: [],
},
};
// Allows you to register properties that are customizable
export const addCustomizationProperty = (type: CustomizationType, name: string, description: string, values?: string[]) => {
prompts[type].features.push({ name, description, ...(values ? { values } : {}) });
};
// All the registered fields, make sure to update during registration, this
// includes most fields but is not yet fully comprehensive
export const gptSlideProperties = [
'title',
'config_zoom',
'presentation_transition',
'presentation_easeFunc',
'presentation_effect',
'presentation_effectDirection',
'presentation_effectTiming',
'presentation_playAudio',
'presentation_zoomText',
'presentation_hideBefore',
'presentation_hide',
'presentation_hideAfter',
'presentation_openInLightbox',
];
// Registers slide properties
const setupPresSlideCustomization = () => {
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 = (inputText: string) => {
/**
* Prompt: Generate entrance animations from slower and gentler to bouncier and more high energy
*
* Format:
* {
* name: Slow Fade, Quick Flip, Springy
* effect: BOUNCE
* effectDirection: LEFT
* timingConfig: {
* }
* }
*/
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.';
return openai.chat.completions
.create({
model: 'gpt-4',
messages: [
{ role: 'system', content: prompt },
{ role: 'user', content: `${customInput}` },
],
temperature: 0,
max_tokens: 1000,
})
.then(response => response.choices[0].message?.content ?? '')
.catch(err => {
console.log(err);
return 'Error connecting with API.';
});
};
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('. ');
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.`;
return openai.chat.completions
.create({
model: 'gpt-4',
messages: [
{ 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.';
});
};
|