-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAskAI.json
More file actions
3339 lines (3339 loc) · 178 KB
/
AskAI.json
File metadata and controls
3339 lines (3339 loc) · 178 KB
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
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"id": "b9bab4d2-10a5-4157-8468-f8c075de353b",
"data": {
"nodes": [
{
"id": "TextInput-rZLTH",
"type": "genericNode",
"position": { "x": -290.64445157219734, "y": 355.8719201308067 },
"data": {
"type": "TextInput",
"node": {
"template": {
"_type": "Component",
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "from langflow.base.io.text import TextComponent\nfrom langflow.io import MultilineInput, Output\nfrom langflow.schema.message import Message\n\n\nclass TextInputComponent(TextComponent):\n display_name = \"Text Input\"\n description = \"Get text inputs from the Playground.\"\n icon = \"type\"\n name = \"TextInput\"\n\n inputs = [\n MultilineInput(\n name=\"input_value\",\n display_name=\"Text\",\n info=\"Text to be passed as input.\",\n ),\n ]\n outputs = [\n Output(display_name=\"Text\", name=\"text\", method=\"text_response\"),\n ]\n\n def text_response(self) -> Message:\n return Message(\n text=self.input_value,\n )\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"input_value": {
"trace_as_input": true,
"multiline": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "input_value",
"value": "whats 1 + 1\n",
"display_name": "Text",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "Text to be passed as input.",
"title_case": false,
"type": "str",
"_input_type": "MultilineInput"
}
},
"description": "Get text inputs from the Playground.",
"icon": "type",
"base_classes": ["Message"],
"display_name": "Question",
"documentation": "",
"custom_fields": {},
"output_types": [],
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": ["Message"],
"selected": "Message",
"name": "text",
"display_name": "Text",
"method": "text_response",
"value": "__UNDEFINED__",
"cache": true
}
],
"field_order": ["input_value"],
"beta": false,
"edited": false,
"metadata": {},
"lf_version": "1.0.19.post1"
},
"id": "TextInput-rZLTH",
"description": "Get text inputs from the Playground.",
"display_name": "Question"
},
"selected": false,
"width": 288,
"height": 216,
"positionAbsolute": {
"x": -290.64445157219734,
"y": 355.8719201308067
},
"dragging": false
},
{
"id": "Prompt-AVWGm",
"type": "genericNode",
"position": { "x": 79.65821150205147, "y": 39.77749269803954 },
"data": {
"type": "Prompt",
"node": {
"template": {
"_type": "Component",
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "from langflow.base.prompts.api_utils import process_prompt_template\nfrom langflow.custom import Component\nfrom langflow.inputs.inputs import DefaultPromptField\nfrom langflow.io import Output, PromptInput\nfrom langflow.schema.message import Message\nfrom langflow.template.utils import update_template_values\n\n\nclass PromptComponent(Component):\n display_name: str = \"Prompt\"\n description: str = \"Create a prompt template with dynamic variables.\"\n icon = \"prompts\"\n trace_type = \"prompt\"\n name = \"Prompt\"\n\n inputs = [\n PromptInput(name=\"template\", display_name=\"Template\"),\n ]\n\n outputs = [\n Output(display_name=\"Prompt Message\", name=\"prompt\", method=\"build_prompt\"),\n ]\n\n async def build_prompt(\n self,\n ) -> Message:\n prompt = await Message.from_template_and_variables(**self._attributes)\n self.status = prompt.text\n return prompt\n\n def _update_template(self, frontend_node: dict):\n prompt_template = frontend_node[\"template\"][\"template\"][\"value\"]\n custom_fields = frontend_node[\"custom_fields\"]\n frontend_node_template = frontend_node[\"template\"]\n _ = process_prompt_template(\n template=prompt_template,\n name=\"template\",\n custom_fields=custom_fields,\n frontend_node_template=frontend_node_template,\n )\n return frontend_node\n\n def post_code_processing(self, new_frontend_node: dict, current_frontend_node: dict):\n \"\"\"\n This function is called after the code validation is done.\n \"\"\"\n frontend_node = super().post_code_processing(new_frontend_node, current_frontend_node)\n template = frontend_node[\"template\"][\"template\"][\"value\"]\n # Kept it duplicated for backwards compatibility\n _ = process_prompt_template(\n template=template,\n name=\"template\",\n custom_fields=frontend_node[\"custom_fields\"],\n frontend_node_template=frontend_node[\"template\"],\n )\n # Now that template is updated, we need to grab any values that were set in the current_frontend_node\n # and update the frontend_node with those values\n update_template_values(new_template=frontend_node, previous_template=current_frontend_node[\"template\"])\n return frontend_node\n\n def _get_fallback_input(self, **kwargs):\n return DefaultPromptField(**kwargs)\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"template": {
"trace_as_input": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "template",
"value": "You are a decision-making assistant, and your task is to respond with either \"Yes\" or \"No\" only—nothing else.\n\nHere is the input: {question}\n\nIf the user is requesting anything that involves math, respond with \"Yes.\"\nIf the user is asking a general question or making a request that does not involve math, respond with \"No.\"\nYour responses should be limited to \"Yes\" or \"No\" without any additional details or explanations.",
"display_name": "Template",
"advanced": false,
"dynamic": false,
"info": "",
"title_case": false,
"type": "prompt",
"_input_type": "PromptInput"
},
"question": {
"field_type": "str",
"required": false,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "",
"fileTypes": [],
"file_path": "",
"name": "question",
"display_name": "question",
"advanced": false,
"input_types": ["Message", "Text"],
"dynamic": false,
"info": "",
"load_from_db": false,
"title_case": false,
"type": "str"
}
},
"description": "Create a prompt template with dynamic variables.",
"icon": "prompts",
"is_input": null,
"is_output": null,
"is_composition": null,
"base_classes": ["Message"],
"name": "",
"display_name": "Prompt",
"documentation": "",
"custom_fields": { "template": ["question"] },
"output_types": [],
"full_path": null,
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": ["Message"],
"selected": "Message",
"name": "prompt",
"hidden": null,
"display_name": "Prompt Message",
"method": "build_prompt",
"value": "__UNDEFINED__",
"cache": true
}
],
"field_order": ["template"],
"beta": false,
"error": null,
"edited": false,
"lf_version": "1.0.19.post1"
},
"id": "Prompt-AVWGm"
},
"selected": false,
"width": 288,
"height": 293,
"positionAbsolute": { "x": 79.65821150205147, "y": 39.77749269803954 },
"dragging": false
},
{
"id": "GoogleGenerativeAIModel-NLX3D",
"type": "genericNode",
"position": { "x": 635.5249149463622, "y": -2.190191221972583 },
"data": {
"type": "GoogleGenerativeAIModel",
"node": {
"template": {
"_type": "Component",
"output_parser": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "output_parser",
"value": "",
"display_name": "Output Parser",
"advanced": true,
"input_types": ["OutputParser"],
"dynamic": false,
"info": "The parser to use to parse the output of the model",
"title_case": false,
"type": "other",
"_input_type": "HandleInput"
},
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "from pydantic.v1 import SecretStr\n\nfrom langflow.base.models.model import LCModelComponent\nfrom langflow.field_typing import LanguageModel\nfrom langflow.inputs import DropdownInput, FloatInput, IntInput, SecretStrInput\nfrom langflow.inputs.inputs import HandleInput\n\n\nclass GoogleGenerativeAIComponent(LCModelComponent):\n display_name = \"Google Generative AI\"\n description = \"Generate text using Google Generative AI.\"\n icon = \"GoogleGenerativeAI\"\n name = \"GoogleGenerativeAIModel\"\n\n inputs = [\n *LCModelComponent._base_inputs,\n IntInput(\n name=\"max_output_tokens\", display_name=\"Max Output Tokens\", info=\"The maximum number of tokens to generate.\"\n ),\n DropdownInput(\n name=\"model\",\n display_name=\"Model\",\n info=\"The name of the model to use.\",\n options=[\"gemini-1.5-pro\", \"gemini-1.5-flash\", \"gemini-1.0-pro\", \"gemini-1.0-pro-vision\"],\n value=\"gemini-1.5-pro\",\n ),\n SecretStrInput(\n name=\"google_api_key\",\n display_name=\"Google API Key\",\n info=\"The Google API Key to use for the Google Generative AI.\",\n ),\n FloatInput(\n name=\"top_p\",\n display_name=\"Top P\",\n info=\"The maximum cumulative probability of tokens to consider when sampling.\",\n advanced=True,\n ),\n FloatInput(name=\"temperature\", display_name=\"Temperature\", value=0.1),\n IntInput(\n name=\"n\",\n display_name=\"N\",\n info=\"Number of chat completions to generate for each prompt. \"\n \"Note that the API may not return the full n completions if duplicates are generated.\",\n advanced=True,\n ),\n IntInput(\n name=\"top_k\",\n display_name=\"Top K\",\n info=\"Decode using top-k sampling: consider the set of top_k most probable tokens. Must be positive.\",\n advanced=True,\n ),\n HandleInput(\n name=\"output_parser\",\n display_name=\"Output Parser\",\n info=\"The parser to use to parse the output of the model\",\n advanced=True,\n input_types=[\"OutputParser\"],\n ),\n ]\n\n def build_model(self) -> LanguageModel: # type: ignore[type-var]\n try:\n from langchain_google_genai import ChatGoogleGenerativeAI\n except ImportError as e:\n msg = \"The 'langchain_google_genai' package is required to use the Google Generative AI model.\"\n raise ImportError(msg) from e\n\n google_api_key = self.google_api_key\n model = self.model\n max_output_tokens = self.max_output_tokens\n temperature = self.temperature\n top_k = self.top_k\n top_p = self.top_p\n n = self.n\n\n return ChatGoogleGenerativeAI(\n model=model,\n max_output_tokens=max_output_tokens or None,\n temperature=temperature,\n top_k=top_k or None,\n top_p=top_p or None,\n n=n or 1,\n google_api_key=SecretStr(google_api_key),\n )\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"google_api_key": {
"load_from_db": true,
"required": false,
"placeholder": "",
"show": true,
"name": "google_api_key",
"value": "google_api_key",
"display_name": "Google API Key",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "The Google API Key to use for the Google Generative AI.",
"title_case": false,
"password": true,
"type": "str",
"_input_type": "SecretStrInput"
},
"input_value": {
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "input_value",
"value": "",
"display_name": "Input",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "",
"title_case": false,
"type": "str",
"_input_type": "MessageInput"
},
"max_output_tokens": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "max_output_tokens",
"value": "",
"display_name": "Max Output Tokens",
"advanced": false,
"dynamic": false,
"info": "The maximum number of tokens to generate.",
"title_case": false,
"type": "int",
"_input_type": "IntInput"
},
"model": {
"trace_as_metadata": true,
"options": [
"gemini-1.5-pro",
"gemini-1.5-flash",
"gemini-1.0-pro",
"gemini-1.0-pro-vision"
],
"combobox": false,
"required": false,
"placeholder": "",
"show": true,
"name": "model",
"value": "gemini-1.5-pro",
"display_name": "Model",
"advanced": false,
"dynamic": false,
"info": "The name of the model to use.",
"title_case": false,
"type": "str",
"_input_type": "DropdownInput"
},
"n": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "n",
"value": "",
"display_name": "N",
"advanced": true,
"dynamic": false,
"info": "Number of chat completions to generate for each prompt. Note that the API may not return the full n completions if duplicates are generated.",
"title_case": false,
"type": "int",
"_input_type": "IntInput"
},
"stream": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "stream",
"value": false,
"display_name": "Stream",
"advanced": true,
"dynamic": false,
"info": "Stream the response from the model. Streaming works only in Chat.",
"title_case": false,
"type": "bool",
"_input_type": "BoolInput"
},
"system_message": {
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "system_message",
"value": "",
"display_name": "System Message",
"advanced": true,
"input_types": ["Message"],
"dynamic": false,
"info": "System message to pass to the model.",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
},
"temperature": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "temperature",
"value": 0.1,
"display_name": "Temperature",
"advanced": false,
"dynamic": false,
"info": "",
"title_case": false,
"type": "float",
"_input_type": "FloatInput"
},
"top_k": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "top_k",
"value": "",
"display_name": "Top K",
"advanced": true,
"dynamic": false,
"info": "Decode using top-k sampling: consider the set of top_k most probable tokens. Must be positive.",
"title_case": false,
"type": "int",
"_input_type": "IntInput"
},
"top_p": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "top_p",
"value": "",
"display_name": "Top P",
"advanced": true,
"dynamic": false,
"info": "The maximum cumulative probability of tokens to consider when sampling.",
"title_case": false,
"type": "float",
"_input_type": "FloatInput"
}
},
"description": "Generate text using Google Generative AI.",
"icon": "GoogleGenerativeAI",
"base_classes": ["LanguageModel", "Message"],
"display_name": "Google Generative AI",
"documentation": "",
"custom_fields": {},
"output_types": [],
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": ["Message"],
"selected": "Message",
"name": "text_output",
"display_name": "Text",
"method": "text_response",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": ["input_value", "stream", "system_message"]
},
{
"types": ["LanguageModel"],
"selected": "LanguageModel",
"name": "model_output",
"display_name": "Language Model",
"method": "build_model",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": [
"google_api_key",
"max_output_tokens",
"model",
"n",
"temperature",
"top_k",
"top_p"
]
}
],
"field_order": [
"input_value",
"system_message",
"stream",
"max_output_tokens",
"model",
"google_api_key",
"top_p",
"temperature",
"n",
"top_k",
"output_parser"
],
"beta": false,
"edited": false,
"metadata": {},
"lf_version": "1.0.19.post1"
},
"id": "GoogleGenerativeAIModel-NLX3D",
"description": "Generate text using Google Generative AI.",
"display_name": "Google Generative AI"
},
"selected": false,
"width": 288,
"height": 506,
"positionAbsolute": { "x": 635.5249149463622, "y": -2.190191221972583 },
"dragging": false
},
{
"id": "ConditionalRouter-152ym",
"type": "genericNode",
"position": { "x": 260.22086238886664, "y": 376.68782992533835 },
"data": {
"type": "ConditionalRouter",
"node": {
"template": {
"_type": "Component",
"case_sensitive": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "case_sensitive",
"value": false,
"display_name": "Case Sensitive",
"advanced": true,
"dynamic": false,
"info": "If true, the comparison will be case sensitive.",
"title_case": false,
"type": "bool",
"_input_type": "BoolInput"
},
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "from langflow.custom import Component\nfrom langflow.io import BoolInput, DropdownInput, MessageInput, MessageTextInput, Output\nfrom langflow.schema.message import Message\n\n\nclass ConditionalRouterComponent(Component):\n display_name = \"Conditional Router\"\n description = \"Routes an input message to a corresponding output based on text comparison.\"\n icon = \"equal\"\n name = \"ConditionalRouter\"\n\n inputs = [\n MessageTextInput(\n name=\"input_text\",\n display_name=\"Input Text\",\n info=\"The primary text input for the operation.\",\n ),\n MessageTextInput(\n name=\"match_text\",\n display_name=\"Match Text\",\n info=\"The text input to compare against.\",\n ),\n DropdownInput(\n name=\"operator\",\n display_name=\"Operator\",\n options=[\"equals\", \"not equals\", \"contains\", \"starts with\", \"ends with\"],\n info=\"The operator to apply for comparing the texts.\",\n value=\"equals\",\n advanced=True,\n ),\n BoolInput(\n name=\"case_sensitive\",\n display_name=\"Case Sensitive\",\n info=\"If true, the comparison will be case sensitive.\",\n value=False,\n advanced=True,\n ),\n MessageInput(\n name=\"message\",\n display_name=\"Message\",\n info=\"The message to pass through either route.\",\n ),\n ]\n\n outputs = [\n Output(display_name=\"True Route\", name=\"true_result\", method=\"true_response\"),\n Output(display_name=\"False Route\", name=\"false_result\", method=\"false_response\"),\n ]\n\n def evaluate_condition(self, input_text: str, match_text: str, operator: str, case_sensitive: bool) -> bool:\n if not case_sensitive:\n input_text = input_text.lower()\n match_text = match_text.lower()\n\n if operator == \"equals\":\n return input_text == match_text\n if operator == \"not equals\":\n return input_text != match_text\n if operator == \"contains\":\n return match_text in input_text\n if operator == \"starts with\":\n return input_text.startswith(match_text)\n if operator == \"ends with\":\n return input_text.endswith(match_text)\n return False\n\n def true_response(self) -> Message:\n result = self.evaluate_condition(self.input_text, self.match_text, self.operator, self.case_sensitive)\n if result:\n self.status = self.message\n return self.message\n self.stop(\"true_result\")\n return None # type: ignore[return-value]\n\n def false_response(self) -> Message:\n result = self.evaluate_condition(self.input_text, self.match_text, self.operator, self.case_sensitive)\n if not result:\n self.status = self.message\n return self.message\n self.stop(\"false_result\")\n return None # type: ignore[return-value]\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"input_text": {
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "input_text",
"value": "",
"display_name": "Input Text",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "The primary text input for the operation.",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
},
"match_text": {
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "match_text",
"value": "Yes",
"display_name": "Match Text",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "The text input to compare against.",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
},
"message": {
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "message",
"value": "",
"display_name": "Message",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "The message to pass through either route.",
"title_case": false,
"type": "str",
"_input_type": "MessageInput"
},
"operator": {
"trace_as_metadata": true,
"options": [
"equals",
"not equals",
"contains",
"starts with",
"ends with"
],
"combobox": false,
"required": false,
"placeholder": "",
"show": true,
"name": "operator",
"value": "equals",
"display_name": "Operator",
"advanced": true,
"dynamic": false,
"info": "The operator to apply for comparing the texts.",
"title_case": false,
"type": "str",
"_input_type": "DropdownInput"
}
},
"description": "Routes an input message to a corresponding output based on text comparison.",
"icon": "equal",
"base_classes": ["Message"],
"display_name": "Conditional Router",
"documentation": "",
"custom_fields": {},
"output_types": [],
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": ["Message"],
"selected": "Message",
"name": "true_result",
"display_name": "True Route",
"method": "true_response",
"value": "__UNDEFINED__",
"cache": true
},
{
"types": ["Message"],
"selected": "Message",
"name": "false_result",
"display_name": "False Route",
"method": "false_response",
"value": "__UNDEFINED__",
"cache": true
}
],
"field_order": [
"input_text",
"match_text",
"operator",
"case_sensitive",
"message"
],
"beta": false,
"edited": false,
"metadata": {},
"lf_version": "1.0.19.post1"
},
"id": "ConditionalRouter-152ym",
"description": "Routes an input message to a corresponding output based on text comparison.",
"display_name": "Conditional Router"
},
"selected": false,
"width": 288,
"height": 388,
"positionAbsolute": {
"x": 260.22086238886664,
"y": 376.68782992533835
},
"dragging": false
},
{
"id": "ToolCallingAgent-6Xgt3",
"type": "genericNode",
"position": { "x": 1540.8382387079844, "y": 291.8574501608608 },
"data": {
"type": "ToolCallingAgent",
"node": {
"template": {
"_type": "Component",
"chat_history": {
"trace_as_metadata": true,
"list": true,
"trace_as_input": true,
"required": false,
"placeholder": "",
"show": true,
"name": "chat_history",
"value": "",
"display_name": "Chat History",
"advanced": true,
"input_types": ["Data"],
"dynamic": false,
"info": "",
"title_case": false,
"type": "other",
"_input_type": "DataInput"
},
"llm": {
"trace_as_metadata": true,
"list": false,
"required": true,
"placeholder": "",
"show": true,
"name": "llm",
"value": "",
"display_name": "Language Model",
"advanced": false,
"input_types": ["LanguageModel"],
"dynamic": false,
"info": "",
"title_case": false,
"type": "other",
"_input_type": "HandleInput"
},
"tools": {
"trace_as_metadata": true,
"list": true,
"required": false,
"placeholder": "",
"show": true,
"name": "tools",
"value": "",
"display_name": "Tools",
"advanced": false,
"input_types": ["Tool", "BaseTool"],
"dynamic": false,
"info": "",
"title_case": false,
"type": "other",
"_input_type": "HandleInput"
},
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "from langchain.agents import create_tool_calling_agent\nfrom langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, PromptTemplate\n\nfrom langflow.base.agents.agent import LCToolsAgentComponent\nfrom langflow.inputs import MultilineInput\nfrom langflow.inputs.inputs import DataInput, HandleInput\nfrom langflow.schema import Data\n\n\nclass ToolCallingAgentComponent(LCToolsAgentComponent):\n display_name: str = \"Tool Calling Agent\"\n description: str = \"Agent that uses tools\"\n icon = \"LangChain\"\n beta = True\n name = \"ToolCallingAgent\"\n\n inputs = [\n *LCToolsAgentComponent._base_inputs,\n HandleInput(name=\"llm\", display_name=\"Language Model\", input_types=[\"LanguageModel\"], required=True),\n MultilineInput(\n name=\"system_prompt\",\n display_name=\"System Prompt\",\n info=\"System prompt for the agent.\",\n value=\"You are a helpful assistant\",\n ),\n MultilineInput(\n name=\"user_prompt\", display_name=\"Prompt\", info=\"This prompt must contain 'input' key.\", value=\"{input}\"\n ),\n DataInput(name=\"chat_history\", display_name=\"Chat History\", is_list=True, advanced=True),\n ]\n\n def get_chat_history_data(self) -> list[Data] | None:\n return self.chat_history\n\n def create_agent_runnable(self):\n if \"input\" not in self.user_prompt:\n msg = \"Prompt must contain 'input' key.\"\n raise ValueError(msg)\n messages = [\n (\"system\", self.system_prompt),\n (\"placeholder\", \"{chat_history}\"),\n HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=[\"input\"], template=self.user_prompt)),\n (\"placeholder\", \"{agent_scratchpad}\"),\n ]\n prompt = ChatPromptTemplate.from_messages(messages)\n return create_tool_calling_agent(self.llm, self.tools, prompt)\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"handle_parsing_errors": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "handle_parsing_errors",
"value": true,
"display_name": "Handle Parse Errors",
"advanced": true,
"dynamic": false,
"info": "",
"title_case": false,
"type": "bool",
"_input_type": "BoolInput"
},
"input_value": {
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "input_value",
"value": "",
"display_name": "Input",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
},
"max_iterations": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "max_iterations",
"value": 15,
"display_name": "Max Iterations",
"advanced": true,
"dynamic": false,
"info": "",
"title_case": false,
"type": "int",
"_input_type": "IntInput"
},
"system_prompt": {
"trace_as_input": true,
"multiline": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "system_prompt",
"value": "",
"display_name": "System Prompt",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "System prompt for the agent.",
"title_case": false,
"type": "str",
"_input_type": "MultilineInput"
},
"user_prompt": {
"trace_as_input": true,
"multiline": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "user_prompt",
"value": "{input}",
"display_name": "Prompt",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "This prompt must contain 'input' key.",
"title_case": false,
"type": "str",
"_input_type": "MultilineInput"
},
"verbose": {
"trace_as_metadata": true,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "verbose",
"value": true,
"display_name": "Verbose",
"advanced": true,
"dynamic": false,
"info": "",
"title_case": false,
"type": "bool",
"_input_type": "BoolInput"
}
},
"description": "Agent that uses tools",
"icon": "LangChain",
"base_classes": ["AgentExecutor", "Message"],
"display_name": "Tool Calling Agent",
"documentation": "",
"custom_fields": {},
"output_types": [],
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": ["AgentExecutor"],
"selected": "AgentExecutor",
"name": "agent",
"display_name": "Agent",
"method": "build_agent",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": ["tools"]
},
{
"types": ["Message"],
"selected": "Message",
"name": "response",
"display_name": "Response",
"method": "message_response",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": []
}
],
"field_order": [
"input_value",
"handle_parsing_errors",
"verbose",
"max_iterations",
"tools",
"llm",
"system_prompt",
"user_prompt",
"chat_history"
],
"beta": true,
"edited": false,
"metadata": {}
},
"id": "ToolCallingAgent-6Xgt3",
"description": "Agent that uses tools",
"display_name": "Tool Calling Agent"
},
"selected": false,
"width": 288,
"height": 448,
"positionAbsolute": { "x": 1540.8382387079844, "y": 291.8574501608608 },
"dragging": false
},
{
"id": "CalculatorTool-3NO3G",
"type": "genericNode",
"position": { "x": 1697.000967030725, "y": -6.039606400460855 },
"data": {
"type": "CalculatorTool",
"node": {
"template": {
"_type": "Component",
"code": {
"type": "code",
"required": true,
"placeholder": "",
"list": false,
"show": true,
"multiline": true,
"value": "import ast\nimport operator\n\nfrom langchain.tools import StructuredTool\nfrom loguru import logger\nfrom pydantic import BaseModel, Field\n\nfrom langflow.base.langchain_utilities.model import LCToolComponent\nfrom langflow.field_typing import Tool\nfrom langflow.inputs import MessageTextInput\nfrom langflow.schema import Data\n\n\nclass CalculatorToolComponent(LCToolComponent):\n display_name = \"Calculator\"\n description = \"Perform basic arithmetic operations on a given expression.\"\n icon = \"calculator\"\n name = \"CalculatorTool\"\n\n inputs = [\n MessageTextInput(\n name=\"expression\",\n display_name=\"Expression\",\n info=\"The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').\",\n ),\n ]\n\n class CalculatorToolSchema(BaseModel):\n expression: str = Field(..., description=\"The arithmetic expression to evaluate.\")\n\n def run_model(self) -> list[Data]:\n return self._evaluate_expression(self.expression)\n\n def build_tool(self) -> Tool:\n return StructuredTool.from_function(\n name=\"calculator\",\n description=\"Evaluate basic arithmetic expressions. Input should be a string containing the expression.\",\n func=self._evaluate_expression,\n args_schema=self.CalculatorToolSchema,\n )\n\n def _evaluate_expression(self, expression: str) -> list[Data]:\n try:\n # Define the allowed operators\n operators = {\n ast.Add: operator.add,\n ast.Sub: operator.sub,\n ast.Mult: operator.mul,\n ast.Div: operator.truediv,\n ast.Pow: operator.pow,\n }\n\n def eval_expr(node):\n if isinstance(node, ast.Num):\n return node.n\n if isinstance(node, ast.BinOp):\n return operators[type(node.op)](eval_expr(node.left), eval_expr(node.right))\n if isinstance(node, ast.UnaryOp):\n return operators[type(node.op)](eval_expr(node.operand))\n raise TypeError(node)\n\n # Parse the expression and evaluate it\n tree = ast.parse(expression, mode=\"eval\")\n result = eval_expr(tree.body)\n\n # Format the result to a reasonable number of decimal places\n formatted_result = f\"{result:.6f}\".rstrip(\"0\").rstrip(\".\")\n\n self.status = formatted_result\n return [Data(data={\"result\": formatted_result})]\n\n except (SyntaxError, TypeError, KeyError) as e:\n error_message = f\"Invalid expression: {e}\"\n self.status = error_message\n return [Data(data={\"error\": error_message})]\n except ZeroDivisionError:\n error_message = \"Error: Division by zero\"\n self.status = error_message\n return [Data(data={\"error\": error_message})]\n except Exception as e: # noqa: BLE001\n logger.opt(exception=True).debug(\"Error evaluating expression\")\n error_message = f\"Error: {e}\"\n self.status = error_message\n return [Data(data={\"error\": error_message})]\n",
"fileTypes": [],
"file_path": "",
"password": false,
"name": "code",
"advanced": true,
"dynamic": true,
"info": "",
"load_from_db": false,
"title_case": false
},
"expression": {
"trace_as_input": true,
"trace_as_metadata": true,
"load_from_db": false,
"list": false,
"required": false,
"placeholder": "",
"show": true,
"name": "expression",
"value": "",
"display_name": "Expression",
"advanced": false,
"input_types": ["Message"],
"dynamic": false,
"info": "The arithmetic expression to evaluate (e.g., '4*4*(33/22)+12-20').",
"title_case": false,
"type": "str",
"_input_type": "MessageTextInput"
}
},
"description": "Perform basic arithmetic operations on a given expression.",
"icon": "calculator",
"base_classes": ["Data", "Tool"],
"display_name": "Calculator",
"documentation": "",
"custom_fields": {},
"output_types": [],
"pinned": false,
"conditional_paths": [],
"frozen": false,
"outputs": [
{
"types": ["Data"],
"selected": "Data",
"name": "api_run_model",
"display_name": "Data",
"method": "run_model",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": ["expression"]
},
{
"types": ["Tool"],
"selected": "Tool",
"name": "api_build_tool",
"display_name": "Tool",
"method": "build_tool",
"value": "__UNDEFINED__",
"cache": true,
"required_inputs": ["expression"]
}
],
"field_order": ["expression"],
"beta": false,
"edited": false,
"metadata": {},
"lf_version": "1.0.19.post1"
},
"id": "CalculatorTool-3NO3G",
"description": "Perform basic arithmetic operations on a given expression.",
"display_name": "Calculator"
},
"selected": false,
"width": 288,
"height": 258,
"positionAbsolute": { "x": 1697.000967030725, "y": -6.039606400460855 },
"dragging": false