Because SID Memory intentionally mirrors the OpenAI API, you can use the same packages to access it. Below are some examples of how to use the OpenAI Python and JavaScript packages to call the SID Memory API.

There are only two changes needed to use the OpenAI packages with SID Memory:

  • The base URL should be set to https://api.sid.ai/v1/memory
  • Query parameters should be passed in the extra_query or query parameter, respectively

The SID Memory API also supports streaming, just like the OpenAI API.

Python

from openai import OpenAI
import os

client = OpenAI(
    api_key=os.getenv('SID_API_KEY'),
    base_url='https://api.sid.ai/v1/memory',
)

res = client.chat.completions.create(
    extra_query={
        "namespace": "",
        "commit_after": 30,
    },
    messages=[{
        "role": "user",
        "content": "Hi, how are you?",
    }],
    model="gpt-3.5-turbo",
)

print(res)

JavaScript

import OpenAI from "openai";

const openai = new OpenAI({
    apiKey: process.env.SID_API_KEY,
    baseURL: 'https://api.sid.ai/v1/memory',
})

let response = await openai.chat.completions.create({
    model: "gpt-3.5-turbo",
    messages: [{
        "role": "user",
        "content": "Hi, how are you?",
    }],
}, {
    query: {
        "namespace": "",
        "commit_after": "30",
    }
});

console.log(response);

Was this page helpful?