mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Feat: add 'delete' for agent's sessions api and unify apis of agent sdk (#5525)
### What problem does this PR solve? Add sessions deletion support for agent in http and python api ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [x] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
@ -2914,6 +2914,62 @@ Failure:
|
||||
|
||||
---
|
||||
|
||||
### Delete agent's sessions
|
||||
|
||||
**DELETE** `/api/v1/agents/{agent_id}/sessions`
|
||||
|
||||
Deletes sessions of a agent by ID.
|
||||
|
||||
#### Request
|
||||
|
||||
- Method: DELETE
|
||||
- URL: `/api/v1/agents/{agent_id}/sessions`
|
||||
- Headers:
|
||||
- `'content-Type: application/json'`
|
||||
- `'Authorization: Bearer <YOUR_API_KEY>'`
|
||||
- Body:
|
||||
- `"ids"`: `list[string]`
|
||||
|
||||
##### Request example
|
||||
|
||||
```bash
|
||||
curl --request DELETE \
|
||||
--url http://{address}/api/v1/agents/{agent_id}/sessions \
|
||||
--header 'Content-Type: application/json' \
|
||||
--header 'Authorization: Bearer <YOUR_API_KEY>' \
|
||||
--data '
|
||||
{
|
||||
"ids": ["test_1", "test_2"]
|
||||
}'
|
||||
```
|
||||
|
||||
##### Request Parameters
|
||||
|
||||
- `agent_id`: (*Path parameter*)
|
||||
The ID of the associated agent.
|
||||
- `"ids"`: (*Body Parameter*), `list[string]`
|
||||
The IDs of the sessions to delete. If it is not specified, all sessions associated with the specified agent will be deleted.
|
||||
|
||||
#### Response
|
||||
|
||||
Success:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 0
|
||||
}
|
||||
```
|
||||
|
||||
Failure:
|
||||
|
||||
```json
|
||||
{
|
||||
"code": 102,
|
||||
"message": "The agent doesn't own the session cbd31e52f73911ef93b232903b842af6"
|
||||
}
|
||||
```
|
||||
---
|
||||
|
||||
## AGENT MANAGEMENT
|
||||
|
||||
---
|
||||
|
||||
@ -1460,21 +1460,13 @@ while True:
|
||||
### Create session with agent
|
||||
|
||||
```python
|
||||
Agent.create_session(id,rag, **kwargs) -> Session
|
||||
Agent.create_session(**kwargs) -> Session
|
||||
```
|
||||
|
||||
Creates a session with the current agent.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### id: `str`, *Required*
|
||||
|
||||
The id of agent
|
||||
|
||||
##### rag:`RAGFlow object`
|
||||
|
||||
The RAGFlow object
|
||||
|
||||
##### **kwargs
|
||||
|
||||
The parameters in `begin` component.
|
||||
@ -1494,7 +1486,8 @@ from ragflow_sdk import RAGFlow, Agent
|
||||
|
||||
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
||||
AGENT_ID = "AGENT_ID"
|
||||
session = Agent.create_session(AGENT_ID, rag_object)
|
||||
agent = rag_object.list_agents(id = AGENT_id)[0]
|
||||
session = agent.create_session()
|
||||
```
|
||||
|
||||
---
|
||||
@ -1571,7 +1564,8 @@ from ragflow_sdk import RAGFlow, Agent
|
||||
|
||||
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
||||
AGENT_id = "AGENT_ID"
|
||||
session = Agent.create_session(AGENT_id, rag_object)
|
||||
agent = rag_object.list_agents(id = AGENT_id)[0]
|
||||
session = agent.create_session()
|
||||
|
||||
print("\n===== Miss R ====\n")
|
||||
print("Hello. What can I do for you?")
|
||||
@ -1592,8 +1586,6 @@ while True:
|
||||
|
||||
```python
|
||||
Agent.list_sessions(
|
||||
agent_id,
|
||||
rag
|
||||
page: int = 1,
|
||||
page_size: int = 30,
|
||||
orderby: str = "update_time",
|
||||
@ -1640,11 +1632,42 @@ The ID of the agent session to retrieve. Defaults to `None`.
|
||||
from ragflow_sdk import RAGFlow
|
||||
|
||||
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
||||
agent_id = "2710f2269b4611ef8fdf0242ac120006"
|
||||
sessions=Agent.list_sessions(agent_id,rag_object)
|
||||
AGENT_id = "AGENT_ID"
|
||||
agent = rag_object.list_agents(id = AGENT_id)[0]
|
||||
sessons = agent.list_sessions()
|
||||
for session in sessions:
|
||||
print(session)
|
||||
```
|
||||
---
|
||||
### Delete agent's sessions
|
||||
|
||||
```python
|
||||
Agent.delete_sessions(ids: list[str] = None)
|
||||
```
|
||||
|
||||
Deletes sessions of a agent by ID.
|
||||
|
||||
#### Parameters
|
||||
|
||||
##### ids: `list[str]`
|
||||
|
||||
The IDs of the sessions to delete. Defaults to `None`. If it is not specified, all sessions associated with the agent will be deleted.
|
||||
|
||||
#### Returns
|
||||
|
||||
- Success: No value is returned.
|
||||
- Failure: `Exception`
|
||||
|
||||
#### Examples
|
||||
|
||||
```python
|
||||
from ragflow_sdk import RAGFlow
|
||||
|
||||
rag_object = RAGFlow(api_key="<YOUR_API_KEY>", base_url="http://<YOUR_BASE_URL>:9380")
|
||||
AGENT_id = "AGENT_ID"
|
||||
agent = rag_object.list_agents(id = AGENT_id)[0]
|
||||
agent.delete_sessions(ids=["id_1","id_2"])
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user