-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkinotron_nodes.py
862 lines (757 loc) · 27.3 KB
/
kinotron_nodes.py
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
from PIL import Image, ImageOps
from io import BytesIO
import numpy as np
import struct
import comfy.utils
import time
import random
from openai import OpenAI
class TextList:
def __init__(self, rnd):
self.items = []
self.id = rnd
def add(self, item):
"""Appends a new item to the list."""
self.items.append(item)
def get(self, n):
return self.items[n]
def size(self):
return len(self.items)
def clear(self):
self.items = []
#IO
class TextInput:
@classmethod
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"input": ("STRING",{"multiline": True}),
},
}
CATEGORY = "Kinotron/Text"
FUNCTION = "output"
RETURN_NAMES = ("text",)
RETURN_TYPES = ("STRING",)
def output(self,input, **inputs):
return (input,)
class ToConsole:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"text": ("STRING", {"forceInput": True}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
OUTPUT_NODE = True
FUNCTION = "show_text"
CATEGORY = "Kinotron/Output"
def show_text(self, text):
print(text)
return text
class ToConsoleList:
@classmethod
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"list": ("LIST", {"forceInput": True}),
},
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("text",)
OUTPUT_NODE = True
FUNCTION = "show_text"
CATEGORY = "Kinotron/Output"
def show_text(self, list):
tmp = ""
for i in range(0,list.size()):
tmp = tmp+"\n"+list.get(i)
list.clear()
print(tmp)
return tmp
class Combine:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"scene_1": ("STRING", {"multiline": False, "forceInput": True}),
},
"optional": {
"scene_2": ("STRING", {"multiline": False, "forceInput": True}),
"scene_3": ("STRING", {"multiline": False, "forceInput": True}),
"scene_4": ("STRING", {"multiline": False, "forceInput": True}),
"scene_5": ("STRING", {"multiline": False, "forceInput": True}),
"scene_6": ("STRING", {"multiline": False, "forceInput": True}),
"scene_7": ("STRING", {"multiline": False, "forceInput": True}),
"scene_8": ("STRING", {"multiline": False, "forceInput": True}),
"scene_9": ("STRING", {"multiline": False, "forceInput": True}),
"scene_10": ("STRING", {"multiline": False, "forceInput": True}),
"scene_11": ("STRING", {"multiline": False, "forceInput": True}),
"scene_12": ("STRING", {"multiline": False, "forceInput": True}),
"scene_13": ("STRING", {"multiline": False, "forceInput": True}),
"scene_14": ("STRING", {"multiline": False, "forceInput": True}),
"scene_15": ("STRING", {"multiline": False, "forceInput": True}),
"scene_16": ("STRING", {"multiline": False, "forceInput": True}),
"scene_17": ("STRING", {"multiline": False, "forceInput": True}),
"scene_18": ("STRING", {"multiline": False, "forceInput": True}),
"scene_19": ("STRING", {"multiline": False, "forceInput": True}),
"scene_20": ("STRING", {"multiline": False, "forceInput": True}),
},
}
RETURN_TYPES = ("LIST",)
RETURN_NAMES = ("output_list",)
OUTPUT_NODE = True
FUNCTION = "combine"
CATEGORY = "Kinotron"
def combine(self, scene_1,scene_2,scene_3,scene_4,scene_5,scene_6,scene_7,scene_8,scene_9,scene_10,
scene_11,scene_12,scene_13,scene_14,scene_15,scene_16,scene_17,scene_18,scene_19,scene_20, **inputs):
return (scene_1+"###"+scene_2+"###"+scene_3+"###"+scene_4+"###"+scene_5+"###"+scene_6+"###"+scene_7+"###"+scene_8+"###"+scene_9+"###"+scene_10+"###"+scene_11+"###"+scene_12+"###"+scene_13+"###"+scene_14+"###"+scene_15+"###"+scene_16+"###"+scene_17+"###"+scene_18+"###"+scene_19+"###"+scene_20,)
class EmptyList:
@classmethod
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(s):
return {
"required": {
},
}
RETURN_TYPES = ("LIST",)
RETURN_NAMES = ("list",)
FUNCTION = "empty"
CATEGORY = "Kinotron/List"
def empty(self,**inputs):
tmp = TextList(random.randint(1, 99999999))
return (tmp,)
class Append:
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"list": ("LIST", {"multiline": False, "forceInput": True}),
"scene": ("STRING", {"multiline": False, "forceInput": True}),
},
}
RETURN_TYPES = ("LIST",)
RETURN_NAMES = ("list",)
FUNCTION = "append"
CATEGORY = "Kinotron/List"
def append(self, list,scene, **inputs):
list.add(scene)
#print(list.items)
return (list,)
class Append2:
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"list": ("LIST", {"multiline": False, "forceInput": True}),
"scene_1": ("STRING", {"multiline": False, "forceInput": True}),
"scene_2": ("STRING", {"multiline": False, "forceInput": True}),
},
}
RETURN_TYPES = ("LIST",)
RETURN_NAMES = ("list",)
FUNCTION = "append"
CATEGORY = "Kinotron/List"
def append(self, list,scene_1,scene_2, **inputs):
list.add(scene_1)
list.add(scene_2)
tmp = list
#print(list.items)
return (tmp,)
class Append3:
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"list": ("LIST", {"multiline": False, "forceInput": True}),
"scene_1": ("STRING", {"multiline": False, "forceInput": True}),
"scene_2": ("STRING", {"multiline": False, "forceInput": True}),
"scene_3": ("STRING", {"multiline": False, "forceInput": True}),
},
}
RETURN_TYPES = ("LIST",)
RETURN_NAMES = ("list",)
FUNCTION = "append"
CATEGORY = "Kinotron/List"
def append(self, list,scene_1,scene_2,scene_3, **inputs):
list.add(scene_1)
list.add(scene_2)
list.add(scene_3)
#print(list.items)
return (list,)
class Append5:
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"list": ("LIST", {"multiline": False, "forceInput": True}),
"scene_1": ("STRING", {"multiline": False, "forceInput": True}),
"scene_2": ("STRING", {"multiline": False, "forceInput": True}),
"scene_3": ("STRING", {"multiline": False, "forceInput": True}),
"scene_4": ("STRING", {"multiline": False, "forceInput": True}),
"scene_5": ("STRING", {"multiline": False, "forceInput": True}),
},
}
RETURN_TYPES = ("LIST",)
RETURN_NAMES = ("list",)
FUNCTION = "append"
CATEGORY = "Kinotron/List"
def append(self, list,scene_1,scene_2,scene_3,scene_4,scene_5, **inputs):
list.add(scene_1)
list.add(scene_2)
list.add(scene_3)
list.add(scene_4)
list.add(scene_5)
#print(list.items)
return (list,)
#BASIC OPENAI LLM GENERATION
class LoadOpenAI:
@classmethod
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"api_key": ("STRING", {"forceInput": False}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron"
FUNCTION = "load"
RETURN_NAMES = ("model",)
RETURN_TYPES = ("OBJECT",)
def load(self,api_key, **inputs):
print("Loaded OpenAI model")
return (OpenAI(api_key=api_key),)
class Inference:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"prompt": ("STRING", {"multiline": True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron"
FUNCTION = "inference"
RETURN_NAMES = ("output",)
RETURN_TYPES = ("STRING",)
def inference(self,model,prompt, **inputs):
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": ""},
{"role": "user",
"content": prompt}
]
)
print(response.choices[0].message.content)
return (response.choices[0].message.content,)
class InferenceTextInput:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"prompt": ("STRING", {"multiline": True}),
"text": ("STRING", {"multiline": False, "forceInput":True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron"
FUNCTION = "inference"
RETURN_NAMES = ("output",)
RETURN_TYPES = ("STRING",)
def inference(self,model,prompt,text, **inputs):
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": f"Execute the user's prompt on this text: {text}"},
{"role": "user",
"content": prompt}
]
)
print(response.choices[0].message.content)
return (response.choices[0].message.content,)
#ARCHETYPES
class ThreeAct:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"synopsis": ("STRING", {"multiline": True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Archetypes"
FUNCTION = "inference"
RETURN_NAMES = ("Act 1","Act 2","Act 3",)
RETURN_TYPES = ("STRING","STRING","STRING",)
def inference(self,model,synopsis, **inputs):
prompt = f"SYNOPSIS: {synopsis} \n Given this synopsis write a brief description for each of the story's acts, one per line. \n THREE ACTS SUMMARIES:"
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": ""},
{"role": "user",
"content": prompt}
]
)
acts = response.choices[0].message.content.split("\n")
acts = [string for string in acts if string]
print(acts)
return (acts[0],acts[1],acts[2],)
class Freytag:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"synopsis": ("STRING", {"multiline": True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Archetypes"
FUNCTION = "inference"
RETURN_NAMES = ("Exposition","Inciting incident","Rising action","Climax","Falling action","Denouement",)
RETURN_TYPES = ("STRING","STRING","STRING","STRING","STRING","STRING",)
def inference(self,model,synopsis, **inputs):
prompt = f"SYNOPSIS: {synopsis} \n Given this synopsis write a brief description for each of Freytag's 6 pyramid chapters, one per line. \n FREYTAG'S SUMMARIES:"
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": ""},
{"role": "user",
"content": prompt}
]
)
acts = response.choices[0].message.content.split("\n")
acts = [string for string in acts if string]
print(acts)
return (acts[0],acts[1],acts[2],acts[3],acts[4],acts[5])
#TREE EXPANSION
class Expand2:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene": ("STRING", {"forceInput": True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Hierarchical"
FUNCTION = "inference"
RETURN_NAMES = ("model","scene_1","scene_2")
RETURN_TYPES = ("OBJECT","STRING","STRING",)
def inference(self,model,scene, **inputs):
print("Expanding into 2 scenes...")
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": "You are a story machine that takes as input from the user a story scene summary and must produce from it 2 short separate scene summaries that deepen the narrative. Write your output in 1 line, separated the scenes by ###, DO NOT NUMBER THE SCENES. Do not write anything elese."},
{"role": "user",
"content": scene}
]
)
scenes = response.choices[0].message.content.split("###")
for scene in scenes:
scene.replace("\n","")
return (model,scenes[0],scenes[1],)
class Expand3:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene": ("STRING", {"forceInput": True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Hierarchical"
FUNCTION = "inference"
RETURN_NAMES = ("model","scene_1","scene_2","scene_3")
RETURN_TYPES = ("OBJECT","STRING","STRING","STRING",)
def inference(self, model, scene, **inputs):
print("Expanding into 2 scenes...")
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": "You are a story machine that takes as input from the user a story scene summary and must produce from it 3 short separate scene summaries that deepen the narrative. Write your output in 1 line, separated the scenes by ###, DO NOT NUMBER THE SCENES. Do not write anything elese."},
{"role": "user",
"content": scene}
]
)
scenes = response.choices[0].message.content.split("###")
for scene in scenes:
scene.replace("\n","")
return (model, scenes[0], scenes[1], scenes[2])
class Interpolate:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene_A": ("STRING", {"multiline": False, "forceInput":True}),
"scene_B": ("STRING", {"multiline": False, "forceInput": True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Hierarchical"
FUNCTION = "inference"
RETURN_NAMES = ("model","interpolated",)
RETURN_TYPES = ("OBJECT","STRING",)
def inference(self,model,scene_A,scene_B, **inputs):
prompt = f"SCENE A SUMMARY: {scene_A} \n SCENE B SUMMARY: {scene_B} \n Generate the summary for a possible scene inbetween A and B. \n INBETWEEN SCENE SUMMARY:"
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": ""},
{"role": "user",
"content": prompt}
]
)
return (model,response.choices[0].message.content,)
#SEQUENTIAL
class NextScene:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene": ("STRING", {"multiline": False, "forceInput":True}),
"list": ("STRING", {"multiline": False, "forceInput": True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Sequential"
FUNCTION = "inference"
RETURN_NAMES = ("model","scene","list")
RETURN_TYPES = ("OBJECT","STRING","STRING")
def inference(self,model,scene,list, **inputs):
prompt = f"CURRENT SCENE SUMMARY: {scene} \n Generate the next scene summary in the plotline. \n NEXT SCENE SUMMARY:"
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": ""},
{"role": "user",
"content": prompt}
]
)
return (model,response.choices[0].message.content,list+"###\n"+response.choices[0].message.content)
class FirstScene:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"input": ("STRING", {"forceInput":True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Sequential"
FUNCTION = "inference"
RETURN_NAMES = ("model","scene","list")
RETURN_TYPES = ("OBJECT","STRING","STRING")
def inference(self,model,input, **inputs):
prompt = f"STORY LOGLINE/SYNOPSIS: {input} \n Based on this story's summary generate the first scene in it's plotline \n FIRST SCENE SUMMARY:"
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": ""},
{"role": "user",
"content": prompt}
]
)
return (model,response.choices[0].message.content,response.choices[0].message.content)
class EndScene:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene": ("STRING", {"multiline": False, "forceInput":True}),
"list": ("STRING", {"multiline": False, "forceInput": True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Sequential"
FUNCTION = "inference"
RETURN_NAMES = ("model","scene","list")
RETURN_TYPES = ("OBJECT","STRING","STRING")
def inference(self,model,scene,list, **inputs):
prompt = f"CURRENT SCENE SUMMARY: {scene} \n Based on this scene summary generate the appropriate ending scene summary.\n ENDING SCENE SUMMARY:"
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": ""},
{"role": "user",
"content": prompt}
]
)
return (model,response.choices[0].message.content,list+"###\n"+response.choices[0].message.content)
class Negative:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene": ("STRING", {"multiline": True}),
},
}
CATEGORY = "Kinotron/Sequential"
FUNCTION = "inference"
RETURN_NAMES = ("model","scene",)
RETURN_TYPES = ("OBJECT","STRING",)
def inference(self,model,scene, **inputs):
prompt = f"SCENE SUMMARY: {scene} \n Given this scene summary rewrite it but with an opposite outcome. \n OPPOSITE SCENE SUMMARY:"
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": ""},
{"role": "user",
"content": prompt}
]
)
return (model,response.choices[0].message.content,)
#DAGS
class BinaryChoice:
@classmethod
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"weight_A": ("INT",{"default": 1, "min": 0, "max": 1000, "step": 1}),
"weight_B": ("INT", {"default": 1, "min": 0, "max": 1000, "step": 1}),
"scene_A": ("STRING",{"forceInput": True}),
"scene_B": ("STRING",{"forceInput": True}),
},
}
CATEGORY = "Kinotron/DAGs"
FUNCTION = "select"
RETURN_NAMES = ("Scene",)
RETURN_TYPES = ("STRING",)
def select(self,scene_A,scene_B,weight_A,weight_B, **inputs):
if weight_A+weight_B==0:
raise ValueError("At least one weight must be positive!")
p = weight_A/(weight_A+weight_B)
if random.uniform(0, 1) < p:
selected = scene_A
else:
selected = scene_B
return (selected,)
class TernaryChoice:
@classmethod
def IS_CHANGED(s):
return True
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"weight_A": ("INT", {"default": 1, "min": 0, "max": 1000, "step": 1}),
"weight_B": ("INT", {"default": 1, "min": 0, "max": 1000, "step": 1}),
"weight_C": ("INT", {"default": 1, "min": 0, "max": 1000, "step": 1}),
"scene_A": ("STRING", {"forceInput": True}),
"scene_B": ("STRING", {"forceInput": True}),
"scene_C": ("STRING", {"forceInput": True}),
},
}
CATEGORY = "Kinotron/DAGs"
FUNCTION = "select"
RETURN_NAMES = ("Scene",)
RETURN_TYPES = ("STRING",)
def select(self, scene_A, scene_B, scene_C, weight_A, weight_B, weight_C, **inputs):
if weight_A + weight_B + weight_C == 0:
raise ValueError("At least one weight must be positive!")
p = weight_A / (weight_A + weight_B + weight_C)
q = (weight_A + weight_B) / (weight_A + weight_B + weight_C)
x = random.uniform(0, 1)
if x < p:
selected = scene_A
else:
if x < q:
selected = scene_B
else:
selected = scene_C
return (selected,)
#GENERATION
class Prose:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene": ("STRING", {"multiline": False, "forceInput":True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Generation"
FUNCTION = "inference"
RETURN_NAMES = ("prose",)
RETURN_TYPES = ("STRING",)
def inference(self,model,scene, **inputs):
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": "You are an expert writer, given the user's summary, write prose narrative text."},
{"role": "user",
"content": scene}
]
)
print(response.choices[0].message.content)
return (response.choices[0].message.content,)
class Script:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene": ("STRING", {"multiline": False, "forceInput":True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Generation"
FUNCTION = "inference"
RETURN_NAMES = ("script",)
RETURN_TYPES = ("STRING",)
def inference(self,model,scene, **inputs):
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": "You are an expert screenwriter, given the user's scene summary, write the corresponding film script text in Fountain format."},
{"role": "user",
"content": scene}
]
)
print(response.choices[0].message.content)
return (response.choices[0].message.content,)
class ScriptList:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"list": ("LIST", {"multiline": False, "forceInput":True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Generation"
FUNCTION = "inference"
RETURN_NAMES = ("script",)
RETURN_TYPES = ("STRING",)
def inference(self,model,list, **inputs):
for scene in list.items:
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": "You are an expert screenwriter, given the user's scene summary, write the corresponding film script text in Fountain format."},
{"role": "user",
"content": scene}
]
)
output = output + response.choices[0].message.content
#print(response.choices[0].message.content)
return (output,)
class ProseScript:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model": ("OBJECT",),
"scene": ("STRING", {"multiline": False, "forceInput":True}),
},
}
OUTPUT_NODE = True
CATEGORY = "Kinotron/Generation"
FUNCTION = "inference"
RETURN_NAMES = ("script",)
RETURN_TYPES = ("STRING",)
def inference(self,model,scene, **inputs):
response = model.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system",
"content": "You are an expert algorithm that transforms prose narrative text into the corresponding film script interpretation, given the user's prose text, write the correct film script text in Fountain format."},
{"role": "user",
"content": scene}
]
)
print(response.choices[0].message.content)
return (response.choices[0].message.content,)
NODE_CLASS_MAPPINGS = {
#IO
"Text Input": TextInput,
"To Console": ToConsole,
"To Console (List)": ToConsoleList,
"Combine": Combine,
#"Save Text": SaveText,
#Lists
"Empty List": EmptyList,
"Append": Append,
"Append (2)": Append2,
"Append (3)": Append3,
"Append (5)": Append5,
#Basic inference
"Load OpenAI": LoadOpenAI,
"Inference": Inference,
"Inference (Input)": InferenceTextInput,
#ScriptGeneration
"Generate Prose": Prose,
"Generate Script": Script,
"Genere Script (List)": ScriptList,
"Prose-to-Script": ProseScript,
#Sequential
"First Scene": FirstScene,
"Next Scene": NextScene,
"Ending": EndScene,
#Tree
"Expand (2)": Expand2,
"Expand (3)": Expand3,
"Interpolate": Interpolate,
#DAG
"Negative": Negative,
"Random (2)": BinaryChoice,
"Random (3)": TernaryChoice,
#Archetypes
"3-Act": ThreeAct,
"Freytag": Freytag,
#"Monomyth": Monomyth,
}