Skip to content

Commit

Permalink
feature/gra-1023-server-not-respecting-provided-chat_id (#778)
Browse files Browse the repository at this point in the history
* updated chat_id typing & cache fixes
  • Loading branch information
ieaves authored Nov 7, 2023
1 parent 34049f8 commit f185d1b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions grai-server/app/grAI/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from grAI.websocket_payloads import ChatErrorMessages, ChatEvent
from users.models import User
from workspaces.models import Membership
import logging
from uuid import UUID


class ChatConsumer(WebsocketConsumer):
Expand All @@ -23,8 +25,8 @@ class ChatConsumer(WebsocketConsumer):
"""

def __init__(self, *args, **kwargs):
self.conversations: dict[str, BaseConversation] = {}
self.active_chats: set = set()
self.conversations: dict[UUID, BaseConversation] = {}
self.active_chats: set[UUID] = set()
super().__init__(*args, **kwargs)

@cached_property
Expand Down Expand Up @@ -58,7 +60,6 @@ def disconnect(self, close_code):
def receive(self, text_data):
data: dict = json.loads(text_data)
socket_message_type = data.get("type", None)

match socket_message_type:
case "chat.message":
self.chat_message(data)
Expand Down
8 changes: 4 additions & 4 deletions grai-server/app/grAI/websocket_payloads.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from enum import Enum
from typing import Literal

from typing import Literal, Annotated
from uuid import UUID
from pydantic import BaseModel, ValidationError, validator


Expand All @@ -18,8 +18,8 @@ class ChatErrorMessages(Enum):
class ChatEvent(BaseModel):
type: Literal["chat.message"] = "chat.message"
message: str
chat_id: str
chat_id: UUID

@validator("chat_id")
def chat_id_is_uuid(cls, v):
return v if v == "" else str(uuid.uuid4())
return uuid.uuid4() if v == "" else v
2 changes: 1 addition & 1 deletion grai-server/app/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "the_guide"
version = "0.1.48"
version = "0.1.49"
description = ""
authors = ["Ian Eaves <[email protected]>", "Edward Louth <[email protected]>"]
license = "Elastic-2.0"
Expand Down
2 changes: 1 addition & 1 deletion grai-server/app/the_guide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__version__ = "0.1.48"
__version__ = "0.1.49"
__all__ = ("celery_app",)

0 comments on commit f185d1b

Please sign in to comment.