Skip to content

Commit

Permalink
Merge pull request #36 from arena-ai/fix_ruff_errors
Browse files Browse the repository at this point in the history
Draft: Fix ruff errors
  • Loading branch information
ngrislain authored Oct 15, 2024
2 parents e5e48d1 + ca0143e commit f95faf3
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 77 deletions.
4 changes: 2 additions & 2 deletions backend/.tools-cfg/ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ exclude = [
line-length = 79
indent-width = 4

# Assume Python 3.9
target-version = "py39"
# Assume Python 3.10
target-version = "py310"

[lint]

Expand Down
1 change: 0 additions & 1 deletion backend/app/lm/api/routes/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from fastapi import APIRouter

from app.api.deps import CurrentUser, SessionDep
Expand Down
19 changes: 19 additions & 0 deletions backend/app/lm/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,25 @@
import app.lm.models.mistral as mistral_models
import app.lm.models.anthropic as anthropic_models

__all__ = [
"Evaluation",
"Score",
"LMConfig",
"LMApiKeys",
"Function",
"FunctionDefinition",
"ChatCompletionToolParam",
"Message",
"ResponseFormatBase",
"ResponseFormat",
"ChatCompletionRequest",
"TopLogprob",
"TokenLogprob",
"ChoiceLogprobs",
"Choice",
"CompletionUsage",
]


class ChatCompletionRequestEventResponse(BaseModel):
request: (
Expand Down
15 changes: 15 additions & 0 deletions backend/app/ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,18 @@
rndi,
)
from app.ops.computation import Op, Computation

__all__ = [
"Var",
"var",
"Tup",
"tup",
"Const",
"cst",
"Rand",
"rnd",
"RandInt",
"rndi",
"Op",
"Computation",
]
4 changes: 2 additions & 2 deletions backend/app/ops/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def to_immutable(cls, obj: Any) -> Any:
elif isinstance(obj, list | tuple | set):
return tuple(cls.to_immutable(o) for o in obj)
elif hasattr(obj, "__dict__"):
return cls.to_immutable(getattr(obj, "__dict__"))
return cls.to_immutable(obj.__dict__)
elif isinstance(obj, str | int | float | NoneType):
return obj
else:
Expand All @@ -69,7 +69,7 @@ def to_json_dict(cls, obj: Any) -> Any:
elif isinstance(obj, list | tuple | set):
return [cls.to_json_dict(o) for o in obj]
elif hasattr(obj, "__dict__"):
return cls.to_json_dict(getattr(obj, "__dict__"))
return cls.to_json_dict(obj.__dict__)
elif isinstance(obj, str | int | float | NoneType):
return obj
else:
Expand Down
2 changes: 2 additions & 0 deletions backend/app/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

from app.services.service import Service
from app.services.models import Request, Response

__all__ = ["Service", "Request", "Response"]
26 changes: 13 additions & 13 deletions backend/app/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
Event,
EventIdentifier,
Attribute,
EventAttribute,
EventAttribute
)
from app.tests.utils.user import authentication_token_from_email
from app.tests.utils.utils import get_superuser_token_headers
from app.lm.models import (
LMApiKeys,
openai,
mistral,
anthropic,
anthropic,Choice,TokenLogprob,ChoiceLogprobs,TopLogprob,CompletionUsage,Message
)


