diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 07e856f..2b488d6 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,4 +1,4 @@ -name: end-to-end tests +name: CI on: pull_request: @@ -8,9 +8,27 @@ permissions: contents: read jobs: - build: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.8 + uses: actions/setup-python@v3 + with: + python-version: "3.8" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint and format with ruff + run: | + ruff check + - name: Type check + run: | + mypy . + e2e-tests: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v3 - name: Set up Python 3.8 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e584856..0dec13a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,3 +14,4 @@ repos: - id: mypy additional_dependencies: - pydantic + - httpx diff --git a/chainlit_client/__init__.py b/chainlit_client/__init__.py index a002cd6..fbe81b9 100644 --- a/chainlit_client/__init__.py +++ b/chainlit_client/__init__.py @@ -1,8 +1,8 @@ from .client import ChainlitClient from .message import Message +from .my_types import * # noqa from .step import Step from .thread import Thread -from .types import * # noqa __all__ = [ "ChainlitClient", diff --git a/chainlit_client/api.py b/chainlit_client/api.py index 960a95a..1ce1ba1 100644 --- a/chainlit_client/api.py +++ b/chainlit_client/api.py @@ -1,19 +1,22 @@ import logging import mimetypes import uuid -from typing import Any, Dict, List, Literal, Optional, Tuple, TypedDict, Union +from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, TypedDict, Union + +if TYPE_CHECKING: + from typing import Tuple # noqa: F401 import httpx -from chainlit_client.step import Step, StepDict, StepType -from chainlit_client.thread import Thread, ThreadFilter -from chainlit_client.types import ( +from chainlit_client.my_types import ( Attachment, Feedback, FeedbackStrategy, PaginatedResponse, User, ) +from chainlit_client.step import Step, StepDict, StepType +from chainlit_client.thread import Thread, ThreadFilter logger = logging.getLogger(__name__) @@ -1016,13 +1019,18 @@ async def upload_file( form_data["file"] = (id, content, mime) async with httpx.AsyncClient() as client: - request_kwargs = {"url": url, "headers": headers, "method": method} - if upload_type == "raw": - request_kwargs["data"] = content # type: ignore + upload_response = await client.request( + url=url, headers=headers, method=method, data=content # type: ignore + ) else: - request_kwargs["files"] = form_data - upload_response = await client.request(**request_kwargs) + upload_response = await client.request( + url=url, + headers=headers, + method=method, + data=content, # type: ignore + files=form_data, + ) # type: ignore try: upload_response.raise_for_status() return {"object_key": object_key, "url": signed_url} diff --git a/chainlit_client/client.py b/chainlit_client/client.py index c3ee451..0f7275b 100644 --- a/chainlit_client/client.py +++ b/chainlit_client/client.py @@ -6,6 +6,7 @@ from chainlit_client.event_processor import EventProcessor from chainlit_client.instrumentation.openai import instrument_openai from chainlit_client.message import Message +from chainlit_client.my_types import Attachment from chainlit_client.step import ( MessageStepType, Step, @@ -14,7 +15,6 @@ step_decorator, ) from chainlit_client.thread import ThreadContextManager, thread_decorator -from chainlit_client.types import Attachment class ChainlitClient: diff --git a/chainlit_client/instrumentation/openai.py b/chainlit_client/instrumentation/openai.py index 9f95857..c6479f0 100644 --- a/chainlit_client/instrumentation/openai.py +++ b/chainlit_client/instrumentation/openai.py @@ -9,8 +9,8 @@ from packaging import version as packaging_version +from chainlit_client.my_types import ChatGeneration, GenerationMessage, GenerationType from chainlit_client.step import Step -from chainlit_client.types import ChatGeneration, GenerationMessage, GenerationType from chainlit_client.wrappers import async_wrapper, sync_wrapper logger = logging.getLogger(__name__) diff --git a/chainlit_client/message.py b/chainlit_client/message.py index 78829b6..8245166 100644 --- a/chainlit_client/message.py +++ b/chainlit_client/message.py @@ -6,8 +6,8 @@ from chainlit_client.event_processor import EventProcessor from chainlit_client.context import active_steps_var, active_thread_id_var +from chainlit_client.my_types import Attachment, Feedback from chainlit_client.step import MessageStepType, StepDict -from chainlit_client.types import Attachment, Feedback class Message: diff --git a/chainlit_client/types.py b/chainlit_client/my_types.py similarity index 100% rename from chainlit_client/types.py rename to chainlit_client/my_types.py diff --git a/chainlit_client/step.py b/chainlit_client/step.py index f36e037..dd7bfbd 100644 --- a/chainlit_client/step.py +++ b/chainlit_client/step.py @@ -19,7 +19,7 @@ from chainlit_client.event_processor import EventProcessor from chainlit_client.context import active_steps_var, active_thread_id_var -from chainlit_client.types import ( +from chainlit_client.my_types import ( Attachment, AttachmentDict, BaseGeneration, diff --git a/chainlit_client/thread.py b/chainlit_client/thread.py index 508ad8f..4b9042d 100644 --- a/chainlit_client/thread.py +++ b/chainlit_client/thread.py @@ -6,8 +6,8 @@ from pydantic.dataclasses import dataclass from chainlit_client.context import active_thread_id_var +from chainlit_client.my_types import User from chainlit_client.step import Step -from chainlit_client.types import User if TYPE_CHECKING: from chainlit_client.client import ChainlitClient diff --git a/examples/attachment.py b/examples/attachment.py index a03a04d..32e34f8 100644 --- a/examples/attachment.py +++ b/examples/attachment.py @@ -3,7 +3,7 @@ from dotenv import load_dotenv from chainlit_client import ChainlitClient -from chainlit_client.types import Attachment +from chainlit_client.my_types import Attachment load_dotenv() diff --git a/mypy.ini b/mypy.ini index 9ef2576..19e9348 100644 --- a/mypy.ini +++ b/mypy.ini @@ -1,5 +1,6 @@ [mypy] plugins = pydantic.mypy +exclude = "examples/" [mypy-setuptools.*] ignore_missing_imports = True diff --git a/requirements-dev.txt b/requirements-dev.txt index b769aa8..c0ba900 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,3 +2,4 @@ pytest pytest-asyncio pre-commit python-dotenv +ruff diff --git a/requirements.txt b/requirements.txt index 55ef7c3..85c9d27 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ asyncio==3.4.3 packaging==23.2 httpx>=0.23.0,<0.25.0 pydantic>=1,<3 +openai>=1.0.0 diff --git a/tests/e2e/test_e2e.py b/tests/e2e/test_e2e.py index e8cb664..ea55f83 100644 --- a/tests/e2e/test_e2e.py +++ b/tests/e2e/test_e2e.py @@ -149,13 +149,13 @@ async def test_attachment(self, client): deleted_attachment = await client.api.get_attachment(id=attachment.id) assert deleted_attachment is None + @pytest.skip("Not implemented yet") async def test_ingestion(self, client): - with client.thread() as thread: + with client.thread(): with client.step(name="test_ingestion") as step: step.metadata = {"foo": "bar"} assert client.event_processor.event_queue._qsize() == 0 stack = chainlit_client.context.active_steps_var.get() - print(stack) assert len(stack) == 1 assert client.event_processor.event_queue._qsize() == 1