Skip to content

Commit

Permalink
Sort all imports with ruff.
Browse files Browse the repository at this point in the history
  • Loading branch information
dokterbob committed Nov 19, 2024
1 parent 5c98c75 commit 59ca064
Show file tree
Hide file tree
Showing 34 changed files with 105 additions and 71 deletions.
5 changes: 3 additions & 2 deletions backend/chainlit/action.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import uuid
from typing import Optional

from chainlit.context import context
from chainlit.telemetry import trace_event
from dataclasses_json import DataClassJsonMixin
from pydantic.dataclasses import Field, dataclass

from chainlit.context import context
from chainlit.telemetry import trace_event


@dataclass
class Action(DataClassJsonMixin):
Expand Down
5 changes: 3 additions & 2 deletions backend/chainlit/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from typing import Any, Dict

import jwt
from fastapi import Depends, HTTPException
from fastapi.security import OAuth2PasswordBearer

from chainlit.config import config
from chainlit.data import get_data_layer
from chainlit.oauth_providers import get_configured_oauth_providers
from chainlit.user import User
from fastapi import Depends, HTTPException
from fastapi.security import OAuth2PasswordBearer

reuseable_oauth = OAuth2PasswordBearer(tokenUrl="/login", auto_error=False)

Expand Down
3 changes: 2 additions & 1 deletion backend/chainlit/chat_settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import List

from pydantic.dataclasses import Field, dataclass

from chainlit.context import context
from chainlit.input_widget import InputWidget
from pydantic.dataclasses import Field, dataclass


@dataclass
Expand Down
3 changes: 2 additions & 1 deletion backend/chainlit/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from contextvars import ContextVar
from typing import TYPE_CHECKING, Dict, List, Optional, Union

from chainlit.session import ClientType, HTTPSession, WebsocketSession
from lazify import LazyProxy

from chainlit.session import ClientType, HTTPSession, WebsocketSession

if TYPE_CHECKING:
from chainlit.emitter import BaseChainlitEmitter
from chainlit.step import Step
Expand Down
3 changes: 2 additions & 1 deletion backend/chainlit/data/acl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from chainlit.data import get_data_layer
from fastapi import HTTPException

from chainlit.data import get_data_layer


async def is_thread_author(username: str, thread_id: str):
data_layer = get_data_layer()
Expand Down
4 changes: 3 additions & 1 deletion backend/chainlit/data/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import aiohttp
import boto3 # type: ignore
from boto3.dynamodb.types import TypeDeserializer, TypeSerializer

from chainlit.context import context
from chainlit.data.base import BaseDataLayer
from chainlit.data.storage_clients.base import BaseStorageClient
Expand All @@ -29,9 +30,10 @@
from chainlit.user import PersistedUser, User

if TYPE_CHECKING:
from chainlit.element import Element
from mypy_boto3_dynamodb import DynamoDBClient

from chainlit.element import Element


_logger = logger.getChild("DynamoDB")
_logger.setLevel(logging.WARNING)
Expand Down
9 changes: 5 additions & 4 deletions backend/chainlit/data/sql_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import aiofiles
import aiohttp
from sqlalchemy import text
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker

from chainlit.data.base import BaseDataLayer
from chainlit.data.storage_clients.base import BaseStorageClient
from chainlit.data.utils import queue_until_user_message
Expand All @@ -23,10 +28,6 @@
ThreadFilter,
)
from chainlit.user import PersistedUser, User
from sqlalchemy import text
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker

if TYPE_CHECKING:
from chainlit.element import Element, ElementDict
Expand Down
1 change: 1 addition & 0 deletions backend/chainlit/data/storage_clients/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
DataLakeServiceClient,
FileSystemClient,
)

from chainlit.data.storage_clients.base import BaseStorageClient
from chainlit.logger import logger

Expand Down
1 change: 1 addition & 0 deletions backend/chainlit/data/storage_clients/s3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, Union

import boto3 # type: ignore

