Examples
Every example is the same call. You name the decision, then send the context and the options that exist in your app at that moment.
Nothing in these objects is fixed by Owctopus. Add a field when your product has it. Remove a field when it does not. The options array is whatever the user can do next.
Checkout
A store sends the cart, the customer, the city, and how soon the order needs to move. The options are the shipping methods on offer, with the price and the days you want considered.
import { Owctopus } from "@owctopus/sdk";
const owctopus = new Owctopus({
apiKey: process.env.OWCTOPUS_API_KEY,
});
const result = await owctopus.decide({
decision: "shipping_method",
context: {
cartValue: 4500,
customerType: "premium",
location: "Bangalore",
deliveryUrgency: "high",
},
options: [
{ id: "standard", price: 40, deliveryDays: 4 },
{ id: "express", price: 90, deliveryDays: 2 },
{ id: "same_day", price: 180, deliveryDays: 0 },
],
});
console.log(result.decision.id);Food logging
A food app sends the day so far: calories, protein, hunger, and the last meal. The options are the meals the person can log right now. Owctopus picks one to suggest.
await owctopus.decide({
decision: "meal_suggestion",
context: {
goal: "fat_loss",
caloriesSoFar: 980,
calorieTarget: 2100,
proteinSoFar: 42,
hunger: "high",
timeOfDay: "lunch",
lastMeal: "oats",
},
options: [
{ id: "chicken_bowl", calories: 540, protein: 42 },
{ id: "salad", calories: 320, protein: 18 },
{ id: "pasta", calories: 780, protein: 24 },
],
});Tomorrow the numbers change, and the meal list can change too. Send the new context and the new options. Owctopus decides from what arrived on that request.
Workout
A training app sends sleep, steps, yesterday's session, and how many minutes are free. The options are the sessions that can start, including rest.
await owctopus.decide({
decision: "daily_workout",
context: {
goal: "fat_loss",
sleepHours: 6.7,
steps: 4820,
yesterdayWorkout: "strength",
weeklyWorkouts: 2,
targetWeeklyWorkouts: 4,
availableMinutes: 30,
},
options: [
{ id: "strength", duration: 30 },
{ id: "cardio", duration: 30 },
{ id: "mobility", duration: 20 },
{ id: "rest", duration: 0 },
],
});Same method, other products
Team size, usage, and budget, with the plans you sell.
Plan, issue, sentiment, and the queues a ticket can enter.
Budget, rating floor, and the hotels returned for this search.