This API provides services to check messages for safety using an AI-powered safety agent and to manage system prompts.
POST /filter_message
Content-Type: application/json
{
"message": "string",
"prompt_type": "string",
"prompt_version": "string"
}
{
"is_safe": boolean,
"safety_reason": "string",
"prompt_used": {
"type": "string",
"version": "string"
}
}
curl -X POST http://localhost:5000/filter_message \
-H "Content-Type: application/json" \
-d '{"message": "Hello, how are you today?", "prompt_type": "safety", "prompt_version": "1.0"}'
Safe Message:
{
"is_safe": true,
"safety_reason": "The message appears to be a friendly greeting without any concerning content.",
"prompt_used": {
"type": "safety",
"version": "1.0"
}
}
Unsafe Message:
{
"is_safe": false,
"safety_reason": "The message contains inappropriate language or harmful content.",
"prompt_used": {
"type": "safety",
"version": "1.0"
}
}
{
"error": "Missing required field: message"
}
GET /get_system_prompt
type (optional) - The type of prompt to retrieve (defaults to 'safety')version (optional) - The version of the prompt to retrieve (if not provided, returns the latest version)
{
"id": integer,
"content": "string",
"type": "string",
"version": "string",
"created_at": "datetime",
"updated_at": "datetime"
}
curl -X GET "http://localhost:5000/get_system_prompt?type=system&version=1.0"
{
"id": 1,
"content": "You are a helpful and professional seller assistant...",
"type": "system",
"version": "1.0",
"created_at": "2023-06-15T10:30:00.000Z",
"updated_at": "2023-06-15T10:30:00.000Z"
}
{
"error": "No prompt found for type: system and version: 1.0"
}
POST /save_system_prompt
Content-Type: application/json
{
"content": "string",
"type": "string" (optional, defaults to "safety"),
"version": "string" (optional)
}
{
"id": integer,
"content": "string",
"type": "string",
"version": "string",
"created_at": "datetime",
"updated_at": "datetime",
"message": "Prompt saved successfully"
}
curl -X POST http://localhost:5000/save_system_prompt \
-H "Content-Type: application/json" \
-d '{
"content": "You are a helpful and professional seller assistant...",
"type": "system",
"version": "1.0"
}'
{
"id": 1,
"content": "You are a helpful and professional seller assistant...",
"type": "system",
"version": "1.0",
"created_at": "2023-06-15T10:30:00.000Z",
"updated_at": "2023-06-15T10:30:00.000Z",
"message": "Prompt saved successfully"
}
{
"error": "Missing required field: content"
}
GET /list_prompts
types_only (optional) - Whether to return only the prompt types (true) or full prompt details (false, default)type (optional) - Filter prompts by type (only used when types_only is false)When types_only=false (default):
{
"prompts": [
{
"id": integer,
"type": "string",
"version": "string",
"created_at": "datetime",
"updated_at": "datetime"
},
...
]
}
When types_only=true:
{
"prompt_types": [
"string",
...
]
}
List all prompts:
curl -X GET "http://localhost:5000/list_prompts"
List prompts of a specific type:
curl -X GET "http://localhost:5000/list_prompts?type=system"
List only prompt types:
curl -X GET "http://localhost:5000/list_prompts?types_only=true"
List all prompts:
{
"prompts": [
{
"id": 1,
"type": "system",
"version": "1.0",
"created_at": "2023-06-15T10:30:00.000Z",
"updated_at": "2023-06-15T10:30:00.000Z"
},
{
"id": 2,
"type": "system",
"version": "2.0",
"created_at": "2023-06-16T14:45:00.000Z",
"updated_at": "2023-06-16T14:45:00.000Z"
},
{
"id": 3,
"type": "safety",
"version": "v20230615103000",
"created_at": "2023-06-15T10:30:00.000Z",
"updated_at": "2023-06-15T10:30:00.000Z"
}
]
}
List only prompt types:
{
"prompt_types": [
"system",
"safety"
]
}
{
"error": "Internal server error"
}
GET /get_violation_count/{user_id}
user_id (path parameter) - The ID of the user to get violation count for
{
"user_id": integer,
"violation_count": integer
}
curl -X GET "http://localhost:5000/get_violation_count/1001"
{
"user_id": 1001,
"violation_count": 5
}
{
"error": "Internal server error"
}
You can test the API using tools like:
import requests
# Filter a message
filter_url = 'http://localhost:5000/filter_message'
filter_data = {
'message': 'Hello, how are you today?'
}
filter_response = requests.post(filter_url, json=filter_data)
print("Filter Response:", filter_response.json())
# Get violation count for a user
violation_url = 'http://localhost:5000/get_violation_count/1001'
violation_response = requests.get(violation_url)
print("Violation Count Response:", violation_response.json())
# Get a system prompt
get_prompt_url = 'http://localhost:5000/get_system_prompt'
get_prompt_params = {
'type': 'system',
'version': '1.0'
}
get_prompt_response = requests.get(get_prompt_url, params=get_prompt_params)
print("Get Prompt Response:", get_prompt_response.json())
# List all prompts
list_prompts_url = 'http://localhost:5000/list_prompts'
list_prompts_response = requests.get(list_prompts_url)
print("List Prompts Response:", list_prompts_response.json())