from chainlit.data.storage_clients.base import BaseStorageClient
from chainlit.logger import logger

Expand Down
3 changes: 2 additions & 1 deletion backend/chainlit/discord/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import discord
import filetype
import httpx
from discord.ui import Button, View

from chainlit.config import config
from chainlit.context import ChainlitContext, HTTPSession, context, context_var
from chainlit.data import get_data_layer
Expand All @@ -23,7 +25,6 @@
from chainlit.types import Feedback
from chainlit.user import PersistedUser, User
from chainlit.user_session import user_session
from discord.ui import Button, View


class FeedbackView(View):
Expand Down
8 changes: 4 additions & 4 deletions backend/chainlit/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
)

import filetype
from pydantic.dataclasses import Field, dataclass
from syncer import asyncio

from chainlit.context import context
from chainlit.data import get_data_layer
from chainlit.logger import logger
from chainlit.telemetry import trace_event
from chainlit.types import FileDict
from pydantic.dataclasses import Field, dataclass
from syncer import asyncio

mime_types = {
"text": "text/plain",
Expand Down Expand Up @@ -352,8 +353,7 @@ class Plotly(Element):
content: str = ""

def __post_init__(self) -> None:
from plotly import graph_objects as go
from plotly import io as pio
from plotly import graph_objects as go, io as pio

if not isinstance(self.figure, go.Figure):
raise TypeError("figure must be a plotly.graph_objects.Figure")
Expand Down
7 changes: 4 additions & 3 deletions backend/chainlit/emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import uuid
from typing import Any, Dict, List, Literal, Optional, Union, cast

from literalai.helper import utc_now
from socketio.exceptions import TimeoutError

from chainlit.chat_context import chat_context
from chainlit.config import config
from chainlit.data import get_data_layer
Expand All @@ -16,12 +19,10 @@
FileDict,
FileReference,
MessagePayload,
OutputAudioChunk,
ThreadDict,
OutputAudioChunk
)
from chainlit.user import PersistedUser
from literalai.helper import utc_now
from socketio.exceptions import TimeoutError


class BaseChainlitEmitter:
Expand Down
7 changes: 4 additions & 3 deletions backend/chainlit/haystack/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import re
from typing import Any, Generic, List, Optional, TypeVar

from chainlit import Message
from chainlit.step import Step
from chainlit.sync import run_sync
from haystack.agents import Agent, Tool
from haystack.agents.agent_step import AgentStep
from literalai.helper import utc_now

from chainlit import Message
from chainlit.step import Step
from chainlit.sync import run_sync

T = TypeVar("T")


Expand Down
3 changes: 2 additions & 1 deletion backend/chainlit/input_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from collections import defaultdict
from typing import Any, Dict, List, Optional

from chainlit.types import InputWidgetType
from pydantic.dataclasses import Field, dataclass

from chainlit.types import InputWidgetType


@dataclass
class InputWidget:
Expand Down
7 changes: 4 additions & 3 deletions backend/chainlit/langchain/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from typing import Any, Dict, List, Optional, Sequence, Tuple, TypedDict, Union
from uuid import UUID

from chainlit.context import context_var
from chainlit.message import Message
from chainlit.step import Step
from langchain.callbacks.tracers.base import BaseTracer
from langchain.callbacks.tracers.schemas import Run
from langchain.schema import BaseMessage
Expand All @@ -14,6 +11,10 @@
from literalai.helper import utc_now
from literalai.observability.step import TrueStepType

from chainlit.context import context_var
from chainlit.message import Message
from chainlit.step import Step

DEFAULT_ANSWER_PREFIX_TOKENS = ["Final", "Answer", ":"]


Expand Down
1 change: 1 addition & 0 deletions backend/chainlit/langflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from typing import Dict, Optional, Union

import httpx

from chainlit.telemetry import trace_event


Expand Down
7 changes: 4 additions & 3 deletions backend/chainlit/llama_index/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
from typing import Any, Dict, List, Optional

