Skip to content

Commit

Permalink
Merge branch 'development' into feat/2980-required-button
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaBondar authored Jan 24, 2025
2 parents 330b78b + a2bc02a commit 4460949
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 71 deletions.
5 changes: 0 additions & 5 deletions apps/chat-e2e/src/ui/webElements/chatHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
} from '../selectors';
import { BaseElement } from './baseElement';

import { API } from '@/src/testData';
import { Tags } from '@/src/ui/domData';
import { Locator, Page } from '@playwright/test';

Expand Down Expand Up @@ -61,11 +60,7 @@ export class ChatHeader extends BaseElement {
}

async openConversationSettingsPopup() {
const modelsResponsePromise = this.page.waitForResponse(API.modelsHost);
const addonsResponsePromise = this.page.waitForResponse(API.addonsHost);
await this.conversationSettings.click();
await modelsResponsePromise;
await addonsResponsePromise;
}

public async hoverOverChatModel() {
Expand Down
19 changes: 4 additions & 15 deletions apps/chat/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@ import {
import { EntityType } from '@/src/types/common';
import { Translation } from '@/src/types/translation';

import {
AddonsActions,
AddonsSelectors,
} from '@/src/store/addons/addons.reducers';
import { AddonsSelectors } from '@/src/store/addons/addons.reducers';
import { ChatActions } from '@/src/store/chat/chat.reducer';
import { ChatSelectors } from '@/src/store/chat/chat.selectors';
import {
ConversationsActions,
ConversationsSelectors,
} from '@/src/store/conversations/conversations.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import {
ModelsActions,
ModelsSelectors,
} from '@/src/store/models/models.reducers';
import { ModelsSelectors } from '@/src/store/models/models.reducers';
import { PublicationSelectors } from '@/src/store/publication/publication.reducers';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';
Expand Down Expand Up @@ -199,6 +193,7 @@ export const ChatView = memo(() => {
!modelsMap[conv.assistantModelId])
);
}));

