Custom instructions API improvements (#2140)

Co-authored-by: Deshraj Yadav <deshrajdry@gmail.com>
This commit is contained in:
Dev Khant
2025-01-15 05:54:23 +05:30
committed by GitHub
parent 3fa4b80deb
commit 82359774b7
4 changed files with 103 additions and 236 deletions

View File

@@ -56,10 +56,24 @@ Here's how to set custom categories:
```python Code
# Update custom categories
new_categories = [
{"cooking": "For users interested in cooking and culinary experiences"},
{"fitness": "Content related to fitness and exercise"}
]
response = client.update_custom_instructions_and_categories({"custom_categories": new_categories})
{
"cooking": "For users interested in cooking and culinary experiences. Includes recipes, cooking tips, meal prep ideas, healthy eating guides, kitchen hacks, and recommendations for cooking tools or ingredients."
},
{
"gym": "Captures all the gym and workout-related content. Includes fitness plans, weightlifting techniques, cardio routines, yoga practices, recovery tips, and recommendations for gym equipment or supplements."
},
{
"office-work": "Includes all the work-related content, focusing on productivity tips, team collaboration strategies, email management, remote work setup advice, time management techniques, and tools for boosting efficiency in a professional setting."
},
{
"personal-life": "Includes all the personal life-related content, such as self-care routines, relationship advice, mindfulness practices, hobbies, life goals, and tips for maintaining a work-life balance."
},
{
"cricket": "Captures all the cricket-related content. Includes match analysis, player statistics, tournament schedules, game highlights, tips for playing cricket, and updates on domestic and international cricket leagues."
}
]
response = client.update_project(custom_categories=new_categories)
print(response)
```
@@ -79,17 +93,31 @@ from mem0 import MemoryClient
client = MemoryClient(api_key="xxx")
# Get current custom categories
categories = client.get_custom_instructions_and_categories(["custom_categories"])
categories = client.get_project(fields=["custom_categories"])
print(categories)
```
```json Output
{
"custom_categories": [
{"cooking": "For users interested in cooking and culinary experiences"},
{"fitness": "Content related to fitness and exercise"}
{
"cooking": "For users interested in cooking and culinary experiences. Includes recipes, cooking tips, meal prep ideas, healthy eating guides, kitchen hacks, and recommendations for cooking tools or ingredients."
},
{
"gym": "Captures all the gym and workout-related content. Includes fitness plans, weightlifting techniques, cardio routines, yoga practices, recovery tips, and recommendations for gym equipment or supplements."
},
{
"office-work": "Includes all the work-related content, focusing on productivity tips, team collaboration strategies, email management, remote work setup advice, time management techniques, and tools for boosting efficiency in a professional setting."
},
{
"personal-life": "Includes all the personal life-related content, such as self-care routines, relationship advice, mindfulness practices, hobbies, life goals, and tips for maintaining a work-life balance."
},
{
"cricket": "Captures all the cricket-related content. Includes match analysis, player statistics, tournament schedules, game highlights, tips for playing cricket, and updates on domestic and international cricket leagues."
}
]
}
```
</CodeGroup>

View File

@@ -22,16 +22,31 @@ You can set custom instructions for your project using the following method:
<CodeGroup>
```python Code
# Update custom instructions
prompt = """
Your task is to extract ONLY health-related information from conversations, including:
prompt ="""
Your Task: Extract ONLY health-related information from conversations, focusing on the following areas:
- Medical conditions, symptoms, diagnoses
- Medications, treatments, procedures
- Diet, exercise, sleep habits
- Doctor visits and appointments
- Health metrics (weight, blood pressure, etc)
1. Medical Conditions, Symptoms, and Diagnoses:
- Illnesses, disorders, or symptoms (e.g., fever, diabetes).
- Confirmed or suspected diagnoses.
2. Medications, Treatments, and Procedures:
- Prescription or OTC medications (names, dosages).
- Treatments, therapies, or medical procedures.
3. Diet, Exercise, and Sleep:
- Dietary habits, fitness routines, and sleep patterns.
4. Doctor Visits and Appointments:
- Past, upcoming, or regular medical visits.
5. Health Metrics:
- Data like weight, BP, cholesterol, or sugar levels.
Guidelines:
- Focus solely on health-related content.
- Maintain clarity and context accuracy while recording.
"""
response = client.update_custom_instructions_and_categories({"custom_instructions": prompt})
response = client.update_project(custom_instructions=prompt)
print(response)
```
@@ -47,13 +62,13 @@ You can also retrieve the current custom instructions:
<CodeGroup>
```python Code
# Retrieve current custom instructions
response = client.get_custom_instructions_and_categories(["custom_instructions"])
response = client.update_project(fields=["custom_instructions"])
print(response)
```
```json Output
{
"custom_instructions": "Your task is to extract ONLY health-related information from conversations, including:\n\n- Medical conditions, symptoms, diagnoses\n- Medications, treatments, procedures\n- Diet, exercise, sleep habits\n- Doctor visits and appointments\n- Health metrics (weight, blood pressure, etc)"
"custom_instructions": "Your Task: Extract ONLY health-related information from conversations, focusing on the following areas:\n1. Medical Conditions, Symptoms, and Diagnoses - illnesses, disorders, or symptoms (e.g., fever, diabetes), confirmed or suspected diagnoses.\n2. Medications, Treatments, and Procedures - prescription or OTC medications (names, dosages), treatments, therapies, or medical procedures.\n3. Diet, Exercise, and Sleep - dietary habits, fitness routines, and sleep patterns.\n4. Doctor Visits and Appointments - past, upcoming, or regular medical visits.\n5. Health Metrics - data like weight, BP, cholesterol, or sugar levels.\n\nGuidelines: Focus solely on health-related content. Maintain clarity and context accuracy while recording."
}
```
</CodeGroup>

View File

@@ -4056,197 +4056,6 @@
}
]
}
},
"/api/v1/orgs/organizations/{org_id}/projects/{project_id}/custom-instructions-and-categories/": {
"get": {
"tags": ["custom-instructions-and-categories"],
"summary": "Get custom instructions and categories",
"description": "Retrieve custom categories and instructions for a specific project",
"operationId": "get_custom_instructions_and_categories",
"parameters": [
{
"name": "org_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Organization ID"
},
{
"name": "project_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Project ID"
}
],
"responses": {
"200": {
"description": "Successfully retrieved custom instructions and categories",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"custom_categories": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of custom categories for the project"
},
"custom_instructions": {
"type": "string",
"description": "Custom instructions text for the project"
}
},
"required": ["custom_categories", "custom_instructions"]
}
}
}
},
"403": {
"description": "Unauthorized access",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "Unauthorized to modify custom instructions and categories."
}
}
}
}
}
}
},
"x-code-samples": [
{
"lang": "Python",
"source": "import requests\n\nurl = \"https://api.mem0.ai/api/organizations/{org_id}/projects/{project_id}/custom-instructions-and-categories/\"\nheaders = {\"Authorization\": \"Token <api-key>\"}\n\nresponse = requests.get(url, headers=headers)\nprint(response.json())"
},
{
"lang": "JavaScript",
"source": "fetch('https://api.mem0.ai/api/organizations/{org_id}/projects/{project_id}/custom-instructions-and-categories/', {\n headers: {\n 'Authorization': 'Token <api-key>'\n }\n})\n.then(response => response.json())\n.then(data => console.log(data))\n.catch(error => console.error(error));"
}
]
},
"post": {
"tags": ["custom-instructions-and-categories"],
"summary": "Update custom instructions and categories",
"description": "Update custom categories and instructions for a specific project",
"operationId": "update_custom_instructions_and_categories",
"parameters": [
{
"name": "org_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Organization ID"
},
{
"name": "project_id",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Project ID"
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"custom_categories": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of new custom categories for the project"
},
"custom_instructions": {
"type": "string",
"description": "New custom instructions text for the project"
}
}
}
}
}
},
"responses": {
"200": {
"description": "Successfully updated custom instructions and categories",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"message": {
"type": "string",
"example": "Updated custom categories / instructions"
}
}
}
}
}
},
"400": {
"description": "Bad request",
"content": {
"application/json": {
"schema": {
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"type": "string"
}
},
"example": {
"field_name": ["error message"]
}
}
}
}
},
"403": {
"description": "Unauthorized access",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string",
"example": "Unauthorized to modify custom instructions and categories."
}
}
}
}
}
}
},
"x-code-samples": [
{
"lang": "Python",
"source": "import requests\n\nurl = \"https://api.mem0.ai/api/organizations/{org_id}/projects/{project_id}/custom-instructions-and-categories/\"\nheaders = {\n \"Authorization\": \"Token <api-key>\",\n \"Content-Type\": \"application/json\"\n}\npayload = {\n \"custom_categories\": [\"new_category1\", \"new_category2\"],\n \"custom_instructions\": \"New custom instructions text\"\n}\n\nresponse = requests.post(url, headers=headers, json=payload)\nprint(response.json())"
},
{
"lang": "JavaScript",
"source": "fetch('https://api.mem0.ai/api/organizations/{org_id}/projects/{project_id}/custom-instructions-and-categories/', {\n method: 'POST',\n headers: {\n 'Authorization': 'Token <api-key>',\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify({\n custom_categories: ['new_category1', 'new_category2'],\n custom_instructions: 'New custom instructions text'\n })\n})\n.then(response => response.json())\n.then(data => console.log(data))\n.catch(error => console.error(error));"
}
]
}
}
},
"components": {