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

fix: update all enum classes to support python 3.11+ users #168

Merged
merged 3 commits into from
Dec 11, 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
7 changes: 3 additions & 4 deletions lanarky/adapters/langchain/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from enum import Enum
from typing import Any, Optional

from fastapi.websockets import WebSocket
Expand All @@ -12,10 +11,10 @@
from starlette.types import Message, Send

from lanarky.events import Events, ServerSentEvent, ensure_bytes
from lanarky.utils import model_dump_json
from lanarky.utils import StrEnum, model_dump_json


class LangchainEvents(str, Enum):
class LangchainEvents(StrEnum):
SOURCE_DOCUMENTS = "source_documents"


Expand Down Expand Up @@ -78,7 +77,7 @@ def _construct_message(self, data: str, event: Optional[str] = None) -> Message:
}


class TokenStreamMode(str, Enum):
class TokenStreamMode(StrEnum):
TEXT = "text"
JSON = "json"

Expand Down
4 changes: 2 additions & 2 deletions lanarky/adapters/langchain/responses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
from enum import Enum
from functools import partial
from typing import Any

Expand All @@ -11,9 +10,10 @@
from lanarky.logging import logger
from lanarky.responses import HTTPStatusDetail
from lanarky.responses import StreamingResponse as _StreamingResponse
from lanarky.utils import StrEnum


class ChainRunMode(str, Enum):
class ChainRunMode(StrEnum):
"""Enum for LangChain run modes."""

ASYNC = "async"
Expand Down
6 changes: 3 additions & 3 deletions lanarky/events.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from enum import Enum

from sse_starlette.sse import ServerSentEvent as ServerSentEvent
from sse_starlette.sse import ensure_bytes as ensure_bytes

from lanarky.utils import StrEnum


class Events(str, Enum):
class Events(StrEnum):
COMPLETION = "completion"
ERROR = "error"
END = "end"
4 changes: 2 additions & 2 deletions lanarky/responses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from enum import Enum
from typing import Any

from fastapi import status
Expand All @@ -7,9 +6,10 @@

from lanarky.events import Events, ServerSentEvent, ensure_bytes
from lanarky.logging import logger
from lanarky.utils import StrEnum


class HTTPStatusDetail(str, Enum):
class HTTPStatusDetail(StrEnum):
INTERNAL_SERVER_ERROR = "Internal Server Error"


Expand Down
9 changes: 9 additions & 0 deletions lanarky/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
import pydantic
from pydantic.fields import FieldInfo

try:
from enum import StrEnum # type: ignore
except ImportError:
from enum import Enum

class StrEnum(str, Enum):
...


PYDANTIC_V2 = pydantic.VERSION.startswith("2.")


Expand Down
4 changes: 2 additions & 2 deletions lanarky/websockets.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from contextlib import asynccontextmanager
from enum import Enum
from typing import Generator

from fastapi.websockets import WebSocket, WebSocketDisconnect

from lanarky.logging import logger
from lanarky.utils import StrEnum


class DataMode(str, Enum):
class DataMode(StrEnum):
JSON = "json"
TEXT = "text"
BYTES = "bytes"
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "lanarky"
version = "0.8.2"
version = "0.8.3"
description = "The web framework for building LLM microservices"
authors = ["Ajinkya Indulkar <ajndkr@gmail.com>"]
readme = "README.pypi.md"
Expand Down