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 1 commit
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 @@
);
};

type ChunkContents = string;
interface ChunkContentsResponse {
text: string;
metadata: Record<string, any>;

Check failure on line 99 in ui/src/api/ragQueryApi.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just string or string | number?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can start with that

}

interface ChunkContentsRequest {
data_source_id: string;
Expand All @@ -110,7 +113,7 @@

const getChunkContents = async (
request: ChunkContentsRequest,
): Promise<ChunkContents> => {
): Promise<ChunkContentsResponse> => {
return getRequest(
`${llmServicePath}/data_sources/${request.data_source_id}/chunks/${request.chunk_id}`,
);
Expand Down
20 changes: 15 additions & 5 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 @@
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 @@ -129,8 +129,18 @@
<Typography.Paragraph
style={{ textAlign: "left", whiteSpace: "pre-wrap" }}
>
{chunkContents.data}
{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}

Check failure on line 140 in ui/src/pages/RagChatTab/ChatOutput/Sources/SourceCard.tsx

View workflow job for this annotation

GitHub Actions / build

Unnecessary optional chain on a non-nullish value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check on line 134 means we know data exists.

Suggested change
Row number: {chunkContents.data?.metadata.row_number}
Row number: {chunkContents.data.metadata.row_number}

</Typography.Text>
</>
) : null}
</Flex>
)}
</Flex>
Expand Down
Loading