From dc4b0b07a2c88b4f697b2d72b554bd82d87fc899 Mon Sep 17 00:00:00 2001 From: Kevin Merritt Date: Mon, 22 Apr 2024 22:03:25 -0400 Subject: [PATCH] control ChatProfile default --- backend/chainlit/types.py | 20 +++++++++++++++++++- frontend/src/App.tsx | 11 +++++++++-- frontend/src/state/project.ts | 1 + 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/backend/chainlit/types.py b/backend/chainlit/types.py index 912fb9b021..27e16bd2a2 100644 --- a/backend/chainlit/types.py +++ b/backend/chainlit/types.py @@ -1,5 +1,17 @@ from enum import Enum -from typing import TYPE_CHECKING, Dict, List, Literal, Optional, TypedDict, Union, Generic, TypeVar, Protocol, Any +from typing import ( + TYPE_CHECKING, + Any, + Dict, + Generic, + List, + Literal, + Optional, + Protocol, + TypedDict, + TypeVar, + Union, +) if TYPE_CHECKING: from chainlit.element import ElementDict @@ -37,6 +49,7 @@ class ThreadFilter(BaseModel): userId: Optional[str] = None search: Optional[str] = None + @dataclass class PageInfo: hasNextPage: bool @@ -59,13 +72,16 @@ def from_dict(cls, page_info_dict: Dict) -> "PageInfo": hasNextPage=hasNextPage, startCursor=startCursor, endCursor=endCursor ) + T = TypeVar("T", covariant=True) + class HasFromDict(Protocol[T]): @classmethod def from_dict(cls, obj_dict: Any) -> T: raise NotImplementedError() + @dataclass class PaginatedResponse(Generic[T]): pageInfo: PageInfo @@ -90,6 +106,7 @@ def from_dict( return cls(pageInfo=pageInfo, data=data) + @dataclass class FileSpec(DataClassJsonMixin): accept: Union[List[str], Dict[str, List[str]]] @@ -196,6 +213,7 @@ class ChatProfile(DataClassJsonMixin): name: str markdown_description: str icon: Optional[str] = None + default: bool = False FeedbackStrategy = Literal["BINARY"] diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 59b7753cfd..03426c4946 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -100,8 +100,15 @@ function App() { }, [userEnv, accessToken, isAuthenticated, connect, chatProfileOk]); if (pSettingsLoaded && pSettings.chatProfiles.length && !chatProfile) { - // Autoselect the chat profile if there is only one - setChatProfile(pSettings.chatProfiles[0].name); + // Autoselect the first default chat profile + const defaultChatProfile = pSettings.chatProfiles.find( + (profile) => profile.default + ); + if (defaultChatProfile) { + setChatProfile(defaultChatProfile.name); + } else { + setChatProfile(pSettings.chatProfiles[0].name); + } } return ( diff --git a/frontend/src/state/project.ts b/frontend/src/state/project.ts index 7d42fa780b..23cdb31aff 100644 --- a/frontend/src/state/project.ts +++ b/frontend/src/state/project.ts @@ -3,6 +3,7 @@ import { atom } from 'recoil'; import { IStep } from '@chainlit/react-client'; export interface ChatProfile { + default: boolean; icon: string; name: string; markdown_description: string;