发送消息
接口说明
用户向AI发送消息并获取回复。
请求信息
- Method:
POST - Path:
/v1/conversations/messages - 认证: 需要
请求参数
json
{
"content": "string" // 消息内容,1-2000个字符
}响应字段说明
| 字段 | 类型 | 说明 |
|---|---|---|
| emotion | string | AI当前情绪(happy/sad/angry/neutral/surprised/fearful/disgusted) |
| location | string | AI当前位置(classroom/campus/bedroom) |
| time_period | string | 当前时间段(day/afternoon/night) |
| added_points | int | 本次获得的亲密度点数 |
| current_intimacy | int | 当前总亲密度点数 |
| current_level | string | 当前等级名称 |
| level_changed | bool | 是否升级 |
| relationship_status | string | 关系状态(normal/lover) |
响应示例
json
{
"code": 0,
"message": "success",
"data": {
"message_id": "550e8400-e29b-41d4-a716-446655440000",
"conversation_id": "770e8400-e29b-41d4-a716-446655440000",
"user_message": "你好,今天过得怎么样?",
"ai_response": "见到你真开心!我今天过得很充实,一直在思考我们之间的对话...",
"emotion": "happy",
"location": "classroom",
"time_period": "day",
"added_points": 1,
"current_intimacy": 101,
"current_level": "陌生人",
"level_changed": false,
"relationship_status": "normal",
"created_at": "2025-10-03T12:30:00Z"
}
}错误情况
- 401: 未认证
- 400: 消息内容为空或超长
- 429: 发送过于频繁
- 500: AI服务异常
示例代码
bash
curl -X POST http://localhost:8081/v1/conversations/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-d '{
"content": "你好!今天过得怎么样?"
}'javascript
const response = await fetch('http://localhost:8081/v1/conversations/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`
},
body: JSON.stringify({
content: '你好!今天过得怎么样?'
})
});
const data = await response.json();
console.log(data.data.ai_response);python
import requests
response = requests.post(
'http://localhost:8081/v1/conversations/messages',
headers={
'Authorization': f'Bearer {access_token}'
},
json={
'content': '你好!今天过得怎么样?'
}
)
data = response.json()
print(data['data']['ai_response'])