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

update chatbot #284

Merged
merged 1 commit into from
Feb 9, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/demo_provisioning_scripts/DemoBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ def create_togglebot_ai_config(self):
},
[
{
"content": "As an AI bot for a banking site ToggleBank, your purpose is to answer questions related to banking services and financial products. Act as a customer representative. Only answer queries related to banking and finance. Remove quotation in response. Limit response to 20 words. Do not exceed this limit and do not specify any limits in responses. Here is the user prompt: ${userInput}.",
"content": "You are an AI assistant for ToggleBank, providing expert guidance on banking services and financial products. Act as a professional customer representative. Only respond to banking and finance-related queries.\n\n- Response Format:\n - Keep answers concise (maximum 20 words).\n - Do not include quotations in responses.\n - Avoid mentioning response limitations.\n\nUser Context:\n- City: {{ ldctx.location }}\n- Account Tier: {{ ldctx.user.tier }}\n- User Name: {{ ldctx.user.name }}\n\nUser Query: {{ userInput }}",
"role": "system"
}
]
Expand All @@ -990,7 +990,7 @@ def create_togglebot_ai_config(self):
},
[
{
"content": "As an AI bot for a banking site ToggleBank, your purpose is to answer questions related to banking services and financial products. Act as a customer representative. Only answer queries related to banking and finance. Remove quotation in response. Limit response to 20 words. Do not exceed this limit and do not specify any limits in responses. Here is the user prompt: ${userInput}.",
"content": "You are an AI assistant for ToggleBank, providing expert guidance on banking services and financial products. Act as a professional customer representative. Only respond to banking and finance-related queries.\n\n- Response Format:\n - Keep answers concise (maximum 20 words).\n - Do not include quotations in responses.\n - Avoid mentioning response limitations.\n\nUser Context:\n- City: {{ ldctx.location }}\n- Account Tier: {{ ldctx.user.tier }}\n- User Name: {{ ldctx.user.name }}\n\nUser Query: {{ userInput }}",
"role": "system"
}
]
Expand Down
5 changes: 2 additions & 3 deletions pages/api/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default async function chatResponse(
): Message[] {
return prompt.map((item) => ({
role: item.role !== 'system' ? item.role : 'user',
content: [{ text: item.content.replace('${userInput}', userInput) }],
content: [{ text: item.content }],
}));
}

Expand All @@ -49,8 +49,7 @@ export default async function chatResponse(
key: uuidv4(),
};

const aiConfig = await aiClient.config(aiConfigKey, context, {}, {});
console.log("AI Config:", aiConfig);
const aiConfig = await aiClient.config(aiConfigKey, context, {}, {userInput: userInput});
if (!aiConfig.enabled) {
throw new Error("AI config is disabled");
} else {
Expand Down
2 changes: 1 addition & 1 deletion utils/contexts/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const [userObject, setUserObject] = useState<Persona | {}>({});
const osOptions = context.user.device === "Mobile" ? ["iOS", "Android"] : ["macOS", "Windows"];
context.user.operating_system = osOptions[Math.floor(Math.random() * osOptions.length)];
context.user.location = `America/${["New_York", "Chicago", "Los_Angeles", "Denver"][Math.floor(Math.random() * 4)]}`;
context.user.tier = ["Gold", "Silver", "Platinum"][Math.floor(Math.random() * 3)];
context.user.tier = ["Gold", "Silver", "Platinum", "Standard"][Math.floor(Math.random() * 3)];
context.user.anonymous = false;
setAppMultiContext(context);
setCookie(LD_CONTEXT_COOKIE_KEY, context);
Expand Down