Skip to content

Commit

Permalink
Ah this is how you json serialize an enum
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Oct 27, 2024
1 parent 9340d35 commit dcda542
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/chap/backends/textgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ async def aask(
full_prompt = session + [User(query)]
del full_prompt[1:-max_query_size]
new_data = old_data = full_query = "\n".join(
f"{role_map.get(q.role,'')}{q.content}\n" for q in full_prompt
) + f"\n{role_map.get('assistant')}"
f"{role_map.get(q.role,)}{q.content}\n" for q in full_prompt
) + f"\n{role_map.get(Role.ASSISTANT)}"
try:
async with websockets.connect(
f"ws://{self.parameters.server_hostname}:7860/queue/join"
Expand Down
6 changes: 3 additions & 3 deletions src/chap/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

import enum
import json
import pathlib
from dataclasses import asdict, dataclass
Expand All @@ -12,8 +13,7 @@
from typing_extensions import TypedDict


# not an enum.Enum because these objects are not json-serializable, sigh
class Role:
class Role(str, enum.Enum):
ASSISTANT = "assistant"
SYSTEM = "system"
USER = "user"
Expand All @@ -23,7 +23,7 @@ class Role:
class Message:
"""Represents one Message within a chap Session"""

role: str
role: Role
content: str


Expand Down

0 comments on commit dcda542

Please sign in to comment.