Skip to content

Latest commit

 

History

History
139 lines (98 loc) · 3.94 KB

README.md

File metadata and controls

139 lines (98 loc) · 3.94 KB
Shows the Memobase logo

User Profile-Based Memory for GenAI Apps

Memobase TypeScript and JavaScript API Library

This library provides convenient access to the Memobase REST API from TypeScript or JavaScript.

Installation

npm install @memobase/memobase

Installation from JSR

deno add jsr:@memobase/memobase
npx jsr add @memobase/memobase

Usage

The code below shows how to get started using the completions API.

import { MemoBaseClient, Blob, BlobType } from '@memobase/memobase';

const client = new MemoBaseClient(process.env['MEMOBASE_PROJECT_URL'], process.env['MEMOBASE_API_KEY'])

const main = async () => {
    const ping = await client.ping()
    console.log(ping)

    const config = await client.getConfig()
    console.log(config)

    const updateConfig = await client.updateConfig('a: 1')
    console.log(updateConfig)

    let userId = await client.addUser()
    console.log(userId)

    userId = await client.updateUser(userId, { name: 'John Doe' })
    console.log('Updated user id: ', userId)

    let user = await client.getUser(userId)
    console.log(user)

    const blobId = await user.insert(Blob.parse({
        type: BlobType.Enum.chat,
        messages: [{
            role: 'user',
            content: 'Hello, how are you? my name is John Doe'
        }]
    }))
    console.log(blobId)

    const blob = await user.get(blobId)
    console.log(blob)

    const flushSuc = await user.flush(BlobType.Enum.chat)
    console.log('Flush success: ', flushSuc)
    
    const blobs = await user.getAll(BlobType.Enum.chat)
    console.log(blobs)

    user = await client.getOrCreateUser(userId)
    console.log(user)

    const profiles = await user.profile(2000, ['Topic1'], ['SubTopic1'], 200, { Topic1: 200 })
    console.log(profiles)

    const event = await user.event(10, 1000)
    console.log(event)

    const context = await user.context(2000, 1000)
    console.log(context)

    profiles.map((profile) => {
        user.deleteProfile(profile.id).then((isDel) => {
            console.log('Delete profile success: ', isDel)
        })
    })

    const isDel = await client.deleteUser(userId)
    console.log(isDel)
}

main()

Support

Join the community for support and discussions:

Or Just email us ❤️

Contributors

This project exists thanks to all the people who contribute.

And thank you to all our backers! 🙏

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.