Skip to content

Commit f21b9a2

Browse files
committed
apply ruff linter
1 parent 33e8fcf commit f21b9a2

File tree

10 files changed

+128
-181
lines changed

10 files changed

+128
-181
lines changed

.flake8

Lines changed: 0 additions & 19 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
- repo: https://github.com/astral-sh/ruff-pre-commit
2+
# Ruff version.
3+
rev: v0.9.10
4+
hooks:
5+
# Run the linter.
6+
- id: ruff
7+
# Run the formatter.
8+
- id: ruff-format

ruff.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
line-length = 120
2+
indent-width = 4
3+
target-version = "py312"
4+
5+
exclude = [
6+
".venv",
7+
".vscode",
8+
"test/*"
9+
]
10+
11+
[lint]
12+
select = ["E", "F"]
13+
ignore = [
14+
"E501",
15+
"B008",
16+
"C901",
17+
"F401",
18+
"W191",
19+
]
20+
21+
[format]
22+
# use double quotes for strings.
23+
quote-style = "double"

src/api/auth.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616
# For backward compatibility.
1717
# Please now use secrets manager instead.
1818
ssm = boto3.client("ssm")
19-
api_key = ssm.get_parameter(Name=api_key_param, WithDecryption=True)["Parameter"][
20-
"Value"
21-
]
19+
api_key = ssm.get_parameter(Name=api_key_param, WithDecryption=True)["Parameter"]["Value"]
2220
elif api_key_secret_arn:
2321
sm = boto3.client("secretsmanager")
2422
try:
2523
response = sm.get_secret_value(SecretId=api_key_secret_arn)
2624
if "SecretString" in response:
2725
secret = json.loads(response["SecretString"])
2826
api_key = secret["api_key"]
29-
except ClientError as e:
30-
raise RuntimeError(
31-
"Unable to retrieve API KEY, please ensure the secret ARN is correct"
32-
)
33-
except KeyError as e:
27+
except ClientError:
28+
raise RuntimeError("Unable to retrieve API KEY, please ensure the secret ARN is correct")
29+
except KeyError:
3430
raise RuntimeError('Please ensure the secret contains a "api_key" field')
3531
elif api_key_env:
3632
api_key = api_key_env
@@ -45,6 +41,4 @@ def api_key_auth(
4541
credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)],
4642
):
4743
if credentials.credentials != api_key:
48-
raise HTTPException(
49-
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid API Key"
50-
)
44+
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid API Key")

src/api/models/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def generate_message_id() -> str:
4343
return "chatcmpl-" + str(uuid.uuid4())[:8]
4444

4545
@staticmethod
46-
def stream_response_to_bytes(
47-
response: ChatStreamResponse | None = None
48-
) -> bytes:
46+
def stream_response_to_bytes(response: ChatStreamResponse | None = None) -> bytes:
4947
if response:
5048
# to populate other fields when using exclude_unset=True
5149
response.system_fingerprint = "fp"

0 commit comments

Comments
 (0)