Skip to content

Commit

Permalink
🎨 feat: Title Improvements (#2363)
Browse files Browse the repository at this point in the history
* fix(assistants): keep generated title upon continued messages in active conversation

* feat: update document.title on successful gentitle mutation
  • Loading branch information
danny-avila authored Apr 9, 2024
1 parent 6f0eb35 commit cc71125
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 0 additions & 1 deletion api/server/middleware/abortRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ async function abortRun(req, res) {
});

const finalEvent = {
title: 'New Chat',
final: true,
conversation,
runMessages,
Expand Down
3 changes: 0 additions & 3 deletions api/server/routes/assistants/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ router.post('/', validateModel, buildEndpointOption, setHeaders, async (req, res
}

finalEvent = {
title: 'New Chat',
final: true,
conversation: await getConvo(req.user.id, conversationId),
runMessages,
Expand Down Expand Up @@ -477,7 +476,6 @@ router.post('/', validateModel, buildEndpointOption, setHeaders, async (req, res

conversation = {
conversationId,
title: 'New Chat',
endpoint: EModelEndpoint.assistants,
promptPrefix: promptPrefix,
instructions: instructions,
Expand Down Expand Up @@ -607,7 +605,6 @@ router.post('/', validateModel, buildEndpointOption, setHeaders, async (req, res
};

sendMessage(res, {
title: 'New Chat',
final: true,
conversation,
requestMessage: {
Expand Down
1 change: 1 addition & 0 deletions client/src/data-provider/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const useGenTitleMutation = (): UseMutationResult<
title: response.title,
} as TConversation);
});
document.title = response.title;
},
});
};
Expand Down
9 changes: 9 additions & 0 deletions client/src/hooks/SSE/useSSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,19 @@ export default function useSSE(submission: TSubmission | null, index = 0) {

let update = {} as TConversation;
setConversation((prevState) => {
let title = prevState?.title;
const parentId = requestMessage.parentMessageId;
if (parentId !== Constants.NO_PARENT && title?.toLowerCase()?.includes('new chat')) {
const convos = queryClient.getQueryData<ConversationData>([QueryKeys.allConversations]);
const cachedConvo = getConversationById(convos, conversationId);
title = cachedConvo?.title;
}

update = tConvoUpdateSchema.parse({
...prevState,
conversationId,
thread_id,
title,
messages: [requestMessage.messageId, responseMessage.messageId],
}) as TConversation;

Expand Down

0 comments on commit cc71125

Please sign in to comment.