这是indexloc提供的服务,不要输入任何密码
Skip to content
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
32 changes: 32 additions & 0 deletions clients/ts-sdk/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -11809,6 +11809,13 @@
"type": "boolean",
"nullable": true
},
"tabMessages": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PublicPageTabMessage"
},
"nullable": true
},
"theme": {
"allOf": [
{
Expand Down Expand Up @@ -11962,6 +11969,25 @@
"search_type": "semantic"
}
},
"PublicPageTabMessage": {
"type": "object",
"required": [
"title",
"tabInnerHtml",
"showComponentCode"
],
"properties": {
"showComponentCode": {
"type": "boolean"
},
"tabInnerHtml": {
"type": "string"
},
"title": {
"type": "string"
}
}
},
"PublicPageTheme": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -15015,6 +15041,12 @@
],
"nullable": true
},
"recency_bias": {
"type": "number",
"format": "float",
"description": "Recency Bias lets you determine how much of an effect the recency of chunks will have on the search results. If not specified, this defaults to 0.0. We recommend setting this to 1.0 for a gentle reranking of the results, >3.0 for a strong reranking of the results.",
"nullable": true
},
"sort_by": {
"allOf": [
{
Expand Down
11 changes: 11 additions & 0 deletions clients/ts-sdk/src/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,7 @@ export type PublicPageParameters = {
responsive?: (boolean) | null;
searchOptions?: ((PublicPageSearchOptions) | null);
suggestedQueries?: (boolean) | null;
tabMessages?: Array<PublicPageTabMessage> | null;
theme?: ((PublicPageTheme) | null);
type?: (string) | null;
useGroupSearch?: (boolean) | null;
Expand Down Expand Up @@ -1916,6 +1917,12 @@ export type PublicPageSearchOptions = {
user_id?: (string) | null;
};

export type PublicPageTabMessage = {
showComponentCode: boolean;
tabInnerHtml: string;
title: string;
};

export type PublicPageTheme = 'light' | 'dark';

export type QdrantChunkMetadata = {
Expand Down Expand Up @@ -2720,6 +2727,10 @@ export type SortBySearchType = {
*/
export type SortOptions = {
location_bias?: ((GeoInfoWithBias) | null);
/**
* Recency Bias lets you determine how much of an effect the recency of chunks will have on the search results. If not specified, this defaults to 0.0. We recommend setting this to 1.0 for a gentle reranking of the results, >3.0 for a strong reranking of the results.
*/
recency_bias?: (number) | null;
sort_by?: ((QdrantSortBy) | null);
/**
* Tag weights is a JSON object which can be used to boost the ranking of chunks with certain tags. This is useful for when you want to be able to bias towards chunks with a certain tag on the fly. The keys are the tag names and the values are the weights.
Expand Down
227 changes: 227 additions & 0 deletions frontends/dashboard/src/hooks/usePublicPageSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
import { createSignal, createEffect, useContext, createMemo } from "solid-js";
import { createStore } from "solid-js/store";
import { Dataset, PublicPageParameters } from "trieve-ts-sdk";
import { createQuery } from "@tanstack/solid-query";
import { DatasetContext } from "../contexts/DatasetContext";
import { UserContext } from "../contexts/UserContext";
import { useTrieve } from "./useTrieve";
import { createToast } from "../components/ShowToasts";
import { ApiRoutes } from "../components/Routes";
import { HeroPatterns } from "../pages/dataset/HeroPatterns";
import { createInitializedContext } from "../utils/initialize";

export type DatasetWithPublicPage = Dataset & {
server_configuration: {
PUBLIC_DATASET?: {
extra_params: PublicPageParameters;
enabled: boolean;
};
};
};

export const { use: usePublicPage, provider: PublicPageProvider } =
createInitializedContext("public-page-settings", () => {
const [extraParams, setExtraParams] = createStore<PublicPageParameters>({});
const [searchOptionsError, setSearchOptionsError] = createSignal<
string | null
>(null);

const [isPublic, setisPublic] = createSignal<boolean>(false);
const [hasLoaded, setHasLoaded] = createSignal(false);

const { datasetId } = useContext(DatasetContext);
const { selectedOrg } = useContext(UserContext);

const trieve = useTrieve();

createEffect(() => {
void (
trieve.fetch<"eject">("/api/dataset/{dataset_id}", "get", {
datasetId: datasetId(),
}) as Promise<DatasetWithPublicPage>
).then((dataset) => {
setisPublic(!!dataset.server_configuration?.PUBLIC_DATASET?.enabled);
setExtraParams(
dataset?.server_configuration?.PUBLIC_DATASET?.extra_params || {},
);

setHasLoaded(true);
});
});

const crawlSettingsQuery = createQuery(() => ({
queryKey: ["crawl-settings", datasetId()],
queryFn: async () => {
const result = await trieve.fetch(
"/api/dataset/crawl_options/{dataset_id}",
"get",
{
datasetId: datasetId(),
},
);
return result.crawl_options ?? null;
},
}));

// If the useGroupSearch has not been manually set,
// set to true if shopify scraping is enabled
createEffect(() => {
if (
crawlSettingsQuery.data &&
crawlSettingsQuery.data.scrape_options?.type === "shopify"
) {
if (
extraParams.useGroupSearch === null ||
extraParams.useGroupSearch === undefined
) {
setExtraParams("useGroupSearch", true);
}
}
});

// manually set the array for rolemessages to simplify logic
// context blocks until it's set
createEffect(() => {
if (
extraParams.tabMessages === undefined ||
extraParams.tabMessages === null
) {
setExtraParams("tabMessages", []);
}
});

// Selecting blank as the hero pattern should reset everything else
// Selecting another pattern builds the svg field
createEffect(() => {
const pattern = extraParams.heroPattern?.heroPatternName;
const foreground = extraParams.heroPattern?.foregroundColor;
if (hasLoaded()) {
if (pattern == "Blank" || !pattern) {
setExtraParams("heroPattern", {
heroPatternName: "Blank",
heroPatternSvg: "",
foregroundColor: "#ffffff",
foregroundOpacity: 0.5,
backgroundColor: "#f3f3f3",
});
} else if (pattern == "Solid") {
setExtraParams("heroPattern", (prev) => ({
...prev,
backgroundColor: foreground,
}));
} else {
setExtraParams("heroPattern", (prev) => ({
...prev,
heroPatternSvg: HeroPatterns[pattern](
prev?.foregroundColor || "#ffffff",
prev?.foregroundOpacity || 0.5,
),
}));
}
}
});

const unpublishDataset = async () => {
await trieve.fetch("/api/dataset", "put", {
organizationId: selectedOrg().id,
data: {
dataset_id: datasetId(),
server_configuration: {
PUBLIC_DATASET: {
enabled: false,
},
},
},
});

createToast({
type: "info",
title: `Made dataset ${datasetId()} private`,
});

setisPublic(false);
};

const publishDataset = async () => {
const name = `${datasetId()}-pregenerated-search-component`;
if (!isPublic()) {
const response = await trieve.fetch(
"/api/organization/api_key",
"post",
{
data: {
name: name,
role: 0,
dataset_ids: [datasetId()],
scopes: ApiRoutes["Search Component Routes"],
},
organizationId: selectedOrg().id,
},
);

await trieve.fetch("/api/dataset", "put", {
organizationId: selectedOrg().id,
data: {
dataset_id: datasetId(),
server_configuration: {
PUBLIC_DATASET: {
enabled: true,
// @ts-expect-error Object literal may only specify known properties, and 'api_key' does not exist in type 'PublicDatasetOptions'. [2353]
api_key: response.api_key,
extra_params: {
...extraParams,
},
},
},
},
});

createToast({
type: "info",
title: `Created API key for ${datasetId()} named ${name}`,
});
} else {
await trieve.fetch("/api/dataset", "put", {
organizationId: selectedOrg().id,
data: {
dataset_id: datasetId(),
server_configuration: {
PUBLIC_DATASET: {
enabled: true,
extra_params: {
...extraParams,
},
},
},
},
});

createToast({
type: "info",
title: `Updated Public settings for ${name}`,
});
}

setExtraParams(extraParams);
setisPublic(true);
};

const apiHost = import.meta.env.VITE_API_HOST as unknown as string;
const publicUrl = createMemo(() => {
return `${apiHost.slice(0, -4)}/public_page/${datasetId()}`;
});

return {
extraParams,
setExtraParams,
searchOptionsError,
setSearchOptionsError,
isPublic,
publicUrl,
unpublishDataset,
publishDataset,
get ready() {
return hasLoaded() && !!extraParams.tabMessages;
},
};
});
4 changes: 4 additions & 0 deletions frontends/dashboard/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ pre.shiki {
}
}

.jsoneditor.jsoneditor-mode-code {
@apply border-neutral-300;
}

@keyframes fadeIn {
from {
opacity: 0;
Expand Down
4 changes: 2 additions & 2 deletions frontends/dashboard/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { RecommendationsTablePage } from "./analytics/pages/tablePages/Recommend
import { SingleRecommendationQueryPage } from "./analytics/pages/SingleRecommendationQueryPage.tsx";
import { EventsTablePage } from "./analytics/pages/tablePages/EventsTablePage.tsx";
import { SingleEventQueryPage } from "./analytics/pages/SingleEventQueryPage.tsx";
import { PublicPageSettings } from "./pages/dataset/PublicPageSettings.tsx";
import { PublicPageSettingsPage } from "./pages/dataset/PublicPageSettings.tsx";

if (!DEV) {
Sentry.init({
Expand Down Expand Up @@ -151,7 +151,7 @@ const routes: RouteDefinition[] = [
},
{
path: "/public-page",
component: PublicPageSettings,
component: PublicPageSettingsPage,
},
{
path: "/analytics",
Expand Down
Loading
Loading