Skip to content

Commit

Permalink
fix(chat): retrieve same level entities when call tryCreate and check…
Browse files Browse the repository at this point in the history
… only same level entities (Issue #265) (#677)
  • Loading branch information
Alexander-Kezik authored Feb 13, 2024
1 parent 6a2eb34 commit 4582175
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions apps/chat/src/utils/app/data/storages/api-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@ export class ApiStorage implements DialStorage {
'messages' in entity
? DEFAULT_CONVERSATION_NAME
: DEFAULT_PROMPT_NAME;
const newName = generateNextName(defaultName, entity.name, [
...entities,
]);
const newName = generateNextName(
defaultName,
entity.name,
entities.filter(
(e) =>
e.folderId === entity.folderId ||
(!e.folderId && !entity.folderId),
),
);
const updatedEntity = {
...entity,
id: constructPath(entity.folderId, newName),
Expand Down Expand Up @@ -117,12 +123,12 @@ export class ApiStorage implements DialStorage {
}

setConversations(conversations: Conversation[]): Observable<void> {
return this.getConversations().pipe(
concatMap((apiConversations) =>
from(conversations).pipe(
concatMap((conversation) =>
return from(conversations).pipe(
concatMap((conv) =>
this.getConversations(conv.folderId).pipe(
concatMap((apiConversations) =>
this.tryCreateEntity(
conversation,
conv,
[...conversations, ...apiConversations],
this._conversationApiStorage,
),
Expand Down Expand Up @@ -159,10 +165,10 @@ export class ApiStorage implements DialStorage {
}

setPrompts(prompts: Prompt[]): Observable<void> {
return this.getPrompts().pipe(
concatMap((apiPrompts) =>
from(prompts).pipe(
concatMap((prompt) =>
return from(prompts).pipe(
concatMap((prompt) =>
this.getPrompts(prompt.folderId).pipe(
concatMap((apiPrompts) =>
this.tryCreateEntity(
prompt,
[...prompts, ...apiPrompts],
Expand Down

0 comments on commit 4582175

Please sign in to comment.