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

Allow for setting a ChatProfile default #930

Merged
merged 1 commit into from
Apr 23, 2024
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
20 changes: 19 additions & 1 deletion backend/chainlit/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -37,6 +49,7 @@ class ThreadFilter(BaseModel):
userId: Optional[str] = None
search: Optional[str] = None


@dataclass
class PageInfo:
hasNextPage: bool
Expand All @@ -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
Expand All @@ -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]]]
Expand Down Expand Up @@ -196,6 +213,7 @@ class ChatProfile(DataClassJsonMixin):
name: str
markdown_description: str
icon: Optional[str] = None
default: bool = False


FeedbackStrategy = Literal["BINARY"]
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions frontend/src/state/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading