Skip to content

Commit

Permalink
cleanup: remove ChunkMetadataWithFileData struct
Browse files Browse the repository at this point in the history
  • Loading branch information
skeptrunedev committed Apr 9, 2024
1 parent c79aad1 commit 1f6c09b
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 264 deletions.
4 changes: 2 additions & 2 deletions search/src/components/BookmarkPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
isChunkGroupPageDTO,
type ChunkBookmarksDTO,
type ChunkGroupDTO,
type ChunkMetadataWithFileData,
type ChunkMetadata,
} from "../../utils/apiTypes";
import InputRowsForm from "./Atoms/InputRowsForm";
import { VsBookmark } from "solid-icons/vs";
Expand All @@ -27,7 +27,7 @@ import { A } from "@solidjs/router";
import { DatasetAndUserContext } from "./Contexts/DatasetAndUserContext";

export interface BookmarkPopoverProps {
chunkMetadata: ChunkMetadataWithFileData;
chunkMetadata: ChunkMetadata;
chunkGroups: ChunkGroupDTO[];
totalGroupPages: number;
setLoginModal?: Setter<boolean>;
Expand Down
4 changes: 2 additions & 2 deletions search/src/components/ChunkMetadataDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
indirectHasOwnProperty,
type ChunkBookmarksDTO,
type ChunkGroupDTO,
ChunkMetadataWithFileData,
ChunkMetadata,
} from "../../utils/apiTypes";
import { BiRegularChevronDown, BiRegularChevronUp } from "solid-icons/bi";
import sanitizeHtml from "sanitize-html";
Expand Down Expand Up @@ -48,7 +48,7 @@ export interface ChunkMetadataDisplayProps {
totalGroupPages: number;
signedInUserId?: string;
viewingUserId?: string;
chunk: ChunkMetadataWithFileData;
chunk: ChunkMetadata;
chunkGroups: ChunkGroupDTO[];
bookmarks: ChunkBookmarksDTO[];
setShowConfirmModal: Setter<boolean>;
Expand Down
4 changes: 2 additions & 2 deletions search/src/components/EditChunkPageForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JSX, Show, createEffect, createSignal, useContext } from "solid-js";
import {
ChunkMetadataWithFileData,
ChunkMetadata,
isActixChunkUpdateError,
} from "../../utils/apiTypes";
import { FullScreenModal } from "./Atoms/FullScreenModal";
Expand Down Expand Up @@ -143,7 +143,7 @@ export const EditChunkPageForm = (props: SingleChunkPageProps) => {
credentials: "include",
}).then((response) => {
if (response.ok) {
void response.json().then((data: ChunkMetadataWithFileData) => {
void response.json().then((data: ChunkMetadata) => {
setEvidenceLink(data.link ?? "");
setTagSet(data.tag_set ?? "");
setMetadata(data.metadata);
Expand Down
10 changes: 5 additions & 5 deletions search/src/components/GroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ChunkGroupSearchDTO,
isScoreChunkDTO,
isChunkGroupPageDTO,
ChunkMetadataWithFileData,
ChunkMetadata,
ChunkBookmarksDTO,
} from "../../utils/apiTypes";
import { FullScreenModal } from "./Atoms/FullScreenModal";
Expand Down Expand Up @@ -55,7 +55,7 @@ export const GroupPage = (props: GroupPageProps) => {
const [filters, setFilters] = createSignal<Filters | undefined>(undefined);
const [searchLoading, setSearchLoading] = createSignal(false);
const [chunkMetadatas, setChunkMetadatas] = createSignal<
ChunkMetadataWithFileData[]
ChunkMetadata[]
>([]);
const [searchMetadatasWithVotes, setSearchMetadatasWithVotes] = createSignal<
ScoreChunkDTO[]
Expand All @@ -74,7 +74,7 @@ export const GroupPage = (props: GroupPageProps) => {
const [loadingRecommendations, setLoadingRecommendations] =
createSignal(false);
const [recommendedChunks, setRecommendedChunks] = createSignal<
ChunkMetadataWithFileData[]
ChunkMetadata[]
>([]);
const [showConfirmDeleteModal, setShowConfirmDeleteModal] =
createSignal(false);
Expand Down Expand Up @@ -328,7 +328,7 @@ export const GroupPage = (props: GroupPageProps) => {

const fetchRecommendations = (
ids: string[],
prev_recommendations: ChunkMetadataWithFileData[],
prev_recommendations: ChunkMetadata[],
) => {
const currentDataset = $dataset?.();
if (!currentDataset) return;
Expand All @@ -348,7 +348,7 @@ export const GroupPage = (props: GroupPageProps) => {
}).then((response) => {
if (response.ok) {
void response.json().then((data) => {
const typed_data = data as ChunkMetadataWithFileData[];
const typed_data = data as ChunkMetadata[];
const deduped_data = typed_data.filter((d) => {
return !prev_recommendations.some((c) => c.id == d.id);
});
Expand Down
4 changes: 2 additions & 2 deletions search/src/components/ScoreChunk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from "solid-js";
import {
ChunkBookmarksDTO,
ChunkMetadataWithFileData,
ChunkMetadata,
indirectHasOwnProperty,
type ChunkGroupDTO,
} from "../../utils/apiTypes";
Expand Down Expand Up @@ -63,7 +63,7 @@ export interface ScoreChunkProps {
chunkGroups?: ChunkGroupDTO[];
totalGroupPages?: number;
group?: boolean;
chunk: ChunkMetadataWithFileData;
chunk: ChunkMetadata;
score: number;
setShowModal?: Setter<boolean>;
setOnDelete?: Setter<() => void>;
Expand Down
4 changes: 2 additions & 2 deletions search/src/components/ScoreChunkArray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Show, createSignal, onMount, useContext } from "solid-js";
import {
indirectHasOwnProperty,
type ChunkGroupDTO,
type ChunkMetadataWithFileData,
type ChunkMetadata,
} from "../../utils/apiTypes";
import type { ScoreChunkProps } from "./ScoreChunk";
import { FiChevronLeft, FiChevronRight } from "solid-icons/fi";
Expand All @@ -14,7 +14,7 @@ export type ScoreChunkAraryProps = Omit<
ScoreChunkProps,
"chunk" | "counter" | "total" | "begin" | "end"
> & {
chunks: ChunkMetadataWithFileData[];
chunks: ChunkMetadata[];
setChunkGroups: Setter<ChunkGroupDTO[]>;
};

Expand Down
12 changes: 6 additions & 6 deletions search/src/components/SingleChunkPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SingleChunkDTO,
ChunkBookmarksDTO,
isChunkGroupPageDTO,
ChunkMetadataWithFileData,
ChunkMetadata,
ScoreChunkDTO,
} from "../../utils/apiTypes";
import ScoreChunk from "./ScoreChunk";
Expand All @@ -36,7 +36,7 @@ export const SingleChunkPage = (props: SingleChunkPageProps) => {
const initialChunkMetadata = props.defaultResultChunk.metadata;

const [chunkMetadata, setChunkMetadata] =
createSignal<ChunkMetadataWithFileData | null>(initialChunkMetadata);
createSignal<ChunkMetadata | null>(initialChunkMetadata);
const [error, setError] = createSignal("");
const [fetching, setFetching] = createSignal(true);
const [chunkGroups, setChunkGroups] = createSignal<ChunkGroupDTO[]>([]);
Expand All @@ -52,7 +52,7 @@ export const SingleChunkPage = (props: SingleChunkPageProps) => {
const [loadingRecommendations, setLoadingRecommendations] =
createSignal(false);
const [recommendedChunks, setRecommendedChunks] = createSignal<
ChunkMetadataWithFileData[]
ChunkMetadata[]
>([]);
const [openChat, setOpenChat] = createSignal(false);
const [selectedIds, setSelectedIds] = createSignal<string[]>([]);
Expand Down Expand Up @@ -113,7 +113,7 @@ export const SingleChunkPage = (props: SingleChunkPageProps) => {

const fetchRecommendations = (
ids: string[],
prev_recommendations: ChunkMetadataWithFileData[],
prev_recommendations: ChunkMetadata[],
) => {
setLoadingRecommendations(true);
const currentDataset = $dataset?.();
Expand All @@ -133,7 +133,7 @@ export const SingleChunkPage = (props: SingleChunkPageProps) => {
}).then((response) => {
if (response.ok) {
void response.json().then((data) => {
const typed_data = data as ChunkMetadataWithFileData[];
const typed_data = data as ChunkMetadata[];
const deduped_data = typed_data.filter((d) => {
return !prev_recommendations.some((c) => c.id == d.id);
});
Expand Down Expand Up @@ -166,7 +166,7 @@ export const SingleChunkPage = (props: SingleChunkPageProps) => {
},
}).then((response) => {
if (response.ok) {
void response.json().then((data: ChunkMetadataWithFileData) => {
void response.json().then((data: ChunkMetadata) => {
setChunkMetadata(data);
setScoreChunk([{ metadata: [data], score: 0 }]);
setError("");
Expand Down
41 changes: 19 additions & 22 deletions search/utils/apiTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { ComboboxSection } from "../src/components/Atoms/ComboboxChecklist";

export interface ChunkMetadataWithFileData {
export interface ChunkMetadata {
id: string;
content: string;
chunk_html?: string;
Expand All @@ -12,9 +12,8 @@ export interface ChunkMetadataWithFileData {
tag_set: string | null;
tracking_id: string | null;
time_stamp: string | null;
file_id: string | null;
file_name: string | null;
metadata: Record<string, never> | null;
dataset_id: string;
weight: number;
}

Expand All @@ -26,27 +25,25 @@ export interface APIRequest {
api_key: string;
}

export const isChunkMetadata = (
chunk: unknown,
): chunk is ChunkMetadataWithFileData => {
export const isChunkMetadata = (chunk: unknown): chunk is ChunkMetadata => {
if (typeof chunk !== "object" || chunk === null) return false;

return (
indirectHasOwnProperty(chunk, "id") &&
typeof (chunk as ChunkMetadataWithFileData).id === "string" &&
typeof (chunk as ChunkMetadata).id === "string" &&
indirectHasOwnProperty(chunk, "content") &&
typeof (chunk as ChunkMetadataWithFileData).content === "string" &&
typeof (chunk as ChunkMetadata).content === "string" &&
indirectHasOwnProperty(chunk, "qdrant_point_id") &&
typeof (chunk as ChunkMetadataWithFileData).qdrant_point_id === "string" &&
typeof (chunk as ChunkMetadata).qdrant_point_id === "string" &&
indirectHasOwnProperty(chunk, "created_at") &&
typeof (chunk as ChunkMetadataWithFileData).created_at === "string" &&
typeof (chunk as ChunkMetadata).created_at === "string" &&
indirectHasOwnProperty(chunk, "updated_at") &&
typeof (chunk as ChunkMetadataWithFileData).updated_at === "string" &&
typeof (chunk as ChunkMetadata).updated_at === "string" &&
indirectHasOwnProperty(chunk, "tag_set") &&
(typeof (chunk as ChunkMetadataWithFileData).tag_set === "string" ||
(chunk as ChunkMetadataWithFileData).tag_set === null) &&
(typeof (chunk as ChunkMetadataWithFileData).metadata === "object" ||
(chunk as ChunkMetadataWithFileData).metadata === null)
(typeof (chunk as ChunkMetadata).tag_set === "string" ||
(chunk as ChunkMetadata).tag_set === null) &&
(typeof (chunk as ChunkMetadata).metadata === "object" ||
(chunk as ChunkMetadata).metadata === null)
);
};

Expand All @@ -73,7 +70,7 @@ export interface ChunksWithTotalPagesDTO {
}

export interface ScoreChunkDTO {
metadata: [ChunkMetadataWithFileData];
metadata: [ChunkMetadata];
score: number;
}

Expand Down Expand Up @@ -204,7 +201,7 @@ export const isUserDTO = (user: unknown): user is UserDTO => {

export type UserDTOWithVotesAndChunks = UserDTO & {
created_at: string;
chunks: ChunkMetadataWithFileData[];
chunks: ChunkMetadata[];
total_chunks_created: number;
};

Expand Down Expand Up @@ -289,7 +286,7 @@ export const isChunkGroupDTO = (group: unknown): group is ChunkGroupDTO => {
};

export interface ChunkGroupBookmarkDTO {
chunks: ChunkMetadataWithFileData[];
chunks: ChunkMetadata[];
group: ChunkGroupDTO;
total_pages: number;
}
Expand Down Expand Up @@ -317,17 +314,17 @@ export const isChunkGroupSearchDTO = (

export interface CreateChunkDTO {
message?: string;
chunk_metadata: ChunkMetadataWithFileData;
chunk_metadata: ChunkMetadata;
duplicate: boolean;
}

export interface SingleChunkDTO {
metadata: ChunkMetadataWithFileData | null;
metadata: ChunkMetadata | null;
status: number;
}

export interface ChunkGroupBookmarksDTO {
bookmarks: ChunkMetadataWithFileData[];
bookmarks: ChunkMetadata[];
group: ChunkGroupDTO;
}
export interface ChunkGroupBookmarksWithStatusDTO {
Expand Down Expand Up @@ -587,7 +584,7 @@ export function isChunkFilePagesDTO(file: unknown): file is ChunkFilePagesDTO {
}

export interface BookmarkData {
chunks: ChunkMetadataWithFileData[];
chunks: ChunkMetadata[];
group: ChunkGroupDTO;
total_pages: number;
}
Expand Down
Loading

0 comments on commit 1f6c09b

Please sign in to comment.