Skip to content

Commit

Permalink
feat: return the document source to chat message (#187)
Browse files Browse the repository at this point in the history
* feat: return the document source to chat message

* feat: remove logs
  • Loading branch information
romansharapov19 authored Sep 21, 2023
1 parent dafccaf commit e6d9b39
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/api/src/chats/chat-socket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export class ChatSocketGateway {
id: data.id,
response: aiResponse.output,
isAi: true,
...(aiResponse.document
? {
source: {
filename: aiResponse.document,
snippets: aiResponse.source.map((source) => source.pageContent),
},
}
: {}),
createdAt: new Date().toISOString(),
})
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SourceMeta } from '@/common/types/chat';
import { SocketMessageResponseDto } from '@/contract/chats/socket-message.response.dto';

interface CreateSocketMessageResponseFactoryType {
Expand All @@ -6,19 +7,22 @@ interface CreateSocketMessageResponseFactoryType {
isAi: boolean;
createdAt: string;
userId?: string;
source?: SourceMeta;
}
export const createSocketMessageResponseFactory = ({
id,
response,
isAi,
createdAt,
userId,
source,
}: CreateSocketMessageResponseFactoryType): SocketMessageResponseDto => {
return {
id,
response,
isAi,
createdAt,
userId,
source,
};
};
1 change: 1 addition & 0 deletions packages/contract/chats/socket-message.response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export interface SocketMessageResponseDto {
response: string;
isAi: boolean;
userId?: string;
source?: { filename: string; snippets: string[] };
createdAt: string;
}
2 changes: 2 additions & 0 deletions packages/web-ui/factory/create-chat.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const createChatMessageFactory = (
id: message.id,
content: message.content,
response: aiMessage?.content,
source: aiMessage?.meta?.source,
createdAt: message.createdAt,
user,
};
Expand Down Expand Up @@ -65,6 +66,7 @@ export const createChatMessagesWithResponseFactory = (
id: message.id,
content: message.content,
response: response.response,
source: response.source,
createdAt: message.createdAt,
user: message.user,
};
Expand Down
6 changes: 6 additions & 0 deletions packages/web-ui/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export interface ChatMessageType {
content: string;
response?: string;
user?: ChatUserType;
source?: ChatMessageSourceType;
createdAt: string;
}

Expand All @@ -20,3 +21,8 @@ export interface SocketMessageType {
content: string;
userId: string;
}

export interface ChatMessageSourceType {
filename: string;
snippets: string[];
}

0 comments on commit e6d9b39

Please sign in to comment.