Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display row number in the UI if present #46

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions llm-service/app/routers/index/data_source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import logging
import tempfile
from typing import Any, Dict

from fastapi import APIRouter, Depends
from fastapi_utils.cbv import cbv
Expand Down Expand Up @@ -65,6 +66,11 @@ class RagIndexDocumentRequest(BaseModel):
configuration: RagIndexDocumentConfiguration = RagIndexDocumentConfiguration()


class ChunkContentsResponse(BaseModel):
text: str
metadata: Dict[str, Any]


@cbv(router)
class DataSourceController:
chunks_vector_store: VectorStore = Depends(
Expand All @@ -86,11 +92,11 @@ def size(self) -> int:
response_model=None,
)
@exceptions.propagates
def chunk_contents(self, chunk_id: str) -> str:
return (
self.chunks_vector_store.llama_vector_store()
.get_nodes([chunk_id])[0]
.get_content()
def chunk_contents(self, chunk_id: str) -> ChunkContentsResponse:
node = self.chunks_vector_store.llama_vector_store().get_nodes([chunk_id])[0]
return ChunkContentsResponse(
text=node.get_content(),
metadata=node.metadata,
)

@router.delete(
Expand Down
9 changes: 6 additions & 3 deletions ui/src/api/ragQueryApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
******************************************************************************/

import { useMutation, useQuery } from "@tanstack/react-query";
import { QueryConfiguration } from "src/api/chatApi.ts";
import {
getRequest,
llmServicePath,
MutationKeys,
postRequest,
QueryKeys,
} from "src/api/utils.ts";
import { QueryConfiguration } from "src/api/chatApi.ts";

export interface RagMessage {
role: "user" | "assistant";
Expand Down Expand Up @@ -94,7 +94,10 @@ const suggestQuestionsQuery = async (
);
};

type ChunkContents = string;
interface ChunkContentsResponse {
text: string;
metadata: Record<string, string | number>;
}

interface ChunkContentsRequest {
data_source_id: string;
Expand All @@ -110,7 +113,7 @@ export const useGetChunkContents = () => {

const getChunkContents = async (
request: ChunkContentsRequest,
): Promise<ChunkContents> => {
): Promise<ChunkContentsResponse> => {
return getRequest(
`${llmServicePath}/data_sources/${request.data_source_id}/chunks/${request.chunk_id}`,
);
Expand Down
40 changes: 26 additions & 14 deletions ui/src/pages/RagChatTab/ChatOutput/Sources/SourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
* DATA.
******************************************************************************/

import { useGetChunkContents } from "src/api/ragQueryApi.ts";
import { useContext, useState } from "react";
import { RagChatContext } from "pages/RagChatTab/State/RagChatContext.tsx";
import Icon from "@ant-design/icons";
import {
Alert,
Card,
Expand All @@ -49,10 +47,12 @@ import {
Tooltip,
Typography,
} from "antd";
import { RagChatContext } from "pages/RagChatTab/State/RagChatContext.tsx";
import { useContext, useState } from "react";
import { SourceNode } from "src/api/chatApi.ts";
import { useGetChunkContents } from "src/api/ragQueryApi.ts";
import { useGetDocumentSummary } from "src/api/summaryApi.ts";
import DocumentationIcon from "src/cuix/icons/DocumentationIcon";
import Icon from "@ant-design/icons";
import { cdlGray600 } from "src/cuix/variables.ts";

export const SourceCard = ({ source }: { source: SourceNode }) => {
Expand Down Expand Up @@ -122,16 +122,28 @@ export const SourceCard = ({ source }: { source: SourceNode }) => {
</div>
</Flex>
) : (
<Flex vertical>
<Typography.Title level={5} style={{ marginTop: 10 }}>
Extracted reference content
</Typography.Title>
<Typography.Paragraph
style={{ textAlign: "left", whiteSpace: "pre-wrap" }}
>
{chunkContents.data}
</Typography.Paragraph>
</Flex>
chunkContents.data && (
<Flex vertical>
<Typography.Title level={5} style={{ marginTop: 10 }}>
Extracted reference content
</Typography.Title>
<Typography.Paragraph
style={{ textAlign: "left", whiteSpace: "pre-wrap" }}
>
{chunkContents.data.text}
</Typography.Paragraph>
{chunkContents.data.metadata.row_number && (
<>
<Typography.Title level={5} style={{ marginTop: 0 }}>
Metadata
</Typography.Title>
<Typography.Text>
Row number: {chunkContents.data.metadata.row_number}
</Typography.Text>
</>
)}
</Flex>
)
)}
</Flex>
</Card>
Expand Down
Loading