Quick Start - Memory

Updated as of 2023-Jun-24

In this example, we will create an AI chatbot with memory.

1. Add your OpenAI API key

  • Go to the Dashboard and submit your OpenAI API Key.

2. Get an API Key

3. Create a chat

  • Chats are used to organize conversational memory.

  • All POST requests can accept the optional String parameters: reference_id and name.

    • These are not used by DopplerAI. They are for your reference only.

    • You may find them useful to organize chats. For example, assigning a user id to reference_id or a category to name.

    • The only exception is the POST /messages API endpoint, which does not have those parameters.

import requests

YOUR_DOPPLERAI_API_KEY = 'sk-...' # Replace with your API Key
headers = {'Authorization': f'Bearer {YOUR_DOPPLERAI_API_KEY}'}

# Create chat
def create_chat(headers, chat_data):
    chats_url = f'https://api.dopplerai.com/v1/chats'
    response = requests.post(chats_url, headers=headers, json=chat_data)
    return response.json()

# The reference_id and name are optional.
# If you don't need them, pass in an empty hash: chat_data = {}
chat_data = {
  "": "ac52d6a60a3b489683fd6cfda6e4abcd",
  "": "Team Blue"
}

response = create_chat(headers=headers, chat_data=chat_data)

print(response)
# {'reference_id': 'ac52d6a60a3b489683fd6cfda6e4abcd', 'name': 'User A', 'uuid': 'ad289875-c446-4799-a017-14cda80d18c1', 'created_at': '2023-06-24T22:24:00.447256'}

4. Send a message with memory enabled

  • Here we send a message to the LLM with access to conversational memory.

  • You have the option to specify memory for the LLM.

    • When you set 'memorize': True, the conversation from this API request will be saved into the chat.

    • When you set 'remember': True, the LLM will be able to access past memories that were previously saved into the chat.

  • This API endpoint returns a dictionary with the following format.

    • {'completion': { ... }, 'uuid': ..., 'created_at': ...}

    • 'completion' is OpenAI's response.

    • 'uuid' and created_at are metadata from DopplerAI. These fields will return None if the memorize parameter is set to False.

import requests

YOUR_DOPPLERAI_API_KEY = 'sk-...' # Replace with your API Key
headers = {'Authorization': f'Bearer {YOUR_DOPPLERAI_API_KEY}'}

# Send message
def send_message(headers, message_data):
    messages_url = f'https://api.dopplerai.com/v1/messages'
    response = requests.post(messages_url, headers=headers, json=message_data)
    return response.json()

 = "ad289875-c446-4799-a017-14cda80d18c1"

message_data = {
  "message": {
    "prompt": "Generate a differential diagnosis for the following patient: ",
    "content": "33-year-old female presents with shortness of breath on exertion. She was seen as an outpatient six months ago",
    "chat_uuid": chat_uuid
  },
  "large_language_model": {
    "model_name": "gpt-3.5-turbo",
    "temperature": 0,
    "frequency_penalty": 0.7
  },
  "memory": {
    "": True,
    "": True
  }
}

response = send_message(headers=headers, message_data=message_data)

print(response)
# {'completion': {'id': 'chatcmpl-7V7bQoY3hmwDmjtNd0ynsi7wkI5O8', 'object': 'chat.completion', 'created': 1687651748, 'model': 'gpt-3.5-turbo-0301', 'choices': [{'index': 0, 'message': {'role': 'assistant', 'content': '1. Asthma\n2. Chronic obstructive pulmonary disease (COPD)\n3. Pulmonary embolism\n4. Pneumonia\n5. Interstitial lung disease\n6. Cardiac disease (e.g., heart failure, coronary artery disease)\n7. Anemia\n8. Anxiety or panic disorder \n9. Obesity hypoventilation syndrome \n10. Pulmonary hypertension \n11. Lung cancer \n12. Pleural effusion \n13. Bronchiectasis'}, 'finish_reason': 'stop'}], 'usage': {'prompt_tokens': 46, 'completion_tokens': 99, 'total_tokens': 145}}, 'uuid': None, 'created_at': None}

print(response['completion']['choices'][0]['message']['content'])
# 1. Asthma\n2. Chronic obstructive pulmonary disease (COPD)\n3. Pulmonary embolism\n4. Pneumonia\n5. Interstitial lung disease\n6. Cardiac disease (e.g., heart failure, coronary artery disease)\n7. Anemia\n8. Anxiety or panic disorder \n9. Obesity hypoventilation syndrome \n10. Pulmonary hypertension \n11. Lung cancer \n12. Pleural effusion \n13. Bronchiectasis

Last updated

Was this helpful?