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

feature/gra-1023-server-not-respecting-provided-chat_id #778

Merged
merged 2 commits into from
Nov 7, 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: 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 <ian@grai.io>", "Edward Louth <edward@grai.io>"]
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",)
Loading