File size: 49,451 Bytes
af895b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "!pip install langchain langchain_core langgraph langchain_groq langgraph pydantic -U faiss-cpu"
      ],
      "metadata": {
        "id": "9zTQHLHLV8sX",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "1a52e540-04d3-4b47-802e-069c848e30ad"
      },
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: langchain in /usr/local/lib/python3.11/dist-packages (0.3.25)\n",
            "Requirement already satisfied: langchain_core in /usr/local/lib/python3.11/dist-packages (0.3.60)\n",
            "Collecting langchain_core\n",
            "  Downloading langchain_core-0.3.62-py3-none-any.whl.metadata (5.8 kB)\n",
            "Requirement already satisfied: langgraph in /usr/local/lib/python3.11/dist-packages (0.4.7)\n",
            "Requirement already satisfied: langchain_groq in /usr/local/lib/python3.11/dist-packages (0.3.2)\n",
            "Requirement already satisfied: pydantic in /usr/local/lib/python3.11/dist-packages (2.11.4)\n",
            "Collecting pydantic\n",
            "  Downloading pydantic-2.11.5-py3-none-any.whl.metadata (67 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m67.2/67.2 kB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hCollecting faiss-cpu\n",
            "  Downloading faiss_cpu-1.11.0-cp311-cp311-manylinux_2_28_x86_64.whl.metadata (4.8 kB)\n",
            "Requirement already satisfied: langchain-text-splitters<1.0.0,>=0.3.8 in /usr/local/lib/python3.11/dist-packages (from langchain) (0.3.8)\n",
            "Requirement already satisfied: langsmith<0.4,>=0.1.17 in /usr/local/lib/python3.11/dist-packages (from langchain) (0.3.42)\n",
            "Requirement already satisfied: SQLAlchemy<3,>=1.4 in /usr/local/lib/python3.11/dist-packages (from langchain) (2.0.41)\n",
            "Requirement already satisfied: requests<3,>=2 in /usr/local/lib/python3.11/dist-packages (from langchain) (2.32.3)\n",
            "Requirement already satisfied: PyYAML>=5.3 in /usr/local/lib/python3.11/dist-packages (from langchain) (6.0.2)\n",
            "Requirement already satisfied: tenacity!=8.4.0,<10.0.0,>=8.1.0 in /usr/local/lib/python3.11/dist-packages (from langchain_core) (9.1.2)\n",
            "Requirement already satisfied: jsonpatch<2.0,>=1.33 in /usr/local/lib/python3.11/dist-packages (from langchain_core) (1.33)\n",
            "Requirement already satisfied: packaging<25,>=23.2 in /usr/local/lib/python3.11/dist-packages (from langchain_core) (24.2)\n",
            "Requirement already satisfied: typing-extensions>=4.7 in /usr/local/lib/python3.11/dist-packages (from langchain_core) (4.13.2)\n",
            "Requirement already satisfied: langgraph-checkpoint>=2.0.26 in /usr/local/lib/python3.11/dist-packages (from langgraph) (2.0.26)\n",
            "Requirement already satisfied: langgraph-prebuilt>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from langgraph) (0.2.2)\n",
            "Requirement already satisfied: langgraph-sdk>=0.1.42 in /usr/local/lib/python3.11/dist-packages (from langgraph) (0.1.70)\n",
            "Requirement already satisfied: xxhash>=3.5.0 in /usr/local/lib/python3.11/dist-packages (from langgraph) (3.5.0)\n",
            "Requirement already satisfied: groq<1,>=0.4.1 in /usr/local/lib/python3.11/dist-packages (from langchain_groq) (0.25.0)\n",
            "Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic) (0.7.0)\n",
            "Requirement already satisfied: pydantic-core==2.33.2 in /usr/local/lib/python3.11/dist-packages (from pydantic) (2.33.2)\n",
            "Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from pydantic) (0.4.1)\n",
            "Requirement already satisfied: numpy<3.0,>=1.25.0 in /usr/local/lib/python3.11/dist-packages (from faiss-cpu) (2.0.2)\n",
            "Requirement already satisfied: anyio<5,>=3.5.0 in /usr/local/lib/python3.11/dist-packages (from groq<1,>=0.4.1->langchain_groq) (4.9.0)\n",
            "Requirement already satisfied: distro<2,>=1.7.0 in /usr/local/lib/python3.11/dist-packages (from groq<1,>=0.4.1->langchain_groq) (1.9.0)\n",
            "Requirement already satisfied: httpx<1,>=0.23.0 in /usr/local/lib/python3.11/dist-packages (from groq<1,>=0.4.1->langchain_groq) (0.28.1)\n",
            "Requirement already satisfied: sniffio in /usr/local/lib/python3.11/dist-packages (from groq<1,>=0.4.1->langchain_groq) (1.3.1)\n",
            "Requirement already satisfied: jsonpointer>=1.9 in /usr/local/lib/python3.11/dist-packages (from jsonpatch<2.0,>=1.33->langchain_core) (3.0.0)\n",
            "Requirement already satisfied: ormsgpack<2.0.0,>=1.8.0 in /usr/local/lib/python3.11/dist-packages (from langgraph-checkpoint>=2.0.26->langgraph) (1.10.0)\n",
            "Requirement already satisfied: orjson>=3.10.1 in /usr/local/lib/python3.11/dist-packages (from langgraph-sdk>=0.1.42->langgraph) (3.10.18)\n",
            "Requirement already satisfied: requests-toolbelt<2.0.0,>=1.0.0 in /usr/local/lib/python3.11/dist-packages (from langsmith<0.4,>=0.1.17->langchain) (1.0.0)\n",
            "Requirement already satisfied: zstandard<0.24.0,>=0.23.0 in /usr/local/lib/python3.11/dist-packages (from langsmith<0.4,>=0.1.17->langchain) (0.23.0)\n",
            "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (3.4.2)\n",
            "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (3.10)\n",
            "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (2.4.0)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2->langchain) (2025.4.26)\n",
            "Requirement already satisfied: greenlet>=1 in /usr/local/lib/python3.11/dist-packages (from SQLAlchemy<3,>=1.4->langchain) (3.2.2)\n",
            "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.11/dist-packages (from httpx<1,>=0.23.0->groq<1,>=0.4.1->langchain_groq) (1.0.9)\n",
            "Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.11/dist-packages (from httpcore==1.*->httpx<1,>=0.23.0->groq<1,>=0.4.1->langchain_groq) (0.16.0)\n",
            "Downloading langchain_core-0.3.62-py3-none-any.whl (438 kB)\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m438.4/438.4 kB\u001b[0m \u001b[31m11.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hDownloading pydantic-2.11.5-py3-none-any.whl (444 kB)\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m444.2/444.2 kB\u001b[0m \u001b[31m22.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hDownloading faiss_cpu-1.11.0-cp311-cp311-manylinux_2_28_x86_64.whl (31.3 MB)\n",
            "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m31.3/31.3 MB\u001b[0m \u001b[31m25.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hInstalling collected packages: faiss-cpu, pydantic, langchain_core\n",
            "  Attempting uninstall: pydantic\n",
            "    Found existing installation: pydantic 2.11.4\n",
            "    Uninstalling pydantic-2.11.4:\n",
            "      Successfully uninstalled pydantic-2.11.4\n",
            "  Attempting uninstall: langchain_core\n",
            "    Found existing installation: langchain-core 0.3.60\n",
            "    Uninstalling langchain-core-0.3.60:\n",
            "      Successfully uninstalled langchain-core-0.3.60\n",
            "Successfully installed faiss-cpu-1.11.0 langchain_core-0.3.62 pydantic-2.11.5\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "import ast\n",
        "from pydantic import BaseModel, Field\n",
        "from typing import Optional\n",
        "import pandas as pd\n",
        "from langchain_core.messages import SystemMessage, HumanMessage\n",
        "from langgraph.graph import StateGraph, START, END\n",
        "from langchain_core.tools import tool\n",
        "from sentence_transformers import SentenceTransformer\n",
        "import numpy as np\n",
        "import faiss\n",
        "\n",
        "\n",
        "from google.colab import userdata\n",
        "os.environ['GROQ_API_KEY']=userdata.get('groq_api_subash')\n",
        "\n",
        "class State(BaseModel):\n",
        "  topic: str\n",
        "  business_details: Optional[dict]\n",
        "  ideator_response: Optional[str] = None\n",
        "  critic_response: Optional[str]=None\n",
        "  improver_response: Optional[str]=None\n",
        "  validator_response: Optional[str]=None\n",
        "  validator_defense1: Optional[str]=None\n",
        "  validator_defense2: Optional[str]=None\n",
        "  validator_defense3: Optional[str]=None\n"
      ],
      "metadata": {
        "id": "7VvhMZXfwatP"
      },
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from langchain_groq import ChatGroq\n",
        "from langgraph.prebuilt import create_react_agent\n",
        "\n",
        "llm = ChatGroq(\n",
        "    model=\"llama3-8b-8192\",\n",
        "    temperature=0.3,\n",
        "    max_tokens=500,\n",
        "\n",
        ")\n",
        "\n",
        "ideator_llm = llm\n",
        "critic_llm = llm\n",
        "improver_llm = llm\n",
        "validator_llm = llm\n"
      ],
      "metadata": {
        "id": "4RXVmUFG8Osd"
      },
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "\n",
        "ST = SentenceTransformer('mixedbread-ai/mxbai-embed-large-v1')\n",
        "class QueryFormatter(BaseModel):\n",
        "    video_topic: str = Field(description=\"The video topic that user passes to the agent\")\n",
        "\n",
        "@tool(\"influencer's data-retrieval-tool\", args_schema=QueryFormatter, return_direct=False,description=\"Retrieve influencer-related data for a given query.\")\n",
        "def retrieve_tool(video_topic):\n",
        "    '''\n",
        "    Always invoke this tool.\n",
        "    Retrieve influencer's data by semantic search of **video topic**.\n",
        "    '''\n",
        "    # === Load CSV ===\n",
        "    csv_path = 'extracted_data.csv'\n",
        "    df = pd.read_csv(csv_path)\n",
        "\n",
        "    # === Parse stored embeddings ===\n",
        "    df['embeddings'] = df['embeddings'].apply(lambda x: ast.literal_eval(x) if isinstance(x, str) else x)\n",
        "    embeddings = np.vstack(df['embeddings'].values).astype('float32')\n",
        "\n",
        "    # === Build FAISS index ===\n",
        "    dimension = embeddings.shape[1]\n",
        "    index = faiss.IndexFlatL2(dimension)\n",
        "    index.add(embeddings)\n",
        "\n",
        "    # === Load SentenceTransformer model ===\n",
        "\n",
        "    # === Encode the query and search ===\n",
        "    query_embedding = ST.encode(str(video_topic)).reshape(1, -1).astype('float32')\n",
        "    top_k=7\n",
        "    distances, indices = index.search(query_embedding, top_k)\n",
        "\n",
        "\n",
        "\n",
        "    # === Format results ===\n",
        "    outer_list = []\n",
        "    for i, idx in enumerate(indices[0]):\n",
        "        res = {\n",
        "            'rank': i + 1,\n",
        "            'username': df.iloc[idx]['username'],\n",
        "            'story': df.iloc[idx]['story'],\n",
        "            'visible_text_or_brandings': df.iloc[idx]['story'],\n",
        "            'likesCount': df.iloc[idx]['likesCount'],\n",
        "            'commentCount': df.iloc[idx]['commentCount'],\n",
        "        }\n",
        "\n",
        "        inner_list = []\n",
        "        inner_list.append(f\"[{res['rank']}]. The influencer name is: **{res['username']}** β€” Likes: **{res['likesCount']}**, Comments: **{res['commentCount']}**\")\n",
        "        inner_list.append(f\"The story of that particular video is:\\n{res['story']}\")\n",
        "        inner_list.append(f\"The branding or promotion done is:\\n{res['visible_text_or_brandings']}\")\n",
        "\n",
        "        outer_list.append(inner_list)\n",
        "\n",
        "    return str(outer_list)\n",
        "\n",
        "# retrieve_tool('I want to promote my restaurant')"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "AH3YslAR6doR",
        "outputId": "c50bdc94-c153-40e7-ae8b-b2c1a8f329e0"
      },
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.11/dist-packages/huggingface_hub/utils/_auth.py:94: UserWarning: \n",
            "The secret `HF_TOKEN` does not exist in your Colab secrets.\n",
            "To authenticate with the Hugging Face Hub, create a token in your settings tab (https://huggingface.co/settings/tokens), set it as secret in your Google Colab and restart your session.\n",
            "You will be able to reuse this secret in all of your notebooks.\n",
            "Please note that authentication is recommended but still optional to access public models or datasets.\n",
            "  warnings.warn(\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "\n",
        "def ideator(state:State):\n",
        "  tools=[retrieve_tool]\n",
        "  react_agent=create_react_agent(\n",
        "    model=llm,\n",
        "    tools=tools\n",
        "  )\n",
        "  template = f'''\n",
        "  You are an expert video content strategist who generates the storyline of a video in exactly 300 words..\n",
        "\n",
        "Your task is to generate a **detailed and creative storyline** for a promotional video on the **given topic**. The storyline should be structured, engaging, and highly relevant to the following **business details**.\n",
        "Another important thing is that you have to give the response  focusing on the response of the tool provided to you. The tool contains the video stories and contents created by the influencers.\n",
        "Use that responses of tool for your reference. You can use your creativity but inside the boundary of tool's response.\n",
        "\n",
        "---\n",
        "\n",
        " **Video Topic**:\n",
        "{state.topic}\n",
        "\n",
        "**Business Details**:\n",
        "{state.business_details}\n",
        "\n",
        "\n",
        "\n",
        "---\n",
        "\n",
        "**Important Instructions**:\n",
        "- Creatively connect the image cues to make the storyline compelling. (If provided).\n",
        "- Structure the storyline logically (e.g., beginning, middle, end), showing what scenes or visuals to include.\n",
        "- Match the tone and depth to the business type (e.g., fun, luxurious, emotional, professional).\n",
        "\n",
        "Now, generate the final storyline for the video topic..\n",
        "  '''\n",
        "  messages = [SystemMessage(content=template),\n",
        "                HumanMessage(content=f'''The topic of the video is:\\n{state.topic}\\n''')]\n",
        "\n",
        "  response = react_agent.invoke({'messages':messages})\n",
        "  response = response['messages'][-1].content\n",
        "  state.ideator_response = response\n",
        "  print('Ideator Generated the story')\n",
        "  return state\n",
        "\n",
        "\n",
        "\n"
      ],
      "metadata": {
        "id": "xIrE3FV03nQz"
      },
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "def critic(state:State):\n",
        "  tools=[retrieve_tool]\n",
        "  react_agent=create_react_agent(\n",
        "    model=llm,\n",
        "    tools=tools\n",
        "  )\n",
        "  critic_template = f'''\n",
        "  You are an expert evaluator and suggestion recommender. Your role is to carefully read the story generated by the Ideator and assess it based on the given video topic, business details, and the tool's response.\n",
        "\n",
        "  Your task is to **critically evaluate** the storyline of a promotional video provided below from ideator. The storyline was generated based on a given video topic and business details. Additionally, the tool's response contains existing influencer-style stories or content for reference, which you must **closely consider** to guide your evaluation.\n",
        "\n",
        "  ---\n",
        "\n",
        "   **Video Topic**:\n",
        "  {state.topic}\n",
        "\n",
        "   **Business Details**:\n",
        "  {state.business_details}\n",
        "\n",
        "   **Generated Storyline from ideator**:\n",
        "  {state.ideator_response}\n",
        "\n",
        "\n",
        "  ---\n",
        "\n",
        "   **Your Task as the Critic**:\n",
        "\n",
        "  1. **Evaluate the Storyline**: Analyze the structure, creativity, tone, and alignment with the business type and audience.\n",
        "  2. **Compare with Tool's Response**: Ensure the storyline stays within the creative boundaries and tone of the influencer-style content in the tool response.\n",
        "  3. **Identify Weaknesses**: Point out inconsistencies, missing elements, weak hooks, structural flaws, or areas lacking emotional or persuasive power.\n",
        "  4. **Suggest Improvements**: Provide clear, actionable suggestions to improve the storyline.\n",
        "\n",
        "  **Output**:\n",
        "  You have to just suggest the improvements in your output in around 100 words only.\n",
        "  '''\n",
        "\n",
        "  messages = [SystemMessage(content=critic_template),\n",
        "                HumanMessage(content=f'''The topic of the video is:\\n{state.topic}\\n. The business_details is\\n{state.business_details}\\n''')]\n",
        "\n",
        "  response = react_agent.invoke({'messages':messages})\n",
        "  response = response['messages'][-1].content\n",
        "  state.critic_response = response\n",
        "  print('Critic Evaluated the story')\n",
        "\n",
        "  return state\n"
      ],
      "metadata": {
        "id": "OKRJsG0J_a5t"
      },
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "def improver(state:State):\n",
        "  react_agent=create_react_agent(\n",
        "    model=llm,\n",
        "    tools=[]\n",
        "  )\n",
        "  improver_template = f'''\n",
        "  You are a professional video content editor and creative storyteller. Your job is to improve the storyline originally generated by the Ideator using the detailed feedback provided by the Critic.\n",
        "\n",
        "  The story was written for a promotional video based on a specific topic and business context. You must revise it while staying aligned with the given business needs and creative direction. The improvement suggestions come from a Critic who has evaluated the structure, tone, creativity, and alignment of the original story.\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Video Topic**:\n",
        "  {state.topic}\n",
        "\n",
        "  **Business Details**:\n",
        "  {state.business_details}\n",
        "\n",
        "  **Original Storyline from Ideator**:\n",
        "  {state.ideator_response}\n",
        "\n",
        "  **Critic's Suggestions for Improvement**:\n",
        "  {state.critic_response}\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Your Task**:\n",
        "\n",
        "  - Carefully read the original story and the critic’s suggestions.\n",
        "  - Revise and enhance the storyline, correcting flaws and adding the suggested improvements.\n",
        "  - Keep the tone, structure, and message appropriate to the business type and the influencer-style content.\n",
        "  - Make sure the final story is structured, compelling, and exactly **300 words** in length.\n",
        "\n",
        "  Now, generate the **final improved storyline** for the video.\n",
        "  '''\n",
        "\n",
        "\n",
        "  messages = [SystemMessage(content=improver_template),\n",
        "                HumanMessage(content=f'''The topic of the video is:\\n{state.topic}\\n The business_details is:\\n{state.business_details}''')]\n",
        "\n",
        "  response = react_agent.invoke({'messages':messages})\n",
        "  response = response['messages'][-1].content\n",
        "  state.improver_response = response\n",
        "  print('Improver Improvred the story')\n",
        "\n",
        "  return state\n"
      ],
      "metadata": {
        "id": "fq0JPkrZCJj-"
      },
      "execution_count": 6,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "class ValidationFormatter(BaseModel):\n",
        "  result: str = Field(description=\"Returns **validated** if the story is validated. Returns **not validated** if story is not validated.\")\n",
        "\n",
        "def validator(state:State):\n",
        "  tools=[retrieve_tool]\n",
        "\n",
        "  react_agent=create_react_agent(\n",
        "    model=llm,\n",
        "    tools=tools,\n",
        "    # response_format=ValidationFormatter\n",
        "  )\n",
        "  validator_template = f'''\n",
        "  You are a strict and unbiased judge responsible for evaluating whether a promotional video storyline is ready for publishing.\n",
        "\n",
        "  You will be given the video topic, business details, and the final version of the storyline (after improvement). Your task is to assess if this storyline meets all necessary standards in terms of:\n",
        "\n",
        "  - Relevance to the video topic\n",
        "  - Alignment with the business context\n",
        "  - Logical structure (beginning, middle, end)\n",
        "  - Tone matching the business type\n",
        "  - Creativity and clarity\n",
        "\n",
        "  You can also use the tool's response as your reference to make the validation. The tool's response includes existing influencer-style stories or content for reference.\n",
        "\n",
        "  ---\n",
        "\n",
        "\n",
        "  **Video Topic**:\n",
        "  {state.topic}\n",
        "\n",
        "  **Business Details**:\n",
        "  {state.business_details}\n",
        "\n",
        "  **Final Storyline from Improver**:\n",
        "  {state.improver_response}\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Validation Criteria**:\n",
        "\n",
        "  - Is the story **fully aligned** with the topic, business details and the tool's response?\n",
        "  - Does the structure flow logically and effectively?\n",
        "  - Does it feel complete and professional to use this story to create a video?\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Output Instruction**:\n",
        "  Respond strictly just with one of the following values:\n",
        "\n",
        "  - `validated` – if the story meets all the criteria and is validated.\n",
        "  - `not validated` – if it fails to meet any key criteria and needs further improvement.\n",
        "  '''\n",
        "\n",
        "\n",
        "\n",
        "  messages = [SystemMessage(content=validator_template),\n",
        "                HumanMessage(content=f'''The topic of the video is:\\n{state.topic}\\n The business_details is:\\n{state.business_details}''')]\n",
        "\n",
        "  response = llm.with_structured_output(ValidationFormatter).invoke(messages)\n",
        "  print('Validator response:',response)\n",
        "  state.validator_response = response.result\n",
        "  return state"
      ],
      "metadata": {
        "id": "LfgWPNJUFOf7"
      },
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "def validator_defense1(state:State):\n",
        "  tools=[retrieve_tool]\n",
        "\n",
        "  react_agent=create_react_agent(\n",
        "    model=llm,\n",
        "    tools=tools,\n",
        "    # response_format=ValidationFormatter\n",
        "  )\n",
        "  validator_template = f'''\n",
        "  You are a strict and unbiased judge responsible for evaluating whether a promotional video storyline is ready for publishing.\n",
        "\n",
        "  You will be given the video topic, business details, and the final version of the storyline (after improvement). Your task is to assess if this storyline meets all necessary standards in terms of:\n",
        "\n",
        "  - Relevance to the video topic\n",
        "  - Alignment with the business context\n",
        "  - Logical structure (beginning, middle, end)\n",
        "  - Tone matching the business type\n",
        "  - Creativity and clarity\n",
        "\n",
        "  You can also use the tool's response as your reference to make the validation. The tool's response includes existing influencer-style stories or content for reference.\n",
        "\n",
        "  ---\n",
        "\n",
        "\n",
        "  **Video Topic**:\n",
        "  {state.topic}\n",
        "\n",
        "  **Business Details**:\n",
        "  {state.business_details}\n",
        "\n",
        "  **Final Storyline from Improver**:\n",
        "  {state.improver_response}\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Validation Criteria**:\n",
        "\n",
        "  - Is the story **fully aligned** with the topic, business details and the tool's response?\n",
        "  - Does the structure flow logically and effectively?\n",
        "  - Does it feel complete and professional to use this story to create a video?\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Output Instruction**:\n",
        "  Respond strictly just with one of the following values:\n",
        "\n",
        "  - `validated` – if the story meets all the criteria and is validated.\n",
        "  - `not validated` – if it fails to meet any key criteria and needs further improvement.\n",
        "  '''\n",
        "\n",
        "\n",
        "\n",
        "  messages = [SystemMessage(content=validator_template),\n",
        "                HumanMessage(content=f'''The topic of the video is:\\n{state.topic}\\n The business_details is:\\n{state.business_details}''')]\n",
        "\n",
        "  response = llm.with_structured_output(ValidationFormatter).invoke(messages)\n",
        "  print('Validator defense 1 response:',response)\n",
        "  state.validator_defense1 = response.result\n",
        "  return state\n",
        "\n",
        "\n",
        "def validator_defense2(state:State):\n",
        "  tools=[retrieve_tool]\n",
        "\n",
        "  react_agent=create_react_agent(\n",
        "    model=llm,\n",
        "    tools=tools,\n",
        "    # response_format=ValidationFormatter\n",
        "  )\n",
        "  validator_template = f'''\n",
        "  You are a strict and unbiased judge responsible for evaluating whether a promotional video storyline is ready for publishing.\n",
        "\n",
        "  You will be given the video topic, business details, and the final version of the storyline (after improvement). Your task is to assess if this storyline meets all necessary standards in terms of:\n",
        "\n",
        "  - Relevance to the video topic\n",
        "  - Alignment with the business context\n",
        "  - Logical structure (beginning, middle, end)\n",
        "  - Tone matching the business type\n",
        "  - Creativity and clarity\n",
        "\n",
        "  You can also use the tool's response as your reference to make the validation. The tool's response includes existing influencer-style stories or content for reference.\n",
        "\n",
        "  ---\n",
        "\n",
        "\n",
        "  **Video Topic**:\n",
        "  {state.topic}\n",
        "\n",
        "  **Business Details**:\n",
        "  {state.business_details}\n",
        "\n",
        "  **Final Storyline from Improver**:\n",
        "  {state.improver_response}\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Validation Criteria**:\n",
        "\n",
        "  - Is the story **fully aligned** with the topic, business details and the tool's response?\n",
        "  - Does the structure flow logically and effectively?\n",
        "  - Does it feel complete and professional to use this story to create a video?\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Output Instruction**:\n",
        "  Respond strictly just with one of the following values:\n",
        "\n",
        "  - `validated` – if the story meets all the criteria and is validated.\n",
        "  - `not validated` – if it fails to meet any key criteria and needs further improvement.\n",
        "  '''\n",
        "\n",
        "\n",
        "\n",
        "  messages = [SystemMessage(content=validator_template),\n",
        "                HumanMessage(content=f'''The topic of the video is:\\n{state.topic}\\n The business_details is:\\n{state.business_details}''')]\n",
        "\n",
        "  response = llm.with_structured_output(ValidationFormatter).invoke(messages)\n",
        "  print('Validator defense 2 response:',response)\n",
        "  state.validator_defense2 = response.result\n",
        "  return state\n",
        "\n",
        "\n",
        "def validator_defense3(state:State):\n",
        "  tools=[retrieve_tool]\n",
        "\n",
        "  react_agent=create_react_agent(\n",
        "    model=llm,\n",
        "    tools=tools,\n",
        "    # response_format=ValidationFormatter\n",
        "  )\n",
        "  validator_template = f'''\n",
        "  You are a strict and unbiased judge responsible for evaluating whether a promotional video storyline is ready for publishing.\n",
        "\n",
        "  You will be given the video topic, business details, and the final version of the storyline (after improvement). Your task is to assess if this storyline meets all necessary standards in terms of:\n",
        "\n",
        "  - Relevance to the video topic\n",
        "  - Alignment with the business context\n",
        "  - Logical structure (beginning, middle, end)\n",
        "  - Tone matching the business type\n",
        "  - Creativity and clarity\n",
        "\n",
        "  You can also use the tool's response as your reference to make the validation. The tool's response includes existing influencer-style stories or content for reference.\n",
        "\n",
        "  ---\n",
        "\n",
        "\n",
        "  **Video Topic**:\n",
        "  {state.topic}\n",
        "\n",
        "  **Business Details**:\n",
        "  {state.business_details}\n",
        "\n",
        "  **Final Storyline from Improver**:\n",
        "  {state.improver_response}\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Validation Criteria**:\n",
        "\n",
        "  - Is the story **fully aligned** with the topic, business details and the tool's response?\n",
        "  - Does the structure flow logically and effectively?\n",
        "  - Does it feel complete and professional to use this story to create a video?\n",
        "\n",
        "  ---\n",
        "\n",
        "  **Output Instruction**:\n",
        "  Respond strictly just with one of the following values:\n",
        "\n",
        "  - `validated` – if the story meets all the criteria and is validated.\n",
        "  - `not validated` – if it fails to meet any key criteria and needs further improvement.\n",
        "  '''\n",
        "\n",
        "\n",
        "\n",
        "  messages = [SystemMessage(content=validator_template),\n",
        "                HumanMessage(content=f'''The topic of the video is:\\n{state.topic}\\n The business_details is:\\n{state.business_details}''')]\n",
        "\n",
        "  response = llm.with_structured_output(ValidationFormatter).invoke(messages)\n",
        "  print('Validator defense 3 response:',response)\n",
        "  state.validator_defense3 = response.result\n",
        "  return state"
      ],
      "metadata": {
        "id": "WFEYu06yrPre"
      },
      "execution_count": 8,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "def route1_after_validation(state:State):\n",
        "  if 'not validated' in state.validator_response:\n",
        "    return False\n",
        "  else:\n",
        "    return True\n",
        "\n",
        "def route2_after_validation(state:State):\n",
        "  if 'not validated' in state.validator_defense1:\n",
        "    return False\n",
        "  else:\n",
        "    return True\n",
        "def route3_after_validation(state:State):\n",
        "  if 'not validated' in state.validator_defense2:\n",
        "    return False\n",
        "  else:\n",
        "    return True\n",
        "def route4_after_validation(state:State):\n",
        "  if 'not validated' in state.validator_defense3:\n",
        "    return False\n",
        "  else:\n",
        "    return True"
      ],
      "metadata": {
        "id": "ThZLEFFxjKwE"
      },
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "graph_builder= StateGraph(State)\n",
        "graph_builder.add_node(ideator)\n",
        "graph_builder.add_node(critic)\n",
        "graph_builder.add_node(improver)\n",
        "graph_builder.add_node(validator)\n",
        "graph_builder.add_node(validator_defense1)\n",
        "graph_builder.add_node(validator_defense2)\n",
        "graph_builder.add_node(validator_defense3)\n",
        "\n",
        "\n",
        "graph_builder.add_edge(START, \"ideator\")  # Start the graph with node_1\n",
        "graph_builder.add_edge(\"ideator\", \"critic\")\n",
        "graph_builder.add_edge(\"critic\", \"improver\")\n",
        "graph_builder.add_edge(\"improver\", \"validator\")\n",
        "graph_builder.add_edge(\"validator\", \"validator_defense1\")\n",
        "graph_builder.add_edge(\"validator_defense1\", \"validator_defense2\")\n",
        "graph_builder.add_edge(\"validator_defense2\", \"validator_defense3\")\n",
        "graph_builder.add_edge(\"validator_defense3\", END)\n",
        "\n",
        "# Use conditional routing from validator\n",
        "graph_builder.add_conditional_edges(\"validator\", route1_after_validation,{False:'ideator',True:validator_defense1})\n",
        "graph_builder.add_conditional_edges(\"validator_defense1\", route2_after_validation,{False:'ideator',True:validator_defense2})\n",
        "graph_builder.add_conditional_edges(\"validator_defense2\", route3_after_validation,{False:'ideator',True:validator_defense3})\n",
        "graph_builder.add_conditional_edges(\"validator_defense3\", route4_after_validation,{False:'ideator',True:END})\n",
        "\n",
        "graph = graph_builder.compile()\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 332
        },
        "id": "-kZyUySjLHDN",
        "outputId": "37026fc3-6925-4256-9a87-6d8d64f4f971"
      },
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "error",
          "ename": "ValueError",
          "evalue": "'validator_defense1' is already being used as a state key",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-10-0d5781a7ad7c>\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0mgraph_builder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_node\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimprover\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0mgraph_builder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_node\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidator\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mgraph_builder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_node\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidator_defense1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      7\u001b[0m \u001b[0mgraph_builder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_node\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidator_defense2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      8\u001b[0m \u001b[0mgraph_builder\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_node\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvalidator_defense3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.11/dist-packages/langgraph/graph/state.py\u001b[0m in \u001b[0;36madd_node\u001b[0;34m(self, node, action, defer, metadata, input, retry, cache_policy, destinations)\u001b[0m\n\u001b[1;32m    358\u001b[0m                 )\n\u001b[1;32m    359\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mnode\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mchannels\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 360\u001b[0;31m             \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"'{node}' is already being used as a state key\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    361\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompiled\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    362\u001b[0m             logger.warning(\n",
            "\u001b[0;31mValueError\u001b[0m: 'validator_defense1' is already being used as a state key"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from IPython.display import Image, display\n",
        "\n",
        "try:\n",
        "    display(Image(graph.get_graph().draw_mermaid_png()))\n",
        "except Exception:\n",
        "    # This requires some extra dependencies and is optional\n",
        "    pass"
      ],
      "metadata": {
        "id": "aLblIS1cnRLT"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "state = graph.invoke({\"topic\": \"I want to promote my restaurant in lakeside\",\n",
        "                      \"business_details\": {\"business_type\": \"restaurant\", \"platform\": \"instagram\", \"target_audience\": \"youths\", \"business_goals\": \"to go global\", \"offerings\": \"nepali foods\", \"Challenges_faced\": \"finding new customers, attracting large customers\"}\n",
        "                      })"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "csSPO6MwMNoM",
        "outputId": "33fb1b07-c154-4ecd-ab27-f9a2fd7b395c"
      },
      "execution_count": 18,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Ideator Generated the story\n",
            "Critic Evaluated the story\n",
            "Improver Improvred the story\n",
            "Validator response: result='validated'\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "state['validator_response']"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "id": "kriV_zErMvGf",
        "outputId": "a247c871-9e05-4f4b-b670-08cc6a938638"
      },
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'validated'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 22
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "state['improver_response']"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 122
        },
        "id": "E2onpug1S7sU",
        "outputId": "eb43ce63-1e68-40fa-8956-75f795bc8ce8"
      },
      "execution_count": 19,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Here is the revised storyline for the promotional video:\\n\\n**Title:** \"Experience the Flavors of Nepal at [Your Restaurant Name] in Lakeside\"\\n\\n**Scene 1:** (0:00 - 0:30)\\n\\n* Opening shot of a stunning visual of the restaurant\\'s exterior, with a warm and inviting glow emanating from the windows.\\n* Voiceover: \"Imagine a place where the beauty of Lakeside meets the flavors of Nepal. Welcome to [Your Restaurant Name], where every bite is a journey to the Himalayas.\"\\n\\n**Scene 2:** (0:30 - 1:00)\\n\\n* Cut to a shot of a group of friends laughing and chatting while enjoying their meals at the restaurant.\\n* Voiceover: \"Our restaurant is more than just a place to eat - it\\'s a gathering spot for friends and family to share in the joy of good food and good company.\"\\n\\n**Scene 3:** (1:00 - 1:30)\\n\\n* Cut to a shot of the restaurant\\'s chefs preparing traditional Nepali dishes, with close-ups of the sizzling pans and aromatic spices.\\n* Voiceover: \"Our chefs use only the freshest ingredients to create authentic Nepali dishes that will tantalize your taste buds.\"\\n\\n**Scene 4:** (1:30 - 2:00)\\n\\n* Cut to a shot of a customer taking a bite of a Nepali dish, with a look of delight on their face.\\n* Voiceover: \"From our signature momos to our slow-cooked curries, every bite is a taste sensation that will leave you wanting more.\"\\n\\n**Scene 5:** (2:00 - 2:30)\\n\\n* Cut to a shot of the restaurant\\'s outdoor seating area, with customers enjoying their meals while taking in the stunning views of the lake.\\n* Voiceover: \"And when the weather permits, our outdoor seating area is the perfect spot to enjoy your meal while taking in the breathtaking views of the lake.\"\\n\\n**Scene 6:** (2:30 - 3:00)\\n\\n* Closing shot of the restaurant\\'s exterior at sunset, with the sound of the lake lapping in the background.\\n* Voiceover: \"So why wait? Come and experience the best of Nepali cuisine at [Your Restaurant Name]. Book your table now and taste the magic of Nepal in Lakeside!\"\\n\\nThis revised storyline incorporates the critic\\'s suggestions, including a more attention-grabbing opening, emotional connections with the target audience,'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 19
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "state['critic_response']\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 105
        },
        "id": "SSsXuklMTJlJ",
        "outputId": "5b21bb65-2ec6-4d97-ebde-9b58d0b550e0"
      },
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "\"Based on the generated storyline, I would suggest the following improvements:\\n\\n* The storyline is quite generic and doesn't specifically highlight the unique aspects of the restaurant or its offerings. Consider incorporating more specific details about the restaurant's menu, ambiance, or staff to make it more engaging.\\n* The storyline focuses more on the influencer's experience rather than the restaurant itself. Consider shifting the focus to the restaurant and its offerings to make it more relevant to the target audience.\\n* The storyline could benefit from a clearer call-to-action (CTA) to encourage viewers to take action, such as visiting the restaurant or trying out a specific dish.\\n\\nOverall, the storyline has potential but could be improved by incorporating more specific details about the restaurant and its offerings, and by shifting the focus to the restaurant itself rather than the influencer's experience.\""
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 13
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "state['ideator_response']\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 122
        },
        "id": "s9Q8O_pRTPvI",
        "outputId": "9863e2c7-9b84-4862-e62c-db1ab968d4b0"
      },
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "'Here is a detailed and creative storyline for a promotional video on your restaurant:\\n\\n**Title:** \"A Taste of Nepal: Discover the Flavors of Home\"\\n\\n**Scene 1:** (0:00 - 0:30)\\n\\n* Opening shot of a bustling street in Kathmandu, Nepal, with the sound of traditional Nepali music playing in the background.\\n* Cut to a shot of your restaurant\\'s exterior, with a sign that reads \"Nepali Food\" in bold letters.\\n* The camera pans inside the restaurant, showing the cozy and inviting atmosphere.\\n\\n**Scene 2:** (0:30 - 1:00)\\n\\n* Cut to a shot of a group of friends gathered around a table, enjoying a meal together.\\n* The camera zooms in on the dishes they\\'re eating, showcasing the variety of Nepali cuisine your restaurant offers.\\n* The friends are laughing and chatting, enjoying each other\\'s company.\\n\\n**Scene 3:** (1:00 - 1:30)\\n\\n* Cut to a shot of the chef, expertly preparing a traditional Nepali dish in the kitchen.\\n* The camera shows the sizzling sounds and aromas of the cooking process, making the viewer\\'s mouth water.\\n* The chef is smiling and chatting with the camera, giving a glimpse into the passion and dedication that goes into preparing each dish.\\n\\n**Scene 4:** (1:30 - 2:00)\\n\\n* Cut to a shot of a customer taking a bite of a dish, with a look of delight on their face.\\n* The camera cuts to a shot of the restaurant\\'s menu, highlighting the variety of options available.\\n* The narrator speaks, \"At [Your Restaurant Name], we\\'re passionate about sharing the flavors of Nepal with our customers. From spicy curries to tender momos, every dish is a taste of home.\"\\n\\n**Scene 5:** (2:00 - 2:30)\\n\\n* Cut to a shot of the restaurant\\'s exterior at night, with twinkling lights and a lively atmosphere.\\n* The camera pans inside, showing the restaurant filled with happy customers and the sound of laughter and chatter.\\n* The narrator speaks, \"So why not join us for a taste of Nepal? Book your table now and experience the warmth and hospitality of our restaurant.\"\\n\\n**Scene 6:** (2:30 - 3:00)\\n\\n* Closing shot of the restaurant\\'s logo and contact information on the screen.\\n* The narrator speaks, \"Nep'"
            ],
            "application/vnd.google.colaboratory.intrinsic+json": {
              "type": "string"
            }
          },
          "metadata": {},
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "ONa-okqQTbi6"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}