Code examples for integrating MotionOS into your applications
import { MotionOS } from '@motionos/sdk';
const motion = new MotionOS({
apiKey: 'sb_secret_xxx',
projectId: 'proj-123'
});
await motion.ingest('User prefers dark mode');
const ctx = await motion.retrieve('user preferences');import { MotionOS } from '@motionos/sdk';
import OpenAI from 'openai';
const motion = new MotionOS({
apiKey: process.env.MOTIONOS_API_KEY!,
projectId: process.env.MOTIONOS_PROJECT_ID!
});
async function chat(message: string) {
await motion.ingest({ rawText: message });
const ctx = await motion.retrieve({ query: message });
const response = await openai.chat.completions.create({
messages: [
{ role: 'system', content: `Context: ${ctx.context}` },
{ role: 'user', content: message }
]
});
return response.choices[0].message.content;
}'use server';
import { MotionOS } from '@motionos/sdk';
const motion = new MotionOS({
apiKey: process.env.MOTIONOS_API_KEY!,
projectId: process.env.MOTIONOS_PROJECT_ID!
});
export async function storeMemory(text: string) {
const result = await motion.ingest({ rawText: text });
return { success: true, id: result.memoryId };
}