Fix basedpyright regressions for custom instructions

This commit is contained in:
adavyas 2026-04-07 12:33:34 -04:00
parent c6ca57b9d8
commit bd801f4964
3 changed files with 8 additions and 11 deletions

View File

@ -285,7 +285,7 @@ class DeriverSettings(BackupLLMSettingsMixin, HonchoSettings):
if self.MAX_CUSTOM_INSTRUCTIONS_TOKENS is None:
raise ValueError(
"No value configured for DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS. "
"Set [deriver].MAX_CUSTOM_INSTRUCTIONS_TOKENS in config.toml."
+ "Set [deriver].MAX_CUSTOM_INSTRUCTIONS_TOKENS in config.toml."
)
return self.MAX_CUSTOM_INSTRUCTIONS_TOKENS
@ -301,9 +301,7 @@ class DeriverSettings(BackupLLMSettingsMixin, HonchoSettings):
and self.MAX_CUSTOM_INSTRUCTIONS_TOKENS > self.MAX_INPUT_TOKENS
):
raise ValueError(
"MAX_CUSTOM_INSTRUCTIONS_TOKENS "
f"({self.MAX_CUSTOM_INSTRUCTIONS_TOKENS}) cannot exceed "
f"max deriver input tokens ({self.MAX_INPUT_TOKENS})"
f"MAX_CUSTOM_INSTRUCTIONS_TOKENS ({self.MAX_CUSTOM_INSTRUCTIONS_TOKENS}) cannot exceed max deriver input tokens ({self.MAX_INPUT_TOKENS})"
)
return self

View File

@ -5,7 +5,7 @@ the fully-resolved variants used at runtime.
"""
from enum import Enum
from typing import Any, Self, cast
from typing import Any, ClassVar, Self, cast
import tiktoken
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
@ -32,9 +32,7 @@ def _validate_custom_instructions_budget(value: str | None) -> str | None:
token_limit = settings.DERIVER.effective_max_custom_instructions_tokens
if token_count > token_limit:
raise ValueError(
"reasoning.custom_instructions uses "
f"{token_count} tokens and exceeds DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS "
f"({token_limit})"
f"reasoning.custom_instructions uses {token_count} tokens and exceeds DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS ({token_limit})"
)
return value
@ -56,7 +54,7 @@ class ReasoningConfiguration(BaseModel):
description="Optional custom instructions for the reasoning system on this workspace/session/message. May be omitted or set to a blank string. Non-blank values are rejected if they exceed the explicitly configured deriver custom-instructions token budget.",
)
_validate_custom_instructions = field_validator(
_validate_custom_instructions: ClassVar[Any] = field_validator(
"custom_instructions", mode="after"
)(_validate_custom_instructions_budget)
@ -163,7 +161,7 @@ class ResolvedReasoningConfiguration(BaseModel):
enabled: bool
custom_instructions: str | None = None
_validate_custom_instructions = field_validator(
_validate_custom_instructions: ClassVar[Any] = field_validator(
"custom_instructions", mode="after"
)(_validate_custom_instructions_budget)

View File

@ -1,5 +1,6 @@
from typing import Any
import pytest
from fastapi.testclient import TestClient
from nanoid import generate as generate_nanoid
@ -93,7 +94,7 @@ def test_create_session_with_configuration(
def test_create_session_rejects_over_budget_reasoning_custom_instructions(
client: TestClient,
sample_data: tuple[Workspace, Peer],
monkeypatch,
monkeypatch: pytest.MonkeyPatch,
):
test_workspace, test_peer = sample_data
session_id = str(generate_nanoid())