Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in agent api and update api document #3996

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def run(self, **kwargs):
self.path.append(["begin"])

self.path.append([])
print(self.path,flush=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(self.path,flush=True)

ran = -1
waiting = []
without_dependent_checking = []
Expand Down
31 changes: 29 additions & 2 deletions api/apps/sdk/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,15 @@ def update(tenant_id, chat_id, session_id):
@token_required
def chat_completion(tenant_id, chat_id):
req = request.json
if not req:
req = {"question":""}
if not DialogService.query(tenant_id=tenant_id,id=chat_id,status=StatusEnum.VALID.value):
return get_error_data_result(f"You don't own the chat {chat_id}")
if req.get("session_id"):
if not ConversationService.query(id=req["session_id"],dialog_id=chat_id):
return get_error_data_result(f"You don't own the session {req['session_id']}")
if not req.get("session_id"):
req["question"]=""
if req.get("stream", True):
resp = Response(rag_completion(tenant_id, chat_id, **req), mimetype="text/event-stream")
resp.headers.add_header("Cache-control", "no-cache")
Expand All @@ -138,11 +142,34 @@ def chat_completion(tenant_id, chat_id):
@token_required
def agent_completions(tenant_id, agent_id):
req = request.json
if not UserCanvasService.query(user_id=tenant_id,id=agent_id):
if not req:
req = {"question":""}
cvs= UserCanvasService.query(user_id=tenant_id,id=agent_id)
if not cvs:
return get_error_data_result(f"You don't own the agent {agent_id}")
if req.get("session_id"):
if not API4ConversationService.query(id=req["session_id"],dialog_id=agent_id):
conv = API4ConversationService.query(id=req["session_id"], dialog_id=agent_id)
if not conv :
return get_error_data_result(f"You don't own the session {req['session_id']}")
try:
temp = cvs.dsl["components"]["begin"]["obj"]["params"]["query"]
if req.get("question"):
return get_error_data_result("`question` can't be provided")
except Exception:
pass
if not req.get("session_id"):
req["question"]=""
cvs = cvs[0]
try:
query = cvs.dsl["components"]["begin"]["obj"]["params"]["query"]
for ele in query:
if not req.get(ele["name"]):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not req.get(ele["name"]):
if not req.get(ele["key"]):

return get_error_data_result(f"`{ele['name']}` is required")
ele["value"]=req[ele['name']]
except Exception:
pass
cvs = cvs.to_dict()
UserCanvasService.update_by_id(agent_id, cvs)
if req.get("stream", True):
resp = Response(agent_completion(tenant_id, agent_id, **req), mimetype="text/event-stream")
resp.headers.add_header("Cache-control", "no-cache")
Expand Down
2 changes: 1 addition & 1 deletion api/db/services/canvas_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def completion(tenant_id, agent_id, question, session_id=None, stream=True, **kw
conv.reference.append({"chunks": [], "doc_aggs": []})

final_ans = {"reference": [], "content": ""}

canvas.reset()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
canvas.reset()

if stream:
try:
for ans in canvas.run(stream=stream):
Expand Down
3 changes: 2 additions & 1 deletion api/db/services/conversation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ def completion(tenant_id, chat_id, question, name="New session", session_id=None
assert dia, "You do not own the chat."

if not session_id:
session_id = get_uuid()
conv = {
"id": get_uuid(),
"id":session_id ,
"dialog_id": chat_id,
"name": name,
"message": [{"role": "assistant", "content": dia[0].prompt_config.get("prologue")}]
Expand Down
93 changes: 89 additions & 4 deletions docs/references/http_api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2159,16 +2159,101 @@ Success:
{
"code": 0,
"data": {
"agent_id": "2e45b5209c1011efa3e90242ac120006",
"id": "7869e9e49c1711ef92840242ac120006",
"agent_id": "b4a39922b76611efaa1a0242ac120006",
"dsl": {
"answer": [],
"components": {
"Answer:GreenReadersDrum": {
"downstream": [],
"obj": {
"component_name": "Answer",
"inputs": [],
"output": null,
"params": {}
},
"upstream": []
},
"begin": {
"downstream": [],
"obj": {
"component_name": "Begin",
"inputs": [],
"output": {},
"params": {}
},
"upstream": []
}
},
"embed_id": "",
"graph": {
"edges": [],
"nodes": [
{
"data": {
"label": "Begin",
"name": "begin"
},
"dragging": false,
"height": 44,
"id": "begin",
"position": {
"x": 53.25688640427177,
"y": 198.37155679786412
},
"positionAbsolute": {
"x": 53.25688640427177,
"y": 198.37155679786412
},
"selected": false,
"sourcePosition": "left",
"targetPosition": "right",
"type": "beginNode",
"width": 200
},
{
"data": {
"form": {},
"label": "Answer",
"name": "对话_0"
},
"dragging": false,
"height": 44,
"id": "Answer:GreenReadersDrum",
"position": {
"x": 360.43473114516974,
"y": 207.29298425089348
},
"positionAbsolute": {
"x": 360.43473114516974,
"y": 207.29298425089348
},
"selected": false,
"sourcePosition": "right",
"targetPosition": "left",
"type": "logicNode",
"width": 200
}
]
},
"history": [],
"messages": [],
"path": [
[
"begin"
],
[]
],
"reference": []
},
"id": "2581031eb7a311efb5200242ac120005",
"message": [
{
"content": "Hello! I am a recruiter at InfiniFlow. I learned that you are an expert in the field, and took the liberty of reaching out to you. There is an opportunity I would like to share with you. RAGFlow is currently looking for a senior engineer for your position. I was wondering if you might be interested?",
"content": "Hi! I'm your smart assistant. What can I do for you?",
"role": "assistant"
}
],
"source": "agent",
"user_id": ""
"user_id": "69736c5e723611efb51b0242ac120007"
}
}
```
Expand Down
7 changes: 7 additions & 0 deletions docs/references/python_api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Dataset Management
:::

---
### Install the RAGFlow SDK

To install the RAGFlow SDK, run the following command in your terminal:

```bash
pip install ragflow-sdk
```

## Create dataset

Expand Down
Loading