Quick Start - Retrieval
Updated as of 2023-Jun-24
Last updated
Was this helpful?
Updated as of 2023-Jun-24
Last updated
Was this helpful?
In this example, we will upload documents to a vector database so our AI chatbot can use the information. We will be uploading information from the .
Go to the and submit your OpenAI API Key.
Go to the and create an API Key.
If you have already created a chat in , skip this step.
Chats are used to organize conversational memory.
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",
"": "Example Labs Ltd"
}
response = create_chat(headers=headers, chat_data=chat_data)
print(response)
# {'reference_id': 'ac52d6a60a3b489683fd6cfda6e4abcd', 'name': 'Example Labs Ltd', 'uuid': 'ad289875-c446-4799-a017-14cda80d18c1', 'created_at': '2023-06-24T22:24:00.447256'}
const axios = require('axios');
const YOUR_DOPPLERAI_API_KEY = 'sk-...' // Replace with your API Key
const headers = { Authorization: `Bearer ${YOUR_DOPPLERAI_API_KEY}` };
// Create chat
async function createChat(headers, chatData) {
const chatsUrl = 'https://api.dopplerai.com/v1/chats';
try {
const response = await axios.post(chatsUrl, chatData, { headers: headers });
return response.data;
} catch (error) {
console.log(error);
}
}
// The reference_id and name are optional.
// If you don't need them, pass in an empty object: chatData = {}
const chatData = {
"reference_id": "ac52d6a60a3b489683fd6cfda6e4abcd",
"name": "User A"
};
createChat(headers, chatData)
.then(response => console.log(response));
// { reference_id: 'ac52d6a60a3b489683fd6cfda6e4abcd', name: 'User A', uuid: 'ad289875-c446-4799-a017-14cda80d18c1', created_at: '2023-06-24T22:24:00.447256' }
Information uploaded to the vector database are organized into collections.
import requests
YOUR_DOPPLERAI_API_KEY = 'sk-...'
headers = {'Authorization': f'Bearer {YOUR_DOPPLERAI_API_KEY}'}
def create_collection(headers, collection_data):
collections_url = 'https://api.dopplerai.com/v1/collections'
response = requests.post(collections_url, headers=headers, json=collection_data)
return response.json()
collection_data = {
"reference_id": "fb700444788d430bb39b148447af7521",
"name": "reports"
}
response = create_collection(headers=headers, collection_data=collection_data)
print(response)
# {'name': 'reports', 'reference_id': 'fb700444788d430bb39b148447af7521', 'uuid': 'e3aa752c-ede3-4c45-8088-67f0671bfc19', 'created_at': '2023-06-25T00:51:31.526000'}
const axios = require('axios');
const YOUR_DOPPLERAI_API_KEY = 'sk-...' // Replace with your API Key
const headers = { 'Authorization': `Bearer ${YOUR_DOPPLERAI_API_KEY}` };
// Create collection
async function createCollection(headers, collectionData) {
const collectionsUrl = 'https://api.dopplerai.com/v1/collections';
try {
const response = await axios.post(collectionsUrl, collectionData, { headers: headers });
return response.data;
} catch (error) {
console.log(error);
}
}
const collectionData = {
"reference_id": "fb700444788d430bb39b148447af7521",
"name": "reports"
};
createCollection(headers, collectionData)
.then(response => {
console.log(response);
});
// {'name': 'reports', 'reference_id': 'fb700444788d430bb39b148447af7521', 'uuid': 'e3aa752c-ede3-4c45-8088-67f0671bfc19', 'created_at': '2023-06-25T00:51:31.526000'}
DopplerAI provides 2 API endpoints for uploading information to the vector database.
/uploads/text
lets you upload a string.
/uploads/url
lets you upload the contents from an URL.
DopplerAI will automatically detect whether the URL is an image, PDF or a regular webpage.
If it's an image, the text from the image will be extracted and uploaded to the vector database. Max file size is 1MB.
If it's a PDF, the text from the PDF will be extracted. Max file size is 1MB.
If it's a webpage, the webpage's HTML will be extracted.
This endpoint uses text-embedding-ada-002
for embeddings. If you want to a different model, or your own fine-tuned model, please just let us know on Discord or via an email to team@dopplerai.com.
import requests
YOUR_DOPPLERAI_API_KEY = 'sk-...'
headers = {'Authorization': f'Bearer {YOUR_DOPPLERAI_API_KEY}'}
def upload_url(headers, upload_data):
uploads_url = 'https://api.dopplerai.com/v1/uploads/url'
response = requests.post(uploads_url, headers=headers, json=upload_data)
return response.json()
upload_data = {
"name": "Acute Bronchitis",
"path": 'https://www.ncbi.nlm.nih.gov/books/NBK448067',
"collection_uuid": "e3aa752c-ede3-4c45-8088-67f0671bfc19"
}
response = upload_url(headers=headers, upload_data=upload_data)
print(response)
# {'name': 'Acute Bronchitis', 'uuid': '237cc0e4-f7c5-4ab1-bc07-8fc849c0d5c3', 'created_at': '2023-06-25T02:13:53.120084', 'collection_uuid': 'e3aa752c-ede3-4c45-8088-67f0671bfc19', 'content': 'Warning: The NCBI web site requires JavaScript to function. more... ...', 'info': 'Added upload to vector database'}
const axios = require('axios');
const YOUR_DOPPLERAI_API_KEY = 'sk-...'; // Replace with your API Key
const headers = { 'Authorization': `Bearer ${YOUR_DOPPLERAI_API_KEY}` };
// Upload URL
async function uploadUrl(headers, uploadData) {
const uploadsUrl = 'https://api.dopplerai.com/v1/uploads/url';
try {
const response = await axios.post(uploadsUrl, uploadData, { headers: headers });
return response.data;
} catch (error) {
console.log(error);
}
}
const uploadData = {
"name": "Acute Bronchitis",
"path": 'https://www.ncbi.nlm.nih.gov/books/NBK448067',
"collection_uuid": "e3aa752c-ede3-4c45-8088-67f0671bfc19"
};
uploadUrl(headers, uploadData)
.then(response => {
console.log(response);
});
// { name: 'Acute Bronchitis', reference_id: null, uuid: '0d11c591-3dc7-495b-af72-0189b80147b4', created_at: '2023-06-25T20:27:38.532505', collection_uuid: 'e3aa752c-ede3-4c45-8088-67f0671bfc19', content: 'Warning: The NCBI web site requires JavaScript to function. more... ...', info: 'Added upload to vector database' }
Upload a string to the vector database.
import requests
YOUR_DOPPLERAI_API_KEY = 'sk-...'
headers = {'Authorization': f'Bearer {YOUR_DOPPLERAI_API_KEY}'}
def upload_text(headers, upload_data):
uploads_url = 'https://api.dopplerai.com/v1/uploads/text'
response = requests.post(uploads_url, headers=headers, json=upload_data)
return response.json()
content = """
Introduction
Acoustic neuroma is also called vestibular schwannoma (VS), acoustic neurinoma, vestibular neuroma or acoustic neurofibroma. These are tumors that evolve from the Schwann cell sheath and can be either intracranial or extra-axial. They usually occur adjacent to the cochlear and vestibular nerves and most often arise from the inferior division of the latter. Anatomically, acoustic neuroma tends to occupy the cerebellopontine angle. About 5-10% of cerebellopontine angle (CPA) tumors are meningiomas and may occur elsewhere in the brain. Bilateral acoustic neuromas tend to be exclusively found in individuals with type 2 neurofibromatosis.[1][2][3]
Etiology
Bilateral acoustic neuromas may be a part of neurofibromatosis type 2 occurring due to a defect on chromosome 22q12.2 at the location of the neurofibromin 2 gene which encodes merlin protein. Studies have shown that acoustic neuroma had a causative predisposition mutation. Radiation exposure may predispose a patient to the development of that condition as well.[4] Even though mobile phone radiation has been of concern, several studies have failed to prove its causative effect on vestibular schwannomas.[5]
Epidemiology
Approximately 8% of all intracranial tumors which manifest clinically are attributed to schwannomas. The majority of acoustic neuromas are unilateral and sporadic. Bilateral acoustic neuromas are in fact genetic and constitute a bit less than 5% of all schwannomas. Acoustic neuromas in general, tend to present between the fourth to sixth decades of life. Acoustic neuromas developing in individuals with neurofibromatosis type 2 (NF II) are likely to present earlier, with a peak incidence around the third decade of life. Although rare, acoustic schwannomas can occur in children. There is a small female preponderance with an aggravation of problems during pregnancy. The hereditary acoustic neuroma occurs in NF II much more often compared to neurofibromatosis type 1 (NF I), although the latter is much more common. Unilateral acoustic neuroma has been reported exclusively in 24% of cases with NF I, while bilateral acoustic schwannoma is a hallmark of NF II. Both these conditions are autosomal dominant. The defective genetic locus has been localized to chromosome 17 in NF I and chromosome 22 in NF II.[6][7]
"""
upload_data = {
"name": "Acoustic Neuroma",
"content": content,
"collection_uuid": "e3aa752c-ede3-4c45-8088-67f0671bfc19"
}
response = upload_text(headers=headers, upload_data=upload_data)
print(response)
# {'name': 'Acoustic Neuroma', 'uuid': '1d8fd24f-26f6-4e77-a7fd-84465cef55be', 'created_at': '2023-06-25T02:27:47.877907', 'collection_uuid': 'e3aa752c-ede3-4c45-8088-67f0671bfc19', 'content': 'Introduction ...', 'info': 'Added upload to vector database'}
const axios = require('axios');
const YOUR_DOPPLERAI_API_KEY = 'sk-...'; // Replace with your API Key
const headers = { 'Authorization': `Bearer ${YOUR_DOPPLERAI_API_KEY}` };
// Upload Text
async function uploadText(headers, uploadData) {
const uploadsUrl = 'https://api.dopplerai.com/v1/uploads/text';
try {
const response = await axios.post(uploadsUrl, uploadData, { headers: headers });
return response.data;
} catch (error) {
console.log(error);
}
}
const content = `
Introduction
Acoustic neuroma is also called vestibular schwannoma (VS), acoustic neurinoma, vestibular neuroma or acoustic neurofibroma. These are tumors that evolve from the Schwann cell sheath and can be either intracranial or extra-axial. They usually occur adjacent to the cochlear and vestibular nerves and most often arise from the inferior division of the latter. Anatomically, acoustic neuroma tends to occupy the cerebellopontine angle. About 5-10% of cerebellopontine angle (CPA) tumors are meningiomas and may occur elsewhere in the brain. Bilateral acoustic neuromas tend to be exclusively found in individuals with type 2 neurofibromatosis.[1][2][3]
Etiology
Bilateral acoustic neuromas may be a part of neurofibromatosis type 2 occurring due to a defect on chromosome 22q12.2 at the location of the neurofibromin 2 gene which encodes merlin protein. Studies have shown that acoustic neuroma had a causative predisposition mutation. Radiation exposure may predispose a patient to the development of that condition as well.[4] Even though mobile phone radiation has been of concern, several studies have failed to prove its causative effect on vestibular schwannomas.[5]
Epidemiology
Approximately 8% of all intracranial tumors which manifest clinically are attributed to schwannomas. The majority of acoustic neuromas are unilateral and sporadic. Bilateral acoustic neuromas are in fact genetic and constitute a bit less than 5% of all schwannomas. Acoustic neuromas in general, tend to present between the fourth to sixth decades of life. Acoustic neuromas developing in individuals with neurofibromatosis type 2 (NF II) are likely to present earlier, with a peak incidence around the third decade of life. Although rare, acoustic schwannomas can occur in children. There is a small female preponderance with an aggravation of problems during pregnancy. The hereditary acoustic neuroma occurs in NF II much more often compared to neurofibromatosis type 1 (NF I), although the latter is much more common. Unilateral acoustic neuroma has been reported exclusively in 24% of cases with NF I, while bilateral acoustic schwannoma is a hallmark of NF II. Both these conditions are autosomal dominant. The defective genetic locus has been localized to chromosome 17 in NF I and chromosome 22 in NF II.[6][7]
`;
const uploadData = {
"name": "Acoustic Neuroma",
"content": content,
"collection_uuid": "e3aa752c-ede3-4c45-8088-67f0671bfc19"
};
uploadText(headers, uploadData)
.then(response => {
console.log(response);
});
// {'name': 'Acoustic Neuroma', 'uuid': '1d8fd24f-26f6-4e77-a7fd-84465cef55be', 'created_at': '2023-06-25T02:27:47.877907', 'collection_uuid': 'e3aa752c-ede3-4c45-8088-67f0671bfc19', 'content': 'Introduction ...', 'info': 'Added upload to vector database'}
Send a message, allowing the LLM to access information from the uploaded articles.
import requests
YOUR_DOPPLERAI_API_KEY = 'sk-...'
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()
chat_uuid = "ad289875-c446-4799-a017-14cda80d18c1"
message_data = {
"message": {
"prompt": "Answer the following question:",
"content": "What is the association bewteen acoustic neuroma and neurofibromatosis?",
"chat_uuid": chat_uuid
},
"large_language_model": {
"model_name": "gpt-3.5-turbo",
"temperature": 0,
"frequency_penalty": 0.7
},
"memory": {
"memorize": False,
"remember": False
},
"vector_database": {
"collection_uuid": "e3aa752c-ede3-4c45-8088-67f0671bfc19",
"": {},
"": 3,
"": "Use the following information to answer the question. If you don't know the answer, just say that you don't know, don't try to make up an answer."
}
}
response = send_message(headers=headers, message_data=message_data)
print(response)
# { "completion":{ "id":"chatcmpl-7VA001CYpUMMrhGdSD6oyAIGcEHby", "object":"chat.completion", "created":1687660960, "model":"gpt-3.5-turbo-0301", "choices":[ { "index":0, "message":{ "role":"assistant", "content":"Acoustic neuromas may be a part of neurofibromatosis type 2 occurring due to a defect on chromosome 22q12.2 at the location of the neurofibromin 2 gene which encodes merlin protein. The hereditary acoustic neuroma occurs in NF II much more often compared to neurofibromatosis type 1 (NF I), although the latter is much more common. Unilateral acoustic neuroma has been reported exclusively in 24% of cases with NF I, while bilateral acoustic schwannoma is a hallmark of NF II. Both these conditions are autosomal dominant." }, "finish_reason":"stop" } ], "usage":{ "prompt_tokens":332, "completion_tokens":125, "total_tokens":457 } }, "uuid":"None", "created_at":"None" }
print(response['completion']['choices'][0]['message']['content'])
# Acoustic neuromas may be a part of neurofibromatosis type 2 occurring due to a defect on chromosome 22q12.2 at the location of the neurofibromin 2 gene which encodes merlin protein. The hereditary acoustic neuroma occurs in NF II much more often compared to neurofibromatosis type 1 (NF I), although the latter is much more common. Unilateral acoustic neuroma has been reported exclusively in 24% of cases with NF I, while bilateral acoustic schwannoma is a hallmark of NF II. Both these conditions are autosomal dominant.
const axios = require('axios');
const YOUR_DOPPLERAI_API_KEY = 'sk-...'; // Replace with your API Key
const headers = { 'Authorization': `Bearer ${YOUR_DOPPLERAI_API_KEY}` };
// Send Message
async function sendMessage(headers, messageData) {
const messagesUrl = 'https://api.dopplerai.com/v1/messages';
try {
const response = await axios.post(messagesUrl, messageData, { headers: headers });
return response.data;
} catch (error) {
console.log(error);
}
}
const chatUuid = "ad289875-c446-4799-a017-14cda80d18c1";
const messageData = {
"message": {
"prompt": "Answer the following question:",
"content": "What is the association between acoustic neuroma and neurofibromatosis?",
"chat_uuid": chatUuid
},
"large_language_model": {
"model_name": "gpt-3.5-turbo",
"temperature": 0,
"frequency_penalty": 0.7
},
"memory": {
"memorize": false,
"remember": false
},
"vector_database": {
"collection_uuid": "e3aa752c-ede3-4c45-8088-67f0671bfc19",
"filters": {},
"limit": 3,
"prompt": "Use the following information to answer the question. If you don't know the answer, just say that you don't know, don't try to make up an answer."
}
};
sendMessage(headers, messageData)
.then(response => {
console.log(response);
// { "completion":{ "id":"chatcmpl-7VA001CYpUMMrhGdSD6oyAIGcEHby", "object":"chat.completion", "created":1687660960, "model":"gpt-3.5-turbo-0301", "choices":[ { "index":0, "message":{ "role":"assistant", "content":"Acoustic neuromas may be a part of neurofibromatosis type 2 occurring due to a defect on chromosome 22q12.2 at the location of the neurofibromin 2 gene which encodes merlin protein. The hereditary acoustic neuroma occurs in NF II much more often compared to neurofibromatosis type 1 (NF I), although the latter is much more common. Unilateral acoustic neuroma has been reported exclusively in 24% of cases with NF I, while bilateral acoustic schwannoma is a hallmark of NF II. Both these conditions are autosomal dominant." }, "finish_reason":"stop" } ], "usage":{ "prompt_tokens":332, "completion_tokens":125, "total_tokens":457 } }, "uuid":"None", "created_at":"None" }
console.log(response.completion.choices[0].message.content);
// Acoustic neuromas may be a part of neurofibromatosis type 2 occurring due to a defect on chromosome 22q12.2 at the location of the neurofibromin 2 gene which encodes merlin protein. The hereditary acoustic neuroma occurs in NF II much more often compared to neurofibromatosis type 1 (NF I), although the latter is much more common. Unilateral acoustic neuroma has been reported exclusively in 24% of cases with NF I, while bilateral acoustic schwannoma is a hallmark of NF II. Both these conditions are autosomal dominant.
});