if (isNotAllowedModel) {
setNotAllowedType(EntityType.Model);
} else if (
Expand Down Expand Up @@ -595,13 +590,7 @@ export const ChatView = memo(() => {
!isExternal
}
isShowSettings={isShowChatSettings}
setShowSettings={(isShow) => {
if (isShow) {
dispatch(ModelsActions.getModels());
dispatch(AddonsActions.getAddons());
}
setIsShowChatSettings(isShow);
}}
setShowSettings={setIsShowChatSettings}
selectedConversationIds={
selectedConversationsIds
}
Expand Down
60 changes: 37 additions & 23 deletions apps/chat/src/components/Chat/ChatHeader/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import {
getSelectedAddons,
getValidEntitiesFromIds,
} from '@/src/utils/app/conversation';
import {
doesModelAllowAddons,
doesModelAllowSystemPrompt,
doesModelAllowTemperature,
} from '@/src/utils/app/models';

import { Conversation } from '@/src/types/chat';
import { EntityType, ScreenState } from '@/src/types/common';
Expand All @@ -36,6 +41,8 @@ import { PublicationActions } from '@/src/store/publication/publication.reducers
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';

import { FALLBACK_TEMPERATURE } from '@/src/constants/default-ui-settings';

import { ConversationContextMenu } from '@/src/components/Chat/ConversationContextMenu';
import { ConfirmDialog } from '@/src/components/Common/ConfirmDialog';

Expand Down Expand Up @@ -267,6 +274,7 @@ export const ChatHeader = Inversify.register(
</span>
{model ? (
model.type !== EntityType.Application &&
doesModelAllowAddons(model) &&
(conversation.selectedAddons.length > 0 ||
(model.selectedAddons &&
model.selectedAddons.length > 0)) && (
Expand Down Expand Up @@ -309,21 +317,22 @@ export const ChatHeader = Inversify.register(
)
) : (
<>
{conversation.selectedAddons.length > 0 && (
<span
className="flex items-center gap-2"
data-qa="chat-addons"
>
{conversation.selectedAddons.map((addon) => (
<ModelIcon
key={addon}
entityId={addon}
size={iconSize}
entity={addonsMap[addon]}
/>
))}
</span>
)}
{doesModelAllowAddons(model) &&
conversation.selectedAddons.length > 0 && (
<span
className="flex items-center gap-2"
data-qa="chat-addons"
>
{conversation.selectedAddons.map((addon) => (
<ModelIcon
key={addon}
entityId={addon}
size={iconSize}
entity={addonsMap[addon]}
/>
))}
</span>
)}
</>
)}
</>
Expand All @@ -344,22 +353,27 @@ export const ChatHeader = Inversify.register(
: undefined
}
systemPrompt={
model?.type === EntityType.Model
model?.type === EntityType.Model &&
doesModelAllowSystemPrompt(model)
? conversation.prompt
: ''
}
temperature={
model?.type !== EntityType.Application
? conversation.temperature
? doesModelAllowTemperature(model)
? conversation.temperature
: FALLBACK_TEMPERATURE
: null
}
selectedAddons={
model
? selectedAddons
: getValidEntitiesFromIds(
conversation.selectedAddons,
addonsMap,
)
doesModelAllowAddons(model)
? model
? selectedAddons
: getValidEntitiesFromIds(
conversation.selectedAddons,
addonsMap,
)
: null
}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function SettingContainer({ children }: SettingContainerProps) {

function EmptySettings() {
const { t } = useTranslation(Translation.Chat);

return (
<SettingContainer>
<FieldContainer>
Expand Down
10 changes: 9 additions & 1 deletion apps/chat/src/components/Chatbar/ChatFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ export const ChatSection = ({
const [isSectionHighlighted, setIsSectionHighlighted] = useState(false);

const searchTerm = useAppSelector(ConversationsSelectors.selectSearchTerm);
const selectedPublication = useAppSelector(
PublicationSelectors.selectSelectedPublication,
);
const selectFilteredFoldersSelector = useMemo(
() =>
ConversationsSelectors.selectFilteredFolders(
Expand Down Expand Up @@ -405,14 +408,19 @@ export const ChatSection = ({
return null;
}

const isOrganizationAndPublicationSelected =
name === ORGANIZATION_SECTION_NAME && selectedPublication;

return (
<CollapsibleSection
onToggle={handleToggle}
name={name}
openByDefault={openByDefault ?? isExpanded}
isExpanded={isExpanded}
dataQa={dataQa}
isHighlighted={isSectionHighlighted}
isHighlighted={
isOrganizationAndPublicationSelected ? false : isSectionHighlighted
}
>
<div>
{rootFolders.map((folder, index, arr) => {
Expand Down
6 changes: 5 additions & 1 deletion apps/chat/src/components/Folder/Folder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ const Folder = <T extends ConversationInfo | PromptInfo | DialFile>({
const iconSize = additionalItemData?.isSidePanelItem ? 24 : 18;
const folderIconStrokeWidth = additionalItemData?.isSidePanelItem ? 1.5 : 2;
const isSidePanelItem = additionalItemData?.isSidePanelItem;
const isInApproveRequiredSectionOrNot =
(selectedPublicationUrl && additionalItemData?.publicationUrl) ||
(!selectedPublicationUrl && !additionalItemData?.publicationUrl);

return (
<div
Expand Down Expand Up @@ -1105,7 +1108,8 @@ const Folder = <T extends ConversationInfo | PromptInfo | DialFile>({
: highlightedFolders?.includes(currentFolder.id) &&
isPartOfSelectedPublication &&
featureType &&
!canSelectFolders
!canSelectFolders &&
isInApproveRequiredSectionOrNot
? 'text-accent-primary'
: 'text-primary',
)}
Expand Down
12 changes: 4 additions & 8 deletions apps/chat/src/components/Header/User/UserDesktop.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*eslint-disable @next/next/no-img-element*/
import { IconSettings } from '@tabler/icons-react';
import { signIn, signOut, useSession } from 'next-auth/react';
import { useCallback, useState } from 'react';
import { useState } from 'react';

import { useTranslation } from 'next-i18next';

import { useLogout } from '@/src/hooks/useLogout';

import { Translation } from '@/src/types/translation';

import { useAppDispatch } from '@/src/store/hooks';
Expand All @@ -24,13 +25,8 @@ export const UserDesktop = Inversify.register('UserDesktop', () => {
const [isOpen, setIsOpen] = useState(false);
const [isLogoutConfirmationOpened, setIsLogoutConfirmationOpened] =
useState(false);
const { data: session } = useSession();
const { session, handleLogout } = useLogout();
const dispatch = useAppDispatch();
const handleLogout = useCallback(() => {
session
? signOut({ redirect: true })
: signIn('azure-ad', { redirect: true });
}, [session]);

return (
<>
Expand Down
11 changes: 4 additions & 7 deletions apps/chat/src/components/Header/User/UserMobile.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*eslint-disable @next/next/no-img-element*/
import { IconSettings } from '@tabler/icons-react';
import { signIn, signOut, useSession } from 'next-auth/react';
import { useSession } from 'next-auth/react';
import { useCallback, useState } from 'react';

import { useTranslation } from 'next-i18next';

import classNames from 'classnames';

import { useLogout } from '@/src/hooks/useLogout';

import { Translation } from '@/src/types/translation';

import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
Expand Down Expand Up @@ -70,16 +72,11 @@ const UserSettings = () => {
};

const Logout = () => {
const { data: session } = useSession();
const { session, handleLogout } = useLogout();
const { t } = useTranslation(Translation.Header);
const [isLogoutConfirmationOpened, setIsLogoutConfirmationOpened] =
useState(false);

const handleLogout = useCallback(() => {
session
? signOut({ redirect: true })
: signIn('azure-ad', { redirect: true });
}, [session]);
return (
<>
<div
Expand Down
10 changes: 9 additions & 1 deletion apps/chat/src/components/Promptbar/components/PromptFolders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,9 @@ const _PromptSection = ({
const [isSectionHighlighted, setIsSectionHighlighted] = useState(false);

const searchTerm = useAppSelector(PromptsSelectors.selectSearchTerm);
const selectedPublication = useAppSelector(
PublicationSelectors.selectSelectedPublication,
);

const filteredPromptsSelector = useMemo(
() => PromptsSelectors.selectFilteredPrompts(filters, searchTerm),
Expand Down Expand Up @@ -386,14 +389,19 @@ const _PromptSection = ({
return null;
}

const isOrganizationAndPublicationSelected =
name === ORGANIZATION_SECTION_NAME && selectedPublication;

return (
<CollapsibleSection
onToggle={handleToggle}
name={name}
openByDefault={openByDefault ?? isExpanded}
isExpanded={isExpanded}
dataQa={dataQa}
isHighlighted={isSectionHighlighted}
isHighlighted={
isOrganizationAndPublicationSelected ? false : isSectionHighlighted
}
>
<div>
{rootFolders.map((folder, index, arr) => (
Expand Down
8 changes: 5 additions & 3 deletions apps/chat/src/constants/default-ui-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const FALLBACK_ASSISTANT_SUBMODEL_ID = 'gpt-4';

export const MAX_ENTITY_LENGTH = 160;

export const DEFAULT_TEMPERATURE = parseFloat(
process.env.NEXT_PUBLIC_DEFAULT_TEMPERATURE ?? '1',
);
export const FALLBACK_TEMPERATURE = 1;

export const DEFAULT_TEMPERATURE = process.env.NEXT_PUBLIC_DEFAULT_TEMPERATURE
? parseFloat(process.env.NEXT_PUBLIC_DEFAULT_TEMPERATURE)
: FALLBACK_TEMPERATURE;
15 changes: 15 additions & 0 deletions apps/chat/src/hooks/useLogout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { signIn, signOut, useSession } from 'next-auth/react';
import { useCallback } from 'react';

export const useLogout = () => {
const { data: session } = useSession();
const handleLogout = useCallback(() => {
session
? signOut({ redirect: true, callbackUrl: '/' })
: signIn('azure-ad', { redirect: true });
}, [session]);
return {
session,
handleLogout,
};
};
7 changes: 5 additions & 2 deletions apps/chat/src/pages/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import { ChatBody } from '@/src/types/chat';
import { EntityType } from '@/src/types/common';

import { DEFAULT_SYSTEM_PROMPT } from '@/src/constants/default-server-settings';
import { DEFAULT_TEMPERATURE } from '@/src/constants/default-ui-settings';
import {
DEFAULT_TEMPERATURE,
FALLBACK_TEMPERATURE,
} from '@/src/constants/default-ui-settings';
import { errorsMessages } from '@/src/constants/errors';

import { authOptions } from './auth/[...nextauth]';
Expand Down Expand Up @@ -65,7 +68,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {

let temperatureToUse = temperature;
if (!doesModelAllowTemperature(model)) {
temperatureToUse = 1;
temperatureToUse = FALLBACK_TEMPERATURE;
} else if (
!temperatureToUse &&
temperatureToUse !== 0 &&
Expand Down
Loading

0 comments on commit 4460949

Please sign in to comment.