Skip to content

Commit

Permalink
refactor: Distinct frontend from backend
Browse files Browse the repository at this point in the history
  • Loading branch information
alimtunc committed Sep 4, 2023
1 parent c71a3f0 commit 1b8deaa
Show file tree
Hide file tree
Showing 227 changed files with 110 additions and 118 deletions.
25 changes: 13 additions & 12 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ Generated using https://ecotrust-canada.github.io/markdown-toc/.
I've copy/pasted the whole document there, without the previous two headings.
-->

- [Local setup](#local-setup)
- [Requirements](#requirements)
- [Setup the repo](#setup-the-repo)
- [Install JS dependencies](#install-js-dependencies)
- [Install python dependencies](#install-python-dependencies)
- [Start the Chainlit server from source](#start-the-chainlit-server-from-source)
- [Start the UI from source](#start-the-ui-from-source)
- [Run the tests](#run-the-tests)
- [Run one test](#run-one-test)

- [Contribute to Chainlit](#contribute-to-chainlit)
- [Table of Contents](#table-of-contents)
- [Local setup](#local-setup)
- [Requirements](#requirements)
- [Setup the repo](#setup-the-repo)
- [Install JS dependencies](#install-js-dependencies)
- [Install python dependencies](#install-python-dependencies)
- [Start the Chainlit server from source](#start-the-chainlit-server-from-source)
- [Start the UI from source](#start-the-ui-from-source)
- [Run the tests](#run-the-tests)
- [Run one test](#run-one-test)

## Local setup

Expand Down Expand Up @@ -90,7 +91,7 @@ You need to build the UI once before starting the server.
pnpm run buildUi
```

Start by running `src/chainlit/hello.py` as an example.
Start by running `backend/hello.py` as an example.

```sh
cd src
Expand All @@ -108,7 +109,7 @@ First, you will have to start the server either [from source](#start-the-chainli
Then, start the UI.

```sh
cd src/chainlit/frontend
cd frontend
pnpm run dev --port 5174
```

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./src/
working-directory: ./backend
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ jobs:
python-version: "3.8"
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Copy readme to src
run: cp README.md src/
- name: Copy readme to backend
run: cp README.md backend/
- name: Install JS dependencies
run: pnpm install --no-frozen-lockfile
- name: Build chainlit
run: pnpm run build
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: src/dist
packages-dir: backend/dist
password: ${{ secrets.PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion PRIVACY_POLICY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 📏 Telemetry

Chainlit collects specific metadata points by default to help us better understand and improve the package based on community usage. We greatly value your privacy and ensure that the metadata we collect [is limited](/src/chainlit//telemetry.py).
Chainlit collects specific metadata points by default to help us better understand and improve the package based on community usage. We greatly value your privacy and ensure that the metadata we collect [is limited](/backend/telemetry.py).

### 🕵️‍♀️ Scope

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 2 additions & 3 deletions src/chainlit/action.py → backend/chainlit/action.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import uuid
from typing import Optional

from dataclasses_json import DataClassJsonMixin
from pydantic.dataclasses import Field, dataclass

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


@dataclass
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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
File renamed without changes.
1 change: 0 additions & 1 deletion src/chainlit/cli/auth.py → backend/chainlit/cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
AsymmetricSignatureVerifier,
TokenVerifier,
)

from chainlit.logger import logger

AUTH0_DOMAIN = "auth.chainlit.io"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tempfile

import requests

from chainlit.cli.auth import get_access_token
from chainlit.cli.utils import check_file
from chainlit.config import config
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
Union,
)

from dataclasses_json import DataClassJsonMixin
from pydantic.dataclasses import dataclass
from starlette.datastructures import Headers

from chainlit.prompt import Prompt
from chainlit.types import (
ConversationFilter,
Expand All @@ -23,6 +19,9 @@
ElementType,
Pagination,
)
from dataclasses_json import DataClassJsonMixin
from pydantic.dataclasses import dataclass
from starlette.datastructures import Headers


class MessageDict(TypedDict):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
from typing import Any, Dict, Mapping, Optional, Union, cast

import aiohttp
from python_graphql_client import GraphqlClient
from starlette.datastructures import Headers

from chainlit.client.base import MessageDict, UserDict
from chainlit.config import config
from chainlit.logger import logger
from python_graphql_client import GraphqlClient
from starlette.datastructures import Headers

from .base import BaseAuthClient, BaseDBClient, PageInfo, PaginatedResponse, UserDict

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Dict, Optional, Union, cast

import aiofiles

from chainlit.client.base import PageInfo, PaginatedResponse
from chainlit.config import config
from chainlit.logger import logger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from typing import Dict, Optional

from fastapi import HTTPException, Request
from starlette.datastructures import Headers

from chainlit.client.base import BaseAuthClient, BaseDBClient, UserDict
from chainlit.client.cloud import CloudAuthClient, CloudDBClient
from chainlit.client.local import LocalAuthClient, LocalDBClient
from chainlit.config import config
from fastapi import HTTPException, Request
from starlette.datastructures import Headers


async def get_auth_client(
Expand Down
5 changes: 2 additions & 3 deletions src/chainlit/config.py → backend/chainlit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Literal, Optional, Union

import tomli
from chainlit.logger import logger
from chainlit.version import __version__
from dataclasses_json import DataClassJsonMixin
from pydantic.dataclasses import dataclass
from starlette.datastructures import Headers

from chainlit.logger import logger
from chainlit.version import __version__

if TYPE_CHECKING:
from chainlit.action import Action
from chainlit.client.base import BaseAuthClient, BaseDBClient
Expand Down
3 changes: 1 addition & 2 deletions src/chainlit/context.py → backend/chainlit/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from contextvars import ContextVar
from typing import TYPE_CHECKING

from lazify import LazyProxy

from chainlit.session import Session
from lazify import LazyProxy

if TYPE_CHECKING:
from chainlit.emitter import ChainlitEmitter
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/chainlit/element.py → backend/chainlit/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@

import aiofiles
import filetype
from pydantic.dataclasses import Field, dataclass

from chainlit.client.base import BaseDBClient, ElementDict
from chainlit.context import context
from chainlit.telemetry import trace_event
from chainlit.types import ElementDisplay, ElementSize, ElementType
from pydantic.dataclasses import Field, dataclass

mime_types = {
"text": "text/plain",
Expand Down
3 changes: 1 addition & 2 deletions src/chainlit/emitter.py → backend/chainlit/emitter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import uuid
from typing import Any, Dict, Union, cast

from socketio.exceptions import TimeoutError

from chainlit.client.base import BaseDBClient, MessageDict
from chainlit.message import Message
from chainlit.session import Session
from chainlit.types import AskSpec, FileSpec
from socketio.exceptions import TimeoutError


class ChainlitEmitter:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Any, Generic, List, Optional, TypeVar

from chainlit.config import config
from chainlit.context import context
from haystack.agents import Agent, Tool
from haystack.agents.agent_step import AgentStep

import chainlit as cl
from chainlit.config import config
from chainlit.context import context

T = TypeVar("T")

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
from collections import defaultdict
from typing import Any, Dict, List, Optional

from pydantic.dataclasses import Field, dataclass

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


@dataclass
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from chainlit.prompt import Prompt, PromptMessage
from chainlit.sync import run_sync

from chainlit import input_widget

IGNORE_LIST = [] # type: List[str]
DEFAULT_ANSWER_PREFIX_TOKENS = ["Final", "Answer", ":"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Dict, Optional, Union

import aiohttp

from chainlit.telemetry import trace_event


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import asyncio
from typing import Any, Dict, List, Optional

from llama_index.callbacks.base import BaseCallbackHandler
from llama_index.callbacks.schema import CBEventType, EventPayload
from llama_index.llms.base import ChatMessage, ChatResponse, CompletionResponse

from chainlit.context import context_var
from chainlit.element import Text
from chainlit.message import Message
from chainlit.prompt import Prompt, PromptMessage
from llama_index.callbacks.base import BaseCallbackHandler
from llama_index.callbacks.schema import CBEventType, EventPayload
from llama_index.llms.base import ChatMessage, ChatResponse, CompletionResponse

DEFAULT_IGNORE = [
CBEventType.CHUNKING,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from typing import Any, Dict, List, Union

from fastapi import HTTPException
from pydantic.dataclasses import dataclass

from chainlit import input_widget
from chainlit.config import config
from chainlit.prompt import Prompt, PromptMessage
from chainlit.telemetry import trace_event
from chainlit.types import CompletionRequest
from fastapi import HTTPException
from pydantic.dataclasses import dataclass

from chainlit import input_widget


@dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from fastapi import HTTPException
from fastapi.responses import StreamingResponse

from chainlit.input_widget import Select, Slider, Tags
from chainlit.playground.provider import BaseProvider
from chainlit.prompt import PromptMessage
from fastapi import HTTPException
from fastapi.responses import StreamingResponse


class AnthropicProvider(BaseProvider):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from typing import Optional

from fastapi import HTTPException
from fastapi.responses import StreamingResponse
from pydantic.dataclasses import dataclass

from chainlit.input_widget import Slider
from chainlit.playground.provider import BaseProvider
from chainlit.sync import make_async
from fastapi import HTTPException
from fastapi.responses import StreamingResponse
from pydantic.dataclasses import dataclass


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from chainlit.prompt import PromptMessage
from chainlit.sync import make_async

from chainlit import input_widget


class LangchainGenericProvider(BaseProvider):
from langchain.chat_models.base import BaseChatModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from contextlib import contextmanager

from fastapi import HTTPException
from fastapi.responses import StreamingResponse

from chainlit.input_widget import Select, Slider, Tags
from chainlit.playground.provider import BaseProvider
from fastapi import HTTPException
from fastapi.responses import StreamingResponse

openai_common_inputs = [
Slider(
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1b8deaa

Please sign in to comment.