Expand Down Expand Up @@ -145,26 +145,26 @@ def chat_completion_openai() -> openai.ChatCompletionResponse:
return openai.ChatCompletionResponse(
id="cmpl-123",
choices=[
openai.Choice(
Choice(
finish_reason="stop",
index=0,
logprobs=openai.ChoiceLogprobs(
logprobs=ChoiceLogprobs(
content=[
openai.TokenLogprob(
TokenLogprob(
token="Hello",
logprob=-1.34,
top_logprobs=[],
text_offset=None,
),
openai.TokenLogprob(
TokenLogprob(
token="world!",
logprob=-1.19,
top_logprobs=[],
text_offset=None,
),
]
),
message=openai.Message(
message=Message(
role="assistant", content="Hello world!"
),
)
Expand All @@ -173,7 +173,7 @@ def chat_completion_openai() -> openai.ChatCompletionResponse:
model="gpt-3.5-turbo",
object="chat.completion",
system_fingerprint="0x1234abcd",
usage=openai.CompletionUsage(
usage=CompletionUsage(
prompt_tokens=5,
completion_tokens=10,
total_tokens=15,
Expand Down Expand Up @@ -209,20 +209,20 @@ def chat_completion_mistral() -> mistral.ChatCompletionResponse:
return mistral.ChatCompletionResponse(
id="cmpl-3o4Mn05jW6S9Zu2DLt2g3t0aFgU",
choices=[
mistral.Choice(
Choice(
index=0,
message=mistral.Message(
role="assistant",
content="Hello, how can I assist you today?",
),
finish_reason="stop",
logprobs=mistral.ChoiceLogprobs(
logprobs=ChoiceLogprobs(
content=[
mistral.TokenLogprob(
TokenLogprob(
token=".",
logprob=-0.100103,
top_logprobs=[
mistral.TopLogprob(
TopLogprob(
token=".", logprob=-0.100103
)
],
Expand All @@ -234,7 +234,7 @@ def chat_completion_mistral() -> mistral.ChatCompletionResponse:
model="gpt-3.0-turbo",
object="chat.completion",
created=1661535393,
usage=mistral.CompletionUsage(
usage=CompletionUsage(
completion_tokens=11, prompt_tokens=3, total_tokens=14
),
)
Expand Down
8 changes: 4 additions & 4 deletions backend/app/tests/crud/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_delete_event(db: Session) -> None:
event_in=EventCreate(name="parent", content=random_lower_string()),
owner_id=alice.id,
)
children = [
_ = [
crud.create_event(
session=db,
event_in=EventCreate(
Expand All @@ -121,7 +121,7 @@ def test_delete_event(db: Session) -> None:
),
owner_id=alice.id,
)
for i in range(10)
for _ in range(10)
]
assert len(db.exec(select(User)).all()) == 3 # Superuser, Alice and Bob
assert len(db.exec(select(Event)).all()) == 11 # parent and children
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_delete_owner(db: Session) -> None:
event_in=EventCreate(name="parent", content=random_lower_string()),
owner_id=alice.id,
)
children = [
_ = [
crud.create_event(
session=db,
event_in=EventCreate(
Expand All @@ -163,7 +163,7 @@ def test_delete_owner(db: Session) -> None:
),
owner_id=alice.id,
)
for i in range(10)
for _ in range(10)
]
assert len(db.exec(select(User)).all()) == 3 # Superuser, Alice and Bob
assert len(db.exec(select(Event)).all()) == 11 # parent and children
Expand Down
4 changes: 2 additions & 2 deletions backend/app/tests/lm/api/test_lm_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def test_mistral(
json=chat_input_gen("mistral-small"),
)
assert response.status_code == 200
content = response.json()
_ = response.json()


@pytest.mark.skip(reason="Too costly")
Expand Down Expand Up @@ -266,7 +266,7 @@ def test_anthropic(
json=ccc.to_dict(),
)
assert response.status_code == 200
content = response.json()
_ = response.json()


@pytest.mark.skip(reason="Too costly")
Expand Down
24 changes: 10 additions & 14 deletions backend/app/tests/lm/models/test_lm_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@


def test_chat_completion_create_openai(chat_completion_create_openai) -> None:
ccc: Mapping = openai.ChatCompletionRequest.from_chat_completion_request(
_: Mapping = openai.ChatCompletionRequest.from_chat_completion_request(
chat_completion_create_openai
).to_dict()


def test_chat_completion_openai(chat_completion_openai) -> None:
cc: openai.ChatCompletionResponse = (
openai.ChatCompletionResponse.from_dict(
chat_completion_openai.model_dump()
).to_chat_completion_response()
)
_: openai.ChatCompletionResponse = openai.ChatCompletionResponse.from_dict(
chat_completion_openai.model_dump()
).to_chat_completion_response()


def test_chat_completion_create_mistral(
chat_completion_create_mistral,
) -> None:
m: Mapping = mistral.ChatCompletionRequest.from_chat_completion_request(
_: Mapping = mistral.ChatCompletionRequest.from_chat_completion_request(
chat_completion_create_mistral
).to_dict()


def test_chat_completion_mistral(chat_completion_mistral) -> None:
cc: mistral.ChatCompletionResponse = (
_: mistral.ChatCompletionResponse = (
mistral.ChatCompletionResponse.from_dict(
chat_completion_mistral.model_dump()
).to_chat_completion_response()
Expand All @@ -40,15 +38,13 @@ def test_chat_completion_mistral(chat_completion_mistral) -> None:
def test_chat_completion_create_anthropic(
chat_completion_create_anthropic,
) -> None:
mcp: Mapping = (
anthropic.ChatCompletionRequest.from_chat_completion_request(
chat_completion_create_anthropic
).to_dict()
)
_: Mapping = anthropic.ChatCompletionRequest.from_chat_completion_request(
chat_completion_create_anthropic
).to_dict()


def test_chat_completion_anthropic(chat_completion_anthropic) -> None:
cc: anthropic.ChatCompletionResponse = (
_: anthropic.ChatCompletionResponse = (
anthropic.ChatCompletionResponse.from_dict(
chat_completion_anthropic
).to_chat_completion_response()
Expand Down
11 changes: 0 additions & 11 deletions backend/app/tests/ops/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,5 @@ async def call(self, a: float, b: float) -> float:
print(s12.to_json())


def test_from_json() -> None:
from app.ops.settings import LMConfigSetting
from app.ops.session import session, user

s = LMConfigSetting()(session(), user())
print(f"BEFORE {s}")
value = s.to_json()
s = Computation.from_json(value)
print(f"AFTER {s}")


def test_flatten() -> None:
pass
29 changes: 2 additions & 27 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ pdf2image = "^1.17.0"
pytest = "^8.3"
pytest-cov = "^5.0"
mypy = "^1.8.0"
ruff = "^0.6"
pre-commit = "^3.6.2"
pytest-mock = "^3.12.0"
types-python-jose = "^3.3.4.0"
types-passlib = "^1.7.7.0"
rich = "^13.7.1"
ruff= "~=0.6.9"
ruff = "~=0.6.9"

[tool.isort]
multi_line_output = 3
Expand All @@ -63,28 +62,4 @@ build-backend = "poetry.masonry.api"

[tool.mypy]
strict = true
exclude = ["venv", "alembic"]

[tool.ruff]
target-version = "py311"

[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
]
ignore = [
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"W191", # indentation contains tabs
"B904", # Allow raising exceptions without from e, for HTTPException
]

[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true
exclude = ["venv", "alembic"]
2 changes: 1 addition & 1 deletion backend/scripts/specific-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e
set -x

echo "Testing $1"
python -m pytest -s $1
python -m pytest -s -vvv $1

0 comments on commit f95faf3

Please sign in to comment.