6
6
7
7
class Select (GenStep ):
8
8
9
- def __init__ (self , llm_input :str , options , to :str , action = None ):
10
- super ().__init__ (llm_input , to , output_type = "Single Word" ,action = action )
11
- if isinstance (options , str ):
12
- if not re .match (r'\{(\w+)\}' , options ):
13
- raise ValueError (f"La source de donnée { options } doit être une variable entre accolades." )
14
- self .options = re .findall (r'\{(\w+)\}' , options )[0 ]
9
+ def __init__ (self , ** kwargs ):
10
+ if len (kwargs ) != 2 :
11
+ raise ValueError ("Var must have 2 arguments, datasource and options." )
12
+ dest = list (kwargs .keys ())[0 ]
13
+ value = list (kwargs .values ())[0 ]
14
+ options = list (kwargs .values ())[1 ]
15
+ super ().__init__ (value , dest , output_type = "Single Word" )
16
+
17
+ if callable (options ):
18
+ self .options = options
15
19
elif isinstance (options , list ):
16
20
self .options = options
17
21
elif isinstance (options , Step ):
18
22
self .options = options
19
23
else :
20
- raise ValueError ("The parameter must be a string (state key) , a list or a Step." )
24
+ raise ValueError ("The parameter must be a lambda function , a list or a Step." )
21
25
self .display_type = "You respond by selecting the correct option."
22
26
23
27
def execute (self , state ):
@@ -27,12 +31,11 @@ def execute(self, state):
27
31
llm += self .display_step_name + self .current_llm_input + " " + select (current_options , name = "response" )
28
32
res = llm ["response" ]
29
33
state .llm += self .display_step_name + res + "\n "
30
- state .set (self .name , res )
31
34
return res
32
35
33
36
def resolve_param (self , param , state ):
34
- if isinstance (param , str ):
35
- return state . get ( param )
37
+ if callable (param ):
38
+ return param ( )
36
39
elif isinstance (param , Step ):
37
40
return param .execute (state )
38
41
elif isinstance (param , list ):
0 commit comments