Skip to content

Commit 8b1613e

Browse files
committed
bugfix(shopify): set AI prompts in onboarding steps is default completed
1 parent b94c03f commit 8b1613e

4 files changed

Lines changed: 68 additions & 57 deletions

File tree

clients/trieve-shopify-extension/app/auth.ts

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { getTrieveBaseUrlEnv } from "./env.server";
66
import { buildAdminApiFetcherForServer } from "./loaders/serverLoader";
77
import { AdminApiCaller } from "./loaders";
88
import { AppInstallData } from "./routes/app.setup";
9+
import {
10+
DEFAULT_RAG_PROMPT,
11+
DEFAULT_SYSTEM_PROMPT,
12+
} from "./components/onboarding/SetPromptsOnboarding";
913

1014
export const validateTrieveAuth = async <S extends boolean = true>(
1115
request: LoaderFunctionArgs["request"],
@@ -80,15 +84,18 @@ export const validateTrieveAuth = async <S extends boolean = true>(
8084

8185
if (!key) {
8286
console.log("No key found for current shop, creating one");
83-
const query = await admin.graphql(
84-
`
87+
const query = await admin
88+
.graphql(
89+
`
8590
query {
8691
shop {
8792
name
8893
email
8994
}
9095
}
91-
`).catch((e) => {
96+
`,
97+
)
98+
.catch((e) => {
9299
console.error(e);
93100
throw e;
94101
});
@@ -103,41 +110,47 @@ export const validateTrieveAuth = async <S extends boolean = true>(
103110

104111
console.log("New User, creating credentials", { shop_name, shop_email });
105112

106-
const userCredentialsResponse = await fetch(`${getTrieveBaseUrlEnv()}/api/auth/create_api_only_user`, {
107-
method: "POST",
108-
credentials: "include",
109-
headers: {
110-
"Content-Type": "application/json",
111-
"X-Shopify-Authorization": `${process.env.SHOPIFY_SECRET_KEY}`,
113+
const userCredentialsResponse = await fetch(
114+
`${getTrieveBaseUrlEnv()}/api/auth/create_api_only_user`,
115+
{
116+
method: "POST",
117+
credentials: "include",
118+
headers: {
119+
"Content-Type": "application/json",
120+
"X-Shopify-Authorization": `${process.env.SHOPIFY_SECRET_KEY}`,
121+
},
122+
body: JSON.stringify({
123+
user_name: shop_name,
124+
user_email: shop_email,
125+
}),
112126
},
113-
body: JSON.stringify({
114-
user_name: shop_name,
115-
user_email: shop_email,
116-
}),
117-
}).catch((e) => {
127+
).catch((e) => {
118128
console.error(e);
119129
throw e;
120130
});
121131

122-
const userCredentials = await userCredentialsResponse.json() as CreateApiUserResponse;
132+
const userCredentials =
133+
(await userCredentialsResponse.json()) as CreateApiUserResponse;
123134

124-
key = await prisma.apiKey.upsert({
125-
where: {
126-
shop: session.shop as string,
127-
},
128-
update: {
129-
key: userCredentials.api_key,
130-
},
131-
create: {
132-
organizationId: userCredentials.organization_id,
133-
shop: session.shop as string,
134-
key: userCredentials.api_key,
135-
createdAt: new Date(),
136-
}
137-
}).catch((e) => {
138-
console.error(e);
139-
throw e;
140-
});
135+
key = await prisma.apiKey
136+
.upsert({
137+
where: {
138+
shop: session.shop as string,
139+
},
140+
update: {
141+
key: userCredentials.api_key,
142+
},
143+
create: {
144+
organizationId: userCredentials.organization_id,
145+
shop: session.shop as string,
146+
key: userCredentials.api_key,
147+
createdAt: new Date(),
148+
},
149+
})
150+
.catch((e) => {
151+
console.error(e);
152+
throw e;
153+
});
141154

142155
const trieve = new TrieveSDK({
143156
baseUrl: getTrieveBaseUrlEnv(),
@@ -166,10 +179,8 @@ export const validateTrieveAuth = async <S extends boolean = true>(
166179
dataset_name: session.shop,
167180
tracking_id: session.shop,
168181
server_configuration: {
169-
SYSTEM_PROMPT:
170-
"[[personality]]\nYou are a friendly, helpful, and knowledgeable ecommerce sales associate. Your communication style is warm, patient, and enthusiastic without being pushy. You're approachable and conversational while maintaining professionalism. You balance being personable with being efficient, understanding that customers value both connection and their time. You're solution-oriented and genuinely interested in helping customers find the right products for their needs.\n\n[[goal]]\nYour primary goal is to help customers find products that genuinely meet their needs while providing an exceptional shopping experience. You aim to:\n1. Understand customer requirements through thoughtful questions\n2. Provide relevant product recommendations based on customer preferences\n3. Offer detailed, accurate information about products\n4. Address customer concerns and objections respectfully\n5. Guide customers through the purchasing process\n6. Encourage sales without being pushy or manipulative\n7. Create a positive impression that builds long-term customer loyalty\n\n[[response structure]]\n1. Begin with a warm greeting and acknowledgment of the customer's query or concern\n2. Ask clarifying questions if needed to better understand their requirements\n3. Provide concise, relevant information that directly addresses their needs\n4. Include specific product recommendations when appropriate, with brief explanations of why they might be suitable\n5. Address any potential concerns proactively\n6. Close with a helpful next step or question that moves the conversation forward\n7. Keep responses conversational yet efficient, balancing thoroughness with respect for the customer's time.\n",
171-
RAG_PROMPT:
172-
"You may use the retrieved context to help you respond. When discussing products, prioritize information from the provided product data while using your general knowledge to create helpful, natural responses. If a customer asks about products or specifications not mentioned in the context, acknowledge the limitation and offer to check for more information rather than inventing details.",
182+
SYSTEM_PROMPT: DEFAULT_SYSTEM_PROMPT,
183+
RAG_PROMPT: DEFAULT_RAG_PROMPT,
173184
},
174185
});
175186

@@ -236,15 +247,12 @@ export const validateTrieveAuthWehbook = async <S extends boolean = true>(
236247
}
237248

238249
if (strict && !key.currentDatasetId) {
239-
throw new Response(
240-
JSON.stringify({ message: "No dataset selected" }),
241-
{
242-
headers: {
243-
"Content-Type": "application/json; charset=utf-8",
244-
},
245-
status: 401,
250+
throw new Response(JSON.stringify({ message: "No dataset selected" }), {
251+
headers: {
252+
"Content-Type": "application/json; charset=utf-8",
246253
},
247-
);
254+
status: 401,
255+
});
248256
}
249257

250258
return {

clients/trieve-shopify-extension/app/components/DatasetSettings.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,7 @@ export const DatasetSettings = ({
217217
autoComplete="off"
218218
label="Checkout Selector"
219219
helpText="The HTML selector of the checkout button on your shopify store. This is used to track revenue when a user clicks the checkout button."
220-
value={
221-
unsavedRevenueTrackingOptions?.checkout_selector || ""
222-
}
220+
value={unsavedRevenueTrackingOptions?.checkout_selector || ""}
223221
onChange={(e) => {
224222
setUnsavedRevenueTrackingOptions({
225223
...unsavedRevenueTrackingOptions,
@@ -275,7 +273,7 @@ export const DatasetSettings = ({
275273
/>
276274
<TextField
277275
label="LLM Default Model"
278-
helpText="The default model to use for the LLM. See https://openrouter.ai/models for all available LLMs you can use."
276+
helpText="Use this prompt to set the personality, tone, and goals of the model."
279277
value={datasetSettings.LLM_DEFAULT_MODEL ?? ""}
280278
onChange={(e) =>
281279
setDatasetSettings({
@@ -299,8 +297,8 @@ export const DatasetSettings = ({
299297
autoComplete="off"
300298
/>
301299
<TextField
302-
label="RAG Prompt"
303-
helpText="The prompt to guide the RAG model in handling retrieved context with the user query"
300+
label="Context Prompt"
301+
helpText="Use this prompt to tell the model how strictly it needs to follow or how it should generally handle the context (your product descriptions, metadata, photos, etc.)."
304302
value={datasetSettings.RAG_PROMPT ?? ""}
305303
multiline={5}
306304
onChange={(e) =>

clients/trieve-shopify-extension/app/components/onboarding/SetPromptsOnboarding.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ import { DatasetConfig } from "../DatasetSettings";
1212
import { withSuspense } from "app/utils/suspense";
1313
import { trackCustomerEvent } from "app/processors/shopifyTrackers";
1414

15+
export const DEFAULT_SYSTEM_PROMPT =
16+
"[[personality]]\nYou are a friendly, helpful, and knowledgeable ecommerce sales associate. Your communication style is warm, patient, and enthusiastic without being pushy. You're approachable and conversational while maintaining professionalism. You balance being personable with being efficient, understanding that customers value both connection and their time. You're solution-oriented and genuinely interested in helping customers find the right products for their needs.\n\n[[goal]]\nYour primary goal is to help customers find products that genuinely meet their needs while providing an exceptional shopping experience. You aim to:\n1. Understand customer requirements through thoughtful questions\n2. Provide relevant product recommendations based on customer preferences\n3. Offer detailed, accurate information about products\n4. Address customer concerns and objections respectfully\n5. Guide customers through the purchasing process\n6. Encourage sales without being pushy or manipulative\n7. Create a positive impression that builds long-term customer loyalty\n\n[[response structure]]\n1. Begin with a warm greeting and acknowledgment of the customer's query or concern\n2. Ask clarifying questions if needed to better understand their requirements\n3. Provide concise, relevant information that directly addresses their needs\n4. Include specific product recommendations when appropriate, with brief explanations of why they might be suitable\n5. Address any potential concerns proactively\n6. Close with a helpful next step or question that moves the conversation forward\n7. Keep responses conversational yet efficient, balancing thoroughness with respect for the customer's time.\n";
17+
18+
export const DEFAULT_RAG_PROMPT =
19+
"You may use the retrieved context to help you respond. When discussing products, prioritize information from the provided product data while using your general knowledge to create helpful, natural responses. If a customer asks about products or specifications not mentioned in the context, acknowledge the limitation and offer to check for more information rather than inventing details.";
20+
1521
export const SetPromptsOnboarding: OnboardingBody = withSuspense(
1622
({ broadcastCompletion, goToNextStep }) => {
1723
const { trieve, organization, trieveKey } = useTrieve();
@@ -47,13 +53,13 @@ export const SetPromptsOnboarding: OnboardingBody = withSuspense(
4753
useEffect(() => {
4854
if (
4955
(shopDataset.server_configuration as DatasetConfig).SYSTEM_PROMPT !=
50-
"You are a helpful assistant"
56+
DEFAULT_SYSTEM_PROMPT
5157
) {
5258
markComplete();
5359
}
5460
if (
5561
(shopDataset.server_configuration as DatasetConfig).RAG_PROMPT !=
56-
"Use the following retrieved documents to respond briefly and accurately:"
62+
DEFAULT_RAG_PROMPT
5763
) {
5864
markComplete();
5965
}
@@ -105,7 +111,7 @@ export const SetPromptsOnboarding: OnboardingBody = withSuspense(
105111
<form onSubmit={submitForm}>
106112
<TextField
107113
label="System Prompt"
108-
helpText="The system prompt to guide the RAG model"
114+
helpText="Use this prompt to set the personality, tone, and goals of the model."
109115
value={datasetSettings.SYSTEM_PROMPT ?? ""}
110116
multiline={3}
111117
onChange={(e) =>
@@ -118,8 +124,8 @@ export const SetPromptsOnboarding: OnboardingBody = withSuspense(
118124
/>
119125
<div className="h-4"></div>
120126
<TextField
121-
label="RAG Prompt"
122-
helpText="The prompt to guide the RAG model in handling retrieved context with the user query"
127+
label="Context Prompt"
128+
helpText="Use this prompt to tell the model how strictly it needs to follow or how it should generally handle the context (your product descriptions, photos, etc.)."
123129
value={datasetSettings.RAG_PROMPT ?? ""}
124130
multiline={3}
125131
onChange={(e) =>

clients/trieve-shopify-extension/app/utils/onboarding.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ type OnboardingStep = {
3535
export const onboardingSteps: OnboardingStep[] = [
3636
{
3737
id: "set-chat-messages",
38-
title: "Set AI Prompts",
38+
title: "Customize AI Prompts",
3939
defaultComplete: false,
4040
body: SetPromptsOnboarding,
41-
nextButtonText: "Setup Component",
4241
},
4342
{
4443
id: "welcome-message",

0 commit comments

Comments
 (0)