Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pawel/improve ci #21

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: end-to-end tests
name: CI

on:
pull_request:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ repos:
- id: mypy
additional_dependencies:
- pydantic
- httpx
2 changes: 1 addition & 1 deletion chainlit_client/__init__.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
26 changes: 17 additions & 9 deletions chainlit_client/api.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion chainlit_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,7 +15,6 @@
step_decorator,
)
from chainlit_client.thread import ThreadContextManager, thread_decorator
from chainlit_client.types import Attachment


class ChainlitClient:
Expand Down
2 changes: 1 addition & 1 deletion chainlit_client/instrumentation/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
2 changes: 1 addition & 1 deletion chainlit_client/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion chainlit_client/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion chainlit_client/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[mypy]
plugins = pydantic.mypy
exclude = "examples/"

[mypy-setuptools.*]
ignore_missing_imports = True
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ pytest
pytest-asyncio
pre-commit
python-dotenv
ruff
mypy
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/e2e/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.mark.skip(reason="segmentaion fault")
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
Expand Down