Skip to content

Commit

Permalink
fix: ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard committed Dec 30, 2024
1 parent ff0251f commit c60a26d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion backend/chainlit/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def get_configuration():
"oauthProviders": (
get_configured_oauth_providers() if is_oauth_enabled() else []
),
"default_theme": config.ui.default_theme
"default_theme": config.ui.default_theme,
}


Expand Down
1 change: 1 addition & 0 deletions backend/chainlit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class Palette(DataClassJsonMixin):
paper: Optional[str] = ""
text: Optional[TextOptions] = None


@dataclass
class SpontaneousFileUploadFeature(DataClassJsonMixin):
enabled: Optional[bool] = None
Expand Down
27 changes: 13 additions & 14 deletions backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,36 +474,29 @@ async def logout(request: Request, response: Response):
async def jwt_auth(request: Request):
"""Login a user using a valid jwt."""
from jwt import InvalidTokenError

auth_header: Optional[str] = request.headers.get("Authorization")
if not auth_header:
raise HTTPException(
status_code=401,
detail="Authorization header missing"
)
raise HTTPException(status_code=401, detail="Authorization header missing")

# Check if it starts with "Bearer "
try:
scheme, token = auth_header.split()
if scheme.lower() != "bearer":
raise HTTPException(
status_code=401,
detail="Invalid authentication scheme. Please use Bearer"
detail="Invalid authentication scheme. Please use Bearer",
)
except ValueError:
raise HTTPException(
status_code=401,
detail="Invalid authorization header format"
status_code=401, detail="Invalid authorization header format"
)

try:
user = decode_jwt(token)
return await _authenticate_user(user)
except InvalidTokenError:
raise HTTPException(
status_code=401,
detail="Invalid token"
)
raise HTTPException(status_code=401, detail="Invalid token")


@router.post("/auth/header")
Expand Down Expand Up @@ -863,6 +856,7 @@ async def rename_thread(
await data_layer.update_thread(thread_id, name=payload.name)
return JSONResponse(content={"success": True})


@router.delete("/project/thread")
async def delete_thread(
request: Request,
Expand Down Expand Up @@ -894,13 +888,17 @@ async def call_action(
from chainlit.session import WebsocketSession
from chainlit.action import Action
from chainlit.context import init_ws_context

Check failure on line 891 in backend/chainlit/server.py

View workflow job for this annotation

GitHub Actions / lint-backend / lint-backend

Ruff (I001)

backend/chainlit/server.py:888:1: I001 Import block is un-sorted or un-formatted
session = WebsocketSession.get_by_id(payload.sessionId)
context = init_ws_context(session)

action = Action(**payload.action)

if current_user:
if not context.session.user or context.session.user.identifier != current_user.identifier:
if (
not context.session.user
or context.session.user.identifier != current_user.identifier
):
raise HTTPException(
status_code=401,
detail="You are not authorized to upload files for this session",
Expand All @@ -917,6 +915,7 @@ async def call_action(

return JSONResponse(content={"success": True})


@router.post("/project/file")
async def upload_file(
current_user: UserParam,
Expand Down
1 change: 1 addition & 0 deletions backend/chainlit/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ async def audio_end(sid):
finally:
await context.emitter.task_end()


@sio.on("chat_settings_change")
async def change_settings(sid, settings: Dict[str, Any]):
"""Handle change settings submit from the UI."""
Expand Down
2 changes: 2 additions & 0 deletions backend/chainlit/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class UpdateThreadRequest(BaseModel):
class DeleteThreadRequest(BaseModel):
threadId: str


class DeleteFeedbackRequest(BaseModel):
feedbackId: str

Expand All @@ -214,6 +215,7 @@ class CallActionRequest(BaseModel):
action: Dict
sessionId: str


class Theme(str, Enum):
light = "light"
dark = "dark"
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/action/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ async def main():
).send()

if result is not None:
await cl.Message(f"Thanks for pressing: {result["payload"]['value']}").send()
await cl.Message(f"Thanks for pressing: {result['payload']['value']}").send()

0 comments on commit c60a26d

Please sign in to comment.