Spaces:
Running
Running
Download src/free_claude_code/application/model_fallback/decision.py from dherain24/claude-proxy: direct link, hf CLI and curl.
- Browser
- Download file 2.48 kB
-
https://huggingface.co/spaces/dherain24/claude-proxy/resolve/main/src/free_claude_code/application/model_fallback/decision.py
- Command line
-
hf download hf://spaces/dherain24/claude-proxy/src/free_claude_code/application/model_fallback/decision.py
-
curl -L -o decision.py https://huggingface.co/spaces/dherain24/claude-proxy/resolve/main/src/free_claude_code/application/model_fallback/decision.py
2.48 kB
| from __future__ import annotations | |
| """Decide what follows one failed model candidate. | |
| Pure: the caller supplies what the client has received and what the failed | |
| candidate left behind, and acts on the step returned. | |
| """ | |
| from dataclasses import dataclass | |
| from free_claude_code.core.stream_recovery import ( | |
| ContinuationSeed, | |
| DeliveredPrefix, | |
| RecoveryAction, | |
| StreamFailureContext, | |
| assess_recovery, | |
| ) | |
| class CandidateFailure: | |
| """What one failed candidate left behind.""" | |
| context: StreamFailureContext | None | |
| retryable: bool | |
| produced_output: bool | |
| class Fail: | |
| """Raise the candidate's failure to the client.""" | |
| class Handoff: | |
| """End the response so the client can act on its released tool calls.""" | |
| class Fallback: | |
| """Open the next candidate, continuing from ``seed`` when there is one.""" | |
| seed: ContinuationSeed | None | |
| action: RecoveryAction | |
| reason: str | None | |
| type FallbackStep = Fail | Handoff | Fallback | |
| def next_step( | |
| failure: CandidateFailure, | |
| *, | |
| content_released: bool, | |
| prefix: DeliveredPrefix | None, | |
| seed: ContinuationSeed | None, | |
| has_next: bool, | |
| ) -> FallbackStep: | |
| """Return the step after ``failure``, given the delivery so far. | |
| ``prefix`` is what the client has received; it is consulted only when the | |
| failure carries stream evidence. | |
| """ | |
| action = RecoveryAction.CONTINUE if seed is not None else RecoveryAction.RESTART | |
| reason: str | None = "no_candidate_output" | |
| if failure.context is None: | |
| # Without stream evidence, only a candidate that produced nothing | |
| # leaves the delivered prefix, and so the current seed, intact. | |
| if content_released and (failure.produced_output or seed is None): | |
| return Fail() | |
| else: | |
| assessment = assess_recovery( | |
| content_released=content_released, | |
| prefix=prefix, | |
| source=failure.context.source, | |
| retryable=failure.retryable, | |
| ) | |
| if assessment.action is RecoveryAction.STOP: | |
| return Fail() | |
| if assessment.action is RecoveryAction.HANDOFF: | |
| return Handoff() | |
| seed = assessment.seed | |
| action = assessment.action | |
| reason = assessment.reason | |
| if not has_next: | |
| return Fail() | |
| return Fallback(seed, action, reason) | |