Skip to content

Commit 3e81339

Browse files
author
AlbanP
committed
ReadMe for New interface
1 parent b3850ef commit 3e81339

13 files changed

+140
-166
lines changed

Noema/conditionnal.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def execute(self, state):
7474
outputs.append(step.execute(state))
7575
state.set_prop(step.name,outputs[-1])
7676
prop_to_remove.append(step.name)
77-
78-
for prop in prop_to_remove:
79-
state.set_prop(prop,None)
77+
78+
# TODO: think about the variable scope. Should we remove the variables created in the IF block?
79+
# for prop in prop_to_remove:
80+
# state.set_prop(prop,None)

Noema/debug.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ def __init__(self, value):
1010
def execute(self, state):
1111
if isinstance(self.value, str):
1212
extracted = self.extract_variables_from_string(self.value, state)
13-
print("DEBUG:",extracted)
13+
print(extracted)
1414
elif isinstance(self.value, Step):
1515
extracted = self.value.execute(state)
16-
print("DEBUG:",extracted)
16+
print(extracted)
1717
else:
1818
raise ValueError("The parameter must be a string (state key) or a Step.")
1919

Noema/generators.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66

77
class Select(GenStep):
88

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
1519
elif isinstance(options, list):
1620
self.options = options
1721
elif isinstance(options, Step):
1822
self.options = options
1923
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.")
2125
self.display_type = "You respond by selecting the correct option."
2226

2327
def execute(self, state):
@@ -27,12 +31,11 @@ def execute(self, state):
2731
llm += self.display_step_name + self.current_llm_input+ " " + select(current_options, name="response")
2832
res = llm["response"]
2933
state.llm += self.display_step_name + res + "\n"
30-
state.set(self.name, res)
3134
return res
3235

3336
def resolve_param(self, param, state):
34-
if isinstance(param, str):
35-
return state.get(param)
37+
if callable(param):
38+
return param()
3639
elif isinstance(param, Step):
3740
return param.execute(state)
3841
elif isinstance(param, list):

Noema/horizon.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .step import DebugStep, FlowStep, GenStep
2+
from .subject import Subject
23
from .var import Var
34

45

Noema/information.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
class Information(Step):
44

5-
def __init__(self, value:str, action=None):
6-
super().__init__(name="Information: ", action=action)
5+
def __init__(self, value:str):
6+
super().__init__(name="Information: ")
77
self.value = value
88

99
def execute(self, state):
1010

1111
if isinstance(self.value, str):
1212
current_value = self.extract_variables_from_string(self.value, state)
13-
state.llm += current_value + "\n"
1413
elif isinstance(self.value, Step):
1514
current_value = self.value.execute(state)
16-
state.llm += current_value + "\n"
1715
else:
1816
raise ValueError("The parameter must be a string (state key) or a Step.")
19-
17+
state.llm += "#"+self.name.upper()+":"+ current_value + "\n"
2018
return current_value
2119

2220
def list_steps(self,state):
23-
return [self.name+" "+self.value] if self.should_include_in_list() else []
21+
return ["#"+self.name.upper()+": "+self.value] if self.should_include_in_list() else []

Noema/loops.py

-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ def evaluate_condition(self, state):
149149
return False
150150
elif isinstance(self.condition, Step):
151151
res = self.condition.execute(state)
152-
print(f"Condition result: {res}")
153152
return bool(res)
154153
else:
155154
raise ValueError("Condition must be either a lambda function or a Step.")

Noema/noesis.py

-5
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def execute_with_params(self, state, param_values):
4949
start_time = time.time()
5050
for i, param_name in enumerate(self.param_names):
5151
param_value = param_values[i]
52-
print(f"Setting {param_name} to {param_value}")
5352
state.set_prop(param_name, param_value)
5453

5554
current_noesis = self.buildNoesis(self.param_names, param_values, state)
@@ -61,7 +60,6 @@ def execute_with_params(self, state, param_values):
6160
for step in self.steps:
6261
if isinstance(step, Return):
6362
output = step.execute(state)
64-
print("IN RETURN")
6563
state.set_prop(self.name, output)
6664
break
6765
elif isinstance(step, FlowStep):
@@ -122,9 +120,7 @@ def __call__(self,*args, **kwargs):
122120
for key, value in kwargs.items():
123121
if key not in self.param_names:
124122
raise ValueError(f"Invalid parameter name: {key}")
125-
print(f"IN CALL: param {key} with {value}")
126123
param_values.append(value)
127-
print(f"Param values: {param_values}")
128124
return self.execute_with_params(state, param_values)
129125

130126

@@ -161,7 +157,6 @@ def resolve_param(self, param, state):
161157

162158
def execute(self, state, run_step = True):
163159
output = self.value()
164-
print(f"Result of '{self.name}' is: {output}")
165160
state.llm += f"#{self.name.upper()}: {output}"+ "\n"
166161
state.set_prop(self.name, output)
167162
return output

Noema/step.py

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def lookup_reference(match):
2121
def lookup_variable(match):
2222
var_name = match.group(1)
2323
value = state.get_prop(var_name)
24-
print("Value: ", value)
2524
if value is not None:
2625
return str(value)
2726
else:
@@ -35,7 +34,6 @@ def lookup_variable(match):
3534
if re.search(r'\{(\w+)\}', string):
3635
string = re.sub(r'(.*)\{(\w+)\}(.*)', r'\1\2\3', string)
3736

38-
print("String: ", string)
3937
return string
4038

4139
def extract_variables_from_string(self, string, state, can_be_None = False):

Noema/subject.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@ def __init__(self, llm_path):
1111
)
1212
self.noema = ""
1313

14-
def add(self, var):
15-
var.execute(self)
14+
def add(self,**kwargs):
15+
for key, value in kwargs.items():
16+
setattr(self, key, value)
1617

1718
def set_prop(self, name, value):
18-
print(f"Setting prop: {name} to {value}")
1919
setattr(self, name, value)
2020

2121
def get_prop(self, name):
2222
value = getattr(self, name, None)
23-
print(f"Getting prop: {name} with value {value}")
2423
return value
2524

2625
def set(self, key, value, extend = False):
@@ -57,7 +56,6 @@ def set(self, key, value, extend = False):
5756
else:
5857
if key not in self.data.keys():
5958
self.data[key] = value
60-
print("New array added")
6159
return
6260
if extend:
6361
if isinstance(self.data[key], list):

Noema/var.py

-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def execute(self, state, run_step = True):
2424
value = self.value.execute(state)
2525
elif callable(self.value):
2626
if run_step:
27-
print(f"RUNNING FUNCTION {self.value.__name__}")
2827
value = self.value()
29-
print(f"RUNNING FUNCTION {self.value.__name__} WITH VALUE {value}")
3028
else:
3129
value = self.value
3230

Noema/write.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def __init__(self, value:str, var_name:str, extend:bool = False, action=None):
1313

1414
def execute(self, state):
1515
current_value = self.extract_variables_from_string(self.value, state)
16-
print(f"Writing {current_value} to {self.name}")
1716
state.set(self.name, current_value, self.extend)
1817
return current_value
1918

0 commit comments

Comments
 (0)