Skip to content

Commit 28355fa

Browse files
committed
always push iteration to stack first
1 parent 79bbbd4 commit 28355fa

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

guardrails/run.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def step(
222222
outputs = Outputs()
223223
iteration = Iteration(inputs=inputs, outputs=outputs)
224224
set_scope(str(id(iteration)))
225+
call_log.iterations.push(iteration)
225226

226227
try:
227228
with start_action(
@@ -259,8 +260,6 @@ def step(
259260
iteration.inputs.prompt = prompt
260261
iteration.inputs.msg_history = msg_history
261262

262-
call_log.iterations.push(iteration)
263-
264263
# Call: run the API.
265264
llm_response = self.call(
266265
index, instructions, prompt, msg_history, api, output
@@ -348,7 +347,7 @@ def prepare(
348347
llm_output=msg_str,
349348
)
350349
iteration = Iteration(inputs=inputs)
351-
call_log.iterations.push(iteration)
350+
call_log.iterations.insert(0, iteration)
352351
validated_msg_history = msg_history_schema.validate(
353352
iteration, msg_str, self.metadata
354353
)
@@ -386,7 +385,7 @@ def prepare(
386385
llm_output=prompt.source,
387386
)
388387
iteration = Iteration(inputs=inputs)
389-
call_log.iterations.push(iteration)
388+
call_log.iterations.insert(0, iteration)
390389
validated_prompt = prompt_schema.validate(
391390
iteration, prompt.source, self.metadata
392391
)
@@ -405,7 +404,7 @@ def prepare(
405404
llm_output=instructions.source,
406405
)
407406
iteration = Iteration(inputs=inputs)
408-
call_log.iterations.push(iteration)
407+
call_log.iterations.insert(0, iteration)
409408
validated_instructions = instructions_schema.validate(
410409
iteration, instructions.source, self.metadata
411410
)
@@ -729,6 +728,8 @@ async def async_step(
729728
)
730729
outputs = Outputs()
731730
iteration = Iteration(inputs=inputs, outputs=outputs)
731+
call_log.iterations.push(iteration)
732+
732733
try:
733734
with start_action(
734735
action_type="step",
@@ -765,8 +766,6 @@ async def async_step(
765766
iteration.inputs.prompt = prompt
766767
iteration.inputs.msg_history = msg_history
767768

768-
call_log.iterations.push(iteration)
769-
770769
# Call: run the API.
771770
llm_response = await self.async_call(
772771
index, instructions, prompt, msg_history, api, output
@@ -925,7 +924,7 @@ async def async_prepare(
925924
llm_output=msg_str,
926925
)
927926
iteration = Iteration(inputs=inputs)
928-
call_log.iterations.push(iteration)
927+
call_log.iterations.insert(0, iteration)
929928
validated_msg_history = await msg_history_schema.async_validate(
930929
iteration, msg_str, self.metadata
931930
)
@@ -957,7 +956,7 @@ async def async_prepare(
957956
llm_output=prompt.source,
958957
)
959958
iteration = Iteration(inputs=inputs)
960-
call_log.iterations.push(iteration)
959+
call_log.iterations.insert(0, iteration)
961960
validated_prompt = await prompt_schema.async_validate(
962961
iteration, prompt.source, self.metadata
963962
)
@@ -976,7 +975,7 @@ async def async_prepare(
976975
llm_output=instructions.source,
977976
)
978977
iteration = Iteration(inputs=inputs)
979-
call_log.iterations.push(iteration)
978+
call_log.iterations.insert(0, iteration)
980979
validated_instructions = await instructions_schema.async_validate(
981980
iteration, instructions.source, self.metadata
982981
)

0 commit comments

Comments
 (0)