from chainlit.context import context_var
from chainlit.element import Text
from chainlit.step import Step, StepType
from literalai import ChatGeneration, CompletionGeneration, GenerationMessage
from literalai.helper import utc_now
from llama_index.core.callbacks import TokenCountingHandler
from llama_index.core.callbacks.schema import CBEventType, EventPayload
from llama_index.core.llms import ChatMessage, ChatResponse, CompletionResponse
from llama_index.core.tools.types import ToolMetadata

from chainlit.context import context_var
from chainlit.element import Text
from chainlit.step import Step, StepType

DEFAULT_IGNORE = [
CBEventType.CHUNKING,
CBEventType.SYNTHESIZE,
Expand Down
5 changes: 3 additions & 2 deletions backend/chainlit/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from abc import ABC
from typing import Dict, List, Optional, Union, cast

from literalai.helper import utc_now
from literalai.observability.step import MessageStepType

from chainlit.action import Action
from chainlit.chat_context import chat_context
from chainlit.config import config
Expand All @@ -22,8 +25,6 @@
AskSpec,
FileDict,
)
from literalai.helper import utc_now
from literalai.observability.step import MessageStepType


class MessageBase(ABC):
Expand Down
5 changes: 3 additions & 2 deletions backend/chainlit/mistralai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
from typing import Union

from chainlit.context import get_context
from chainlit.step import Step
from literalai import ChatGeneration, CompletionGeneration
from literalai.helper import timestamp_utc

from chainlit.context import get_context
from chainlit.step import Step


def instrument_mistralai():
from literalai.instrumentation.mistralai import instrument_mistralai
Expand Down
3 changes: 2 additions & 1 deletion backend/chainlit/oauth_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from typing import Dict, List, Optional, Tuple

import httpx
from fastapi import HTTPException

from chainlit.secret import random_secret
from chainlit.user import User
from fastapi import HTTPException


class OAuthProvider:
Expand Down
5 changes: 3 additions & 2 deletions backend/chainlit/openai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
from typing import Union

from literalai import ChatGeneration, CompletionGeneration
from literalai.helper import timestamp_utc

from chainlit.context import local_steps
from chainlit.step import Step
from chainlit.utils import check_module_version
from literalai import ChatGeneration, CompletionGeneration
from literalai.helper import timestamp_utc


def instrument_openai():
Expand Down
42 changes: 22 additions & 20 deletions backend/chainlit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
from typing import Any, Optional, Union

import socketio
from fastapi import (
APIRouter,
Depends,
FastAPI,
File,
Form,
HTTPException,
Query,
Request,
Response,
UploadFile,
status,
)
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, RedirectResponse
from fastapi.security import OAuth2PasswordRequestForm
from fastapi.staticfiles import StaticFiles
from starlette.datastructures import URL
from starlette.middleware.cors import CORSMiddleware
from typing_extensions import Annotated
from watchfiles import awatch

from chainlit.auth import create_jwt, get_configuration, get_current_user
from chainlit.config import (
APP_ROOT,
Expand All @@ -37,26 +58,6 @@
UpdateFeedbackRequest,
)
from chainlit.user import PersistedUser, User
from fastapi import (
APIRouter,
Depends,
FastAPI,
File,
Form,
HTTPException,
Query,
Request,
Response,
UploadFile,
status,
)
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse, RedirectResponse
from fastapi.security import OAuth2PasswordRequestForm
from fastapi.staticfiles import StaticFiles
from starlette.datastructures import URL
from starlette.middleware.cors import CORSMiddleware
from typing_extensions import Annotated
from watchfiles import awatch

from ._utils import is_path_inside

Expand Down Expand Up @@ -248,6 +249,7 @@ async def slack_endpoint(req: Request):

if os.environ.get("TEAMS_APP_ID") and os.environ.get("TEAMS_APP_PASSWORD"):
from botbuilder.schema import Activity

from chainlit.teams.app import adapter, bot

@router.post("/teams/events")
Expand Down
Loading

0 comments on commit 59ca064

Please sign in to comment.