0.0.7 • Published 10 months ago
@braum-ai/sdk v0.0.7
TypeScript / JavaScript SDK
This is the official Braum AI SDK for TypeScript / JavaScript.
Installation
# npm
npm install @braum-ai/sdk
# yarn
yarn add @braum-ai/sdk
# pnpm
pnpm add @braum-ai/sdk
Usage
Recommend popular items
import { BraumAPI } from "@braum-ai/sdk";
const client = new BraumAPI({
apiKey: "braum_api_key",
modelId: "braum_model_id",
projectId: "braum_project_id",
});
const items = await client.recommend({
context: {
user_id: 1,
},
});
console.log(items);
// [
// {
// id: '847',
// score: 0.99,
// },
// {
// id: '1244',
// score: 0.998,
// },
// {
// id: '97714',
// score: 0.985,
// },
// ...
// ]
Recommend similar items
import { BraumAPI } from "@braum-ai/sdk";
const client = new BraumAPI({
apiKey: "braum_api_key",
modelId: "braum_model_id",
projectId: "braum_project_id",
});
const items = await client.recommendSimilar(4562, {
context: {
user_id: 1,
},
});
Sort items in personalized order
import { BraumAPI } from "@braum-ai/sdk";
const client = new BraumAPI({
apiKey: "braum_api_key",
modelId: "braum_model_id",
projectId: "braum_project_id",
});
const items = await client.sort([4562, 1245, 245], {
context: {
user_id: 1,
},
});
Find popular with filters (e.g. only recommend shoes)
import { BraumAPI } from "@braum-ai/sdk";
const items = await client.recommend({
options: {
limit: 100,
},
context: {
user_id: 1,
},
filters: [
{
query: "SELECT * FROM items WHERE type = 'shoes'",
},
],
});
Boost certain type of content (e.g. shoes)
import { BraumAPI } from "@braum-ai/sdk";
const items = await client.recommend({
options: {
limit: 100,
},
context: {
user_id: 1,
},
boosters: [
{
query:
"SELECT *, CASE type WHEN 'shoes' THEN 1.2 WHEN 'hoodies' THEN 1.5 ELSE 1 END AS factor FROM items",
},
],
});
Recommend sections (blueprints)
const sections = await client.blueprints.fetch("blueprint_id", {
context: {
variables: {
game_id_one: "asdas",
game_id_two: "asdsaa",
list_of_users: [
212, 3123, 12312, 312, 312
]
}
}
})
const items = await client.blueprints.recommend({
sections: [
{
name: "asdas",
method: "asdas",
filters: [
{
query: "SELECT * FROM items WHERE type = 'shoes'",
},
],
boosters: [
{
query: "SELECT *, CASE type WHEN 'shoes' THEN 1.2 ELSE 1 END AS factor FROM items",
}
]
options: {
limit: 10,
},
},
],
context: {
user_id: 1,
},
});