File tree Expand file tree Collapse file tree 2 files changed +27
-26
lines changed Expand file tree Collapse file tree 2 files changed +27
-26
lines changed Original file line number Diff line number Diff line change 21
21
run_sitemap_spider_in_process ,
22
22
run_url_spider_in_process ,
23
23
)
24
+ from llmstack .common .utils .liquid import render_template
24
25
25
26
logger = logging .getLogger (__name__ )
26
27
@@ -515,3 +516,28 @@ def vectorize_text(text):
515
516
516
517
vectors = embedding_functions .DefaultEmbeddingFunction ()([text ])
517
518
return vectors [0 ]
519
+
520
+
521
+ def hydrate_input (input , values ):
522
+ def render (value ):
523
+ if isinstance (value , str ):
524
+ try :
525
+ return render_template (value , values )
526
+ except Exception :
527
+ logger .exception ("Error rendering template when hydrating input" )
528
+
529
+ return value
530
+
531
+ def traverse (obj ):
532
+ if isinstance (obj , dict ):
533
+ return {key : traverse (render (value )) for key , value in obj .items ()}
534
+ elif isinstance (obj , list ):
535
+ return [traverse (render (item )) for item in obj ]
536
+ elif isinstance (obj , BaseModel ):
537
+ cls = obj .__class__
538
+ return cls .model_validate (traverse (obj .model_dump ()))
539
+ elif isinstance (obj , str ):
540
+ return render (obj )
541
+ return obj
542
+
543
+ return traverse (input )
Original file line number Diff line number Diff line change 16
16
ProcessorInterface ,
17
17
)
18
18
from llmstack .common .blocks .base .schema import BaseSchema as _Schema
19
- from llmstack .common .utils .liquid import render_template
20
19
from llmstack .common .utils .provider_config import get_matched_provider_config
20
+ from llmstack .common .utils .utils import hydrate_input
21
21
from llmstack .play .actor import Actor , BookKeepingData
22
22
from llmstack .play .actors .agent import ToolInvokeInput
23
23
from llmstack .play .utils import extract_jinja2_variables
36
36
FILE_WIDGET_NAME = "file"
37
37
38
38
39
- def hydrate_input (input , values ):
40
- def render (value ):
41
- if isinstance (value , str ):
42
- try :
43
- return render_template (value , values )
44
- except Exception :
45
- logger .exception ("Error rendering template when hydrating input" )
46
-
47
- return value
48
-
49
- def traverse (obj ):
50
- if isinstance (obj , dict ):
51
- return {key : traverse (render (value )) for key , value in obj .items ()}
52
- elif isinstance (obj , list ):
53
- return [traverse (render (item )) for item in obj ]
54
- elif isinstance (obj , BaseModel ):
55
- cls = obj .__class__
56
- return cls .model_validate (traverse (obj .model_dump ()))
57
- elif isinstance (obj , str ):
58
- return render (obj )
59
- return obj
60
-
61
- return traverse (input )
62
-
63
-
64
39
class ApiProcessorSchema (_Schema ):
65
40
pass
66
41
You can’t perform that action at this time.
0 commit comments