Skip to content

Commit 2dd54fc

Browse files
CopilotTomeHirata
andcommitted
Remove unnecessary try-catch around truncate_trajectory
Co-authored-by: TomeHirata <[email protected]>
1 parent ae1b52a commit 2dd54fc

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

dspy/predict/react.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,7 @@ def _call_with_potential_trajectory_truncation(self, module, trajectory, **input
152152
)
153153
except ContextWindowExceededError:
154154
logger.warning("Trajectory exceeded the context window, truncating the oldest tool call information.")
155-
try:
156-
trajectory = self.truncate_trajectory(trajectory)
157-
except ValueError:
158-
# Cannot truncate further, raise a clear error
159-
raise ValueError(
160-
"The context window was exceeded and the trajectory could not be truncated further."
161-
) from None
155+
trajectory = self.truncate_trajectory(trajectory)
162156
raise ValueError(
163157
"The context window was exceeded even after 3 attempts to truncate the trajectory."
164158
)
@@ -172,13 +166,7 @@ async def _async_call_with_potential_trajectory_truncation(self, module, traject
172166
)
173167
except ContextWindowExceededError:
174168
logger.warning("Trajectory exceeded the context window, truncating the oldest tool call information.")
175-
try:
176-
trajectory = self.truncate_trajectory(trajectory)
177-
except ValueError:
178-
# Cannot truncate further, raise a clear error
179-
raise ValueError(
180-
"The context window was exceeded and the trajectory could not be truncated further."
181-
) from None
169+
trajectory = self.truncate_trajectory(trajectory)
182170
raise ValueError(
183171
"The context window was exceeded even after 3 attempts to truncate the trajectory."
184172
)

0 commit comments

Comments
 (0)