Skip to content

Commit 437a154

Browse files
cdxkerdensumesh
authored andcommitted
feat(shopify): add Search Tool Configuration into Tool Config settings
1 parent d79ffff commit 437a154

File tree

7 files changed

+82
-34
lines changed

7 files changed

+82
-34
lines changed

clients/trieve-shopify-extension/app/components/settings/LLMSettings.tsx

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import {
1616
} from "@shopify/polaris";
1717
import { CaretDownIcon, CaretUpIcon } from "@shopify/polaris-icons";
1818
import { useState } from "react";
19-
import { DatasetConfig, ShopifyDatasetSettings } from "./DatasetSettings";
19+
import { DatasetConfig } from "./DatasetSettings";
2020
import { useSubmit } from "@remix-run/react";
2121
import { useAppBridge } from "@shopify/app-bridge-react";
2222
import {
2323
Dataset,
2424
PriceToolCallOptions,
2525
RelevanceToolCallOptions,
26+
SearchToolCallOptions,
2627
} from "trieve-ts-sdk";
2728

2829
export const defaultRelevanceToolCallOptions: RelevanceToolCallOptions = {
@@ -47,18 +48,26 @@ export const defaultPriceToolCallOptions: PriceToolCallOptions = {
4748
"Maximum price of the product. Only set this if a maximum price is mentioned in the query.",
4849
};
4950

51+
export const defaultSearchToolCallOptions: SearchToolCallOptions = {
52+
userMessageTextPrefix: "Here is the user query:",
53+
toolDescription:
54+
"Call this tool anytime it seems like we need to skip the search step. This tool tells our system that the user is asking about what they were previously shown.",
55+
};
56+
5057
interface LLMSettingsProps {
5158
shopDataset: Dataset;
5259
existingPdpPrompt: string;
5360
existingRelevanceToolCallOptions: RelevanceToolCallOptions | null;
5461
existingPriceToolCallOptions: PriceToolCallOptions | null;
62+
existingSearchToolCallOptions: SearchToolCallOptions | null;
5563
}
5664

5765
export function LLMSettings({
5866
shopDataset,
5967
existingPdpPrompt,
6068
existingRelevanceToolCallOptions,
6169
existingPriceToolCallOptions,
70+
existingSearchToolCallOptions
6271
}: LLMSettingsProps) {
6372
const shopify = useAppBridge();
6473
const submit = useSubmit();
@@ -79,6 +88,10 @@ export function LLMSettings({
7988
existingPriceToolCallOptions ?? defaultPriceToolCallOptions,
8089
);
8190

91+
const [searchToolCallOptions, setSearchToolCallOptions] = useState(
92+
existingSearchToolCallOptions ?? defaultSearchToolCallOptions,
93+
);
94+
8295
const onLLMSettingsSave = async () => {
8396
submit(
8497
{
@@ -100,6 +113,7 @@ export function LLMSettings({
100113
{
101114
relevance_tool_call_options: JSON.stringify(relevanceToolCallOptions),
102115
price_tool_call_options: JSON.stringify(priceToolCallOptions),
116+
search_tool_call_options: JSON.stringify(searchToolCallOptions),
103117
dataset_id: shopDataset.id,
104118
type: "tool_call_options",
105119
},
@@ -464,6 +478,46 @@ export function LLMSettings({
464478
<Button onClick={saveToolCallOptions}>Save</Button>
465479
</InlineStack>
466480
</Card>
481+
<Card roundedAbove="sm">
482+
<BlockStack gap="400">
483+
<FormLayout>
484+
<Text as="h1" variant="headingMd">
485+
Search Tool Configuration
486+
</Text>
487+
<BlockStack gap="400">
488+
<TextField
489+
label="Tool Description"
490+
helpText="The description of the tool"
491+
value={searchToolCallOptions.toolDescription ?? ""}
492+
onChange={(e) =>
493+
setSearchToolCallOptions({
494+
...searchToolCallOptions,
495+
toolDescription: e,
496+
})
497+
}
498+
multiline={3}
499+
autoComplete="off"
500+
/>
501+
<TextField
502+
label="User Message Text Prefix"
503+
helpText="The prefix to use before showing the the users message"
504+
value={searchToolCallOptions.userMessageTextPrefix ?? ""}
505+
onChange={(e) =>
506+
setSearchToolCallOptions({
507+
...searchToolCallOptions,
508+
userMessageTextPrefix: e,
509+
})
510+
}
511+
multiline={3}
512+
autoComplete="off"
513+
/>
514+
</BlockStack>
515+
</FormLayout>
516+
</BlockStack>
517+
<InlineStack align="end" gap="200">
518+
<Button onClick={saveToolCallOptions}>Save</Button>
519+
</InlineStack>
520+
</Card>
467521
</BlockStack>
468522
</InlineGrid>
469523
</BlockStack>

clients/trieve-shopify-extension/app/routes/app._dashboard.settings.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
RelevanceToolCallOptions,
1717
PriceToolCallOptions,
1818
type Dataset,
19+
SearchToolCallOptions,
1920
} from "trieve-ts-sdk";
2021
import { createWebPixel, isWebPixelInstalled } from "app/queries/webPixel";
2122
import { getAppMetafields, setAppMetafields } from "app/queries/metafield";
@@ -38,6 +39,7 @@ export const loader = async ({
3839
pdpPrompt: string;
3940
presetQuestions: PresetQuestion[];
4041
relevanceToolCallOptions: RelevanceToolCallOptions | null;
42+
searchToolCallOptions: SearchToolCallOptions | null;
4143
priceToolCallOptions: PriceToolCallOptions | null;
4244
}> => {
4345
const { session } = await authenticate.admin(request);
@@ -84,6 +86,11 @@ export const loader = async ({
8486
fetcher,
8587
"relevance_tool_call_options",
8688
);
89+
const searchToolCallOptions =
90+
await getAppMetafields<RelevanceToolCallOptions>(
91+
fetcher,
92+
"search_tool_call_options",
93+
);
8794
const priceToolCallOptions = await getAppMetafields<PriceToolCallOptions>(
8895
fetcher,
8996
"price_tool_call_options",
@@ -96,6 +103,7 @@ export const loader = async ({
96103
pdpPrompt,
97104
presetQuestions,
98105
relevanceToolCallOptions,
106+
searchToolCallOptions,
99107
priceToolCallOptions,
100108
};
101109
};
@@ -204,6 +212,7 @@ export const action = async ({ request }: ActionFunctionArgs) => {
204212
"relevance_tool_call_options",
205213
);
206214
const priceToolCallOptions = formData.get("price_tool_call_options");
215+
const searchToolCallOptions = formData.get("search_tool_call_options");
207216
await setAppMetafields(fetcher, [
208217
{
209218
key: "relevance_tool_call_options",
@@ -215,6 +224,11 @@ export const action = async ({ request }: ActionFunctionArgs) => {
215224
value: priceToolCallOptions as string,
216225
type: "json",
217226
},
227+
{
228+
key: "search_tool_call_options",
229+
value: searchToolCallOptions as string,
230+
type: "json",
231+
},
218232
]);
219233
return { success: true };
220234
}
@@ -261,6 +275,7 @@ export default function Dataset() {
261275
pdpPrompt,
262276
presetQuestions,
263277
relevanceToolCallOptions,
278+
searchToolCallOptions,
264279
priceToolCallOptions,
265280
} = useLoaderData<typeof loader>();
266281
const [selectedTab, setSelectedTab] = useState(0);
@@ -325,6 +340,7 @@ export default function Dataset() {
325340
shopDataset={shopDataset as Dataset}
326341
existingPdpPrompt={pdpPrompt}
327342
existingRelevanceToolCallOptions={relevanceToolCallOptions}
343+
existingSearchToolCallOptions={searchToolCallOptions}
328344
existingPriceToolCallOptions={priceToolCallOptions}
329345
/>
330346
),

clients/trieve-shopify-extension/extensions/global-search/blocks/global_component.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
showTrieve: false,
6464
relevanceToolCallOptions: appMetafieldTrieve.relevance_tool_call_options,
6565
priceToolCallOptions: appMetafieldTrieve.price_tool_call_options,
66+
searchToolCallOptions: appMetafieldTrieve.search_tool_call_options,
6667
getCartQuantity: (trackingId) => {
6768
return checkCartQuantity(parseInt(trackingId));
6869
},

clients/trieve-shopify-extension/extensions/global-search/blocks/inline_component.liquid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
showTrieve: false,
8080
relevanceToolCallOptions: appMetafieldTrieve.relevance_tool_call_options,
8181
priceToolCallOptions: appMetafieldTrieve.price_tool_call_options,
82+
searchToolCallOptions: appMetafieldTrieve.search_tool_call_options,
8283
getCartQuantity: (trackingId) => {
8384
return checkCartQuantity(parseInt(trackingId));
8485
},

clients/trieve-shopify-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"tailwind-merge": "^3.1.0",
5757
"tailwindcss": "^3.4.17",
5858
"trieve-search-component": "0.4.65",
59-
"trieve-ts-sdk": "^0.0.114",
59+
"trieve-ts-sdk": "^0.0.115",
6060
"vite-tsconfig-paths": "^5.0.1"
6161
},
6262
"devDependencies": {

clients/trieve-shopify-extension/yarn.lock

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8996,16 +8996,7 @@ string-hash@^1.1.3:
89968996
resolved "https://registry.yarnpkg.com/string-hash/-/string-hash-1.1.3.tgz#e8aafc0ac1855b4666929ed7dd1275df5d6c811b"
89978997
integrity sha512-kJUvRUFK49aub+a7T1nNE66EJbZBMnBgoC1UbCZ5n6bsZKBRga4KgBRTMn/pFkeCZSYtNeSyMxPDM0AXWELk2A==
89988998

8999-
"string-width-cjs@npm:string-width@^4.2.0":
9000-
version "4.2.3"
9001-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
9002-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
9003-
dependencies:
9004-
emoji-regex "^8.0.0"
9005-
is-fullwidth-code-point "^3.0.0"
9006-
strip-ansi "^6.0.1"
9007-
9008-
string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
8999+
"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
90099000
version "4.2.3"
90109001
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
90119002
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -9113,14 +9104,7 @@ stringify-entities@^4.0.0:
91139104
character-entities-html4 "^2.0.0"
91149105
character-entities-legacy "^3.0.0"
91159106

9116-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
9117-
version "6.0.1"
9118-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
9119-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
9120-
dependencies:
9121-
ansi-regex "^5.0.1"
9122-
9123-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
9107+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
91249108
version "6.0.1"
91259109
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
91269110
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -9384,10 +9368,10 @@ trieve-search-component@0.4.65:
93849368
tailwind-merge "^3.0.2"
93859369
trieve-ts-sdk "^0.0.90"
93869370

9387-
trieve-ts-sdk@^0.0.114:
9388-
version "0.0.114"
9389-
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.114.tgz#1207d09f4a4295e50350f7468e2eea8c13ccf9d2"
9390-
integrity sha512-cVOSWt9yxL+3g8LRPTVLNOHViK7jVcXVD/2UzteEWzU1GjgvNGcyKkdwjpcwNr8qsKC5m4+OZDExaGnSoPCy8g==
9371+
trieve-ts-sdk@^0.0.115:
9372+
version "0.0.115"
9373+
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.115.tgz#c54b2be29916e087991f413cae9b48c92f7125df"
9374+
integrity sha512-1VkI5GJ0mKEQcRjM1amX62TZvRtuZoB5NfFHba6qpK0JnXtLm7h9O8UtjRliUu2gi35J6zIU49OaYgd/OIVV3w==
93919375

93929376
trieve-ts-sdk@^0.0.90:
93939377
version "0.0.90"
@@ -10052,7 +10036,7 @@ word-wrap@^1.2.5:
1005210036
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.5.tgz#d2c45c6dd4fbce621a66f136cbe328afd0410b34"
1005310037
integrity sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==
1005410038

10055-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
10039+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
1005610040
version "7.0.0"
1005710041
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
1005810042
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -10070,15 +10054,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
1007010054
string-width "^4.1.0"
1007110055
strip-ansi "^6.0.0"
1007210056

10073-
wrap-ansi@^7.0.0:
10074-
version "7.0.0"
10075-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
10076-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
10077-
dependencies:
10078-
ansi-styles "^4.0.0"
10079-
string-width "^4.1.0"
10080-
strip-ansi "^6.0.0"
10081-
1008210057
wrap-ansi@^8.1.0:
1008310058
version "8.1.0"
1008410059
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

frontends/dashboard/src/pages/dataset/PublicPageSettings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
PublicPageTabMessage,
3232
RelevanceToolCallOptions,
3333
SearchOverGroupsResponseBody,
34+
SearchToolCallOptions,
3435
} from "trieve-ts-sdk";
3536
import FilterSidebarBuilder from "../../components/FilterSidebarBuilder";
3637
import { DatasetContext } from "../../contexts/DatasetContext";

0 commit comments

Comments
 (0)