Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove transcript from decorator for now #473

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/inspect_ai/solver/_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,12 @@ async def __call__(
state: TaskState,
generate: Generate,
) -> TaskState:
from ._transcript import solver_transcript

for solver in self._solvers:
state = await solver(state, generate)
with solver_transcript(solver, state) as st:
state = await solver(state, generate)
st.complete(state)
if state.completed:
break

Expand Down
10 changes: 8 additions & 2 deletions src/inspect_ai/solver/_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ async def __call__(
state: TaskState,
generate: Generate,
) -> TaskState:
from ._transcript import solver_transcript

try:
# execute steps
for index, solver in enumerate(self.steps):
# run solver
state = await solver(state, generate)
with solver_transcript(solver, state) as st:
state = await solver(state, generate)
st.complete(state)

# tick progress
self.progress()
Expand All @@ -114,7 +118,9 @@ async def __call__(

# execute finish
if self.finish:
state = await self.finish(state, generate)
with solver_transcript(self.finish, state) as st:
state = await self.finish(state, generate)
st.complete(state)
self.progress()

# mark completed
Expand Down
22 changes: 2 additions & 20 deletions src/inspect_ai/solver/_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,15 @@ def solver_wrapper(*args: Any, **kwargs: dict[str, Any]) -> Solver:
if not is_callable_coroutine(solver):
raise TypeError(f"'{solver}' is not declared as an async callable.")

async def solver_with_transcript(
state: TaskState, generate: Generate
) -> TaskState:
from ._transcript import solver_transcript

with solver_transcript(solver, state, solver_name) as st: # type: ignore
state = await solver(state, generate)
st.complete(state)
return state

# don't wrap transcript around compound solver types
from ._chain import Chain
from ._plan import Plan

target_solver = (
solver if isinstance(solver, Chain | Plan) else solver_with_transcript
)

registry_tag(
solver_type,
target_solver,
solver,
RegistryInfo(type="solver", name=solver_name),
*args,
**kwargs,
)

return target_solver
return solver

return solver_register(cast(SolverType, solver_wrapper), solver_name)

Expand Down
Loading