Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/duplicate-shared-prompt' in…
Browse files Browse the repository at this point in the history
…to feat/duplicate-shared-prompt
  • Loading branch information
irinakartun committed Sep 10, 2024
2 parents a157ca6 + 5f71410 commit cca805e
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 79 deletions.
89 changes: 47 additions & 42 deletions apps/chat/src/components/Chat/ModelList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,48 +219,50 @@ const ModelGroup = ({
entity={currentEntity}
size={24}
/>
<div className="flex w-full flex-col gap-1 text-left">
<div className="flex items-center justify-between">
<span data-qa="group-entity-name" className="whitespace-pre">
{entities.length === 1
? getOpenAIEntityFullName(currentEntity)
: currentEntity.name}
</span>
<div className="flex items-center gap-2">
<ModelVersionSelect
className="h-max"
entities={entities}
onSelect={onSelect}
currentEntity={currentEntity}
/>
{isCustomApplicationsEnabled &&
isApplicationId(currentEntity.id) && (
<ContextMenu
menuItems={menuItems}
TriggerIcon={IconDots}
triggerIconSize={18}
className="m-0 justify-self-end"
featureType={FeatureType.Chat}
onOpenChange={() => openApplicationModal}
/>
)}
<div className="flex w-full overflow-hidden">
<div className="flex w-full flex-wrap">
<div className="flex w-full items-center gap-2">
<span data-qa="group-entity-name" className="w-full truncate">
{entities.length === 1
? getOpenAIEntityFullName(currentEntity)
: currentEntity.name}
</span>
<div className="flex items-center gap-2">
<ModelVersionSelect
className="h-max"
entities={entities}
onSelect={onSelect}
currentEntity={currentEntity}
/>
{isCustomApplicationsEnabled &&
isApplicationId(currentEntity.id) && (
<ContextMenu
menuItems={menuItems}
TriggerIcon={IconDots}
triggerIconSize={18}
className="m-0 justify-self-end"
featureType={FeatureType.Chat}
onOpenChange={() => openApplicationModal}
/>
)}
</div>
</div>
{description && (
<span
className="text-secondary"
onClick={(e) => {
if ((e.target as HTMLAnchorElement)?.tagName === 'A') {
e.stopPropagation();
}
}}
data-qa="group-entity-descr"
>
<EntityMarkdownDescription isShortDescription={!isOpened}>
{description}
</EntityMarkdownDescription>
</span>
)}
</div>
{description && (
<span
className="text-secondary"
onClick={(e) => {
if ((e.target as HTMLAnchorElement)?.tagName === 'A') {
e.stopPropagation();
}
}}
data-qa="group-entity-descr"
>
<EntityMarkdownDescription isShortDescription={!isOpened}>
{description}
</EntityMarkdownDescription>
</span>
)}
</div>
{!notAllowExpandDescription &&
description &&
Expand Down Expand Up @@ -366,7 +368,7 @@ export const ModelList = ({

const modelsMapKeys = Object.keys(modelsMap);

onSelect(recentModelsIds[1] ?? modelsMap[modelsMapKeys[0]]);
onSelect(recentModelsIds[1] ?? modelsMap[modelsMapKeys[0]]?.reference);
selectedConversations.forEach((conv) => {
if (
conv.model.id === currentEntity?.reference ||
Expand All @@ -376,7 +378,10 @@ export const ModelList = ({
ConversationsActions.updateConversation({
id: conv.id,
values: {
model: { id: recentModelsIds[1] ?? modelsMap[modelsMapKeys[0]] },
model: {
id:
recentModelsIds[1] ?? modelsMap[modelsMapKeys[0]]?.reference,
},
},
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,17 @@ export function ReviewApplicationDialogView() {
<span className="w-[122px] text-secondary">
{t('Features data:')}
</span>
<div className="flex flex-col justify-start">
<div className="flex flex-col justify-start break-all">
{'{'}
<pre className="flex max-w-[414px] flex-wrap leading-5 text-primary">
<br />
<div className="max-w-[414px] whitespace-pre-wrap leading-5 text-primary">
{Object.entries(application?.features || {}).map(
([key, value]) => (
([key, value], index, array) => (
<Fragment key={key}>
<span>{key}</span> <span>{value}</span>
<br />
{`"${key}" : "${value}"${index !== array.length - 1 ? ',\n' : ''}`}
</Fragment>
),
)}
</pre>
</div>
{'}'}
</div>
</div>
Expand Down Expand Up @@ -119,7 +117,7 @@ export function ReviewApplicationDialogView() {
<span className="w-[122px] text-secondary">
{t('Completion URL:')}
</span>
<span className="max-w-[414px] text-primary">
<span className="max-w-[414px] break-all text-primary">
{application?.completionUrl}
</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Common/ApplicationDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ const ApplicationDialogView: React.FC<Props> = ({
className="mb-1 flex text-xs text-secondary"
htmlFor="maxInputAttachments"
>
{t('Max attachments')}
{t('Max. attachments number')}
</label>
<input
{...register('maxInputAttachments', {
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/store/conversations/conversations.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ const createNewConversationsEpic: AppEpic = (action$, state$) =>
),
messages: [],
model: {
id: model.id,
id: model.reference,
},
prompt: DEFAULT_SYSTEM_PROMPT,
temperature:
Expand Down
11 changes: 7 additions & 4 deletions apps/chat/src/store/overlay/overlay.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,19 @@ const setOverlayOptionsEpic: AppEpic = (action$, state$) =>
if (currentConversation) {
const models = ModelsSelectors.selectModels(state$.value);

const newAiEntity = models.find(({ id }) => id === finalModelId) as
| DialAIEntityModel
| undefined;
const newAiEntity = models.find(
({ reference, id }) =>
id === finalModelId || reference === finalModelId,
) as DialAIEntityModel | undefined;

actions.push(
of(
ConversationsActions.updateConversation({
id: currentConversation.id,
values: {
model: { id: finalModelId },
model: {
id: newAiEntity?.reference ?? finalModelId,
},
},
}),
),
Expand Down
51 changes: 28 additions & 23 deletions apps/chat/src/utils/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,7 @@ export const OpenAIStream = async ({
body,
});

if (
res.status === 400 &&
retries === 0 &&
model.limits?.isMaxRequestTokensCustom
) {
retries += 1;
const json = await res.json();
logger.info(
json,
`Getting 400 error and retrying chat request to ${model.id} model`,
);
messagesToSend = hardLimitMessages(messagesToSend);
continue;
} else if (res.status !== 200) {
if (res.status !== 200) {
let result: DialAIErrorResponse;
try {
result = (await res.json()) as DialAIErrorResponse;
Expand All @@ -134,19 +121,37 @@ export const OpenAIStream = async ({
);
}

if (result.error) {
throw new DialAIError(
result.error.message ?? '',
result.error.type ?? '',
result.error.param ?? '',
result.error.code ?? res.status.toString(10),
result.error.display_message,
);
} else {
if (!result.error) {
throw new Error(
`Core API returned an error: ${JSON.stringify(result, null, 2)}`,
);
}

const dial_error = new DialAIError(
result.error.message ?? '',
result.error.type ?? '',
result.error.param ?? '',
result.error.code ?? res.status.toString(10),
result.error.display_message,
);

if (
res.status === 400 &&
dial_error.code === 'truncate_prompt_error' &&
retries === 0 &&
model.limits?.isMaxRequestTokensCustom
) {
retries += 1;
const json = await res.json();
logger.info(
json,
`Getting error with status ${res.status} and code '${dial_error.code}'. Retrying chat request to ${model.id} model`,
);
messagesToSend = hardLimitMessages(messagesToSend);
continue;
}

throw dial_error;
}

break;
Expand Down

0 comments on commit cca805e

Please sign in to comment.