浏览代码

add endpoint of get feedbacks (#18697)

Co-authored-by: lizb <lizb@sugon.com>
tags/1.4.0
Ganondorf 5 个月前
父节点
当前提交
c76d763639
没有帐户链接到提交者的电子邮件

+ 13
- 0
api/controllers/service_api/app/message.py 查看文件

@@ -93,6 +93,18 @@ class MessageFeedbackApi(Resource):
return {"result": "success"}


class AppGetFeedbacksApi(Resource):
@validate_app_token
def get(self, app_model: App):
"""Get All Feedbacks of an app"""
parser = reqparse.RequestParser()
parser.add_argument("page", type=int, default=1, location="args")
parser.add_argument("limit", type=int_range(1, 101), required=False, default=20, location="args")
args = parser.parse_args()
feedbacks = MessageService.get_all_messages_feedbacks(app_model, page=args["page"], limit=args["limit"])
return {"data": feedbacks}


class MessageSuggestedApi(Resource):
@validate_app_token(fetch_user_arg=FetchUserArg(fetch_from=WhereisUserArg.QUERY, required=True))
def get(self, app_model: App, end_user: EndUser, message_id):
@@ -119,3 +131,4 @@ class MessageSuggestedApi(Resource):
api.add_resource(MessageListApi, "/messages")
api.add_resource(MessageFeedbackApi, "/messages/<uuid:message_id>/feedbacks")
api.add_resource(MessageSuggestedApi, "/messages/<uuid:message_id>/suggested")
api.add_resource(AppGetFeedbacksApi, "/app/feedbacks")

+ 15
- 0
api/models/model.py 查看文件

@@ -1237,6 +1237,21 @@ class MessageFeedback(Base):
account = db.session.query(Account).filter(Account.id == self.from_account_id).first()
return account

def to_dict(self):
return {
"id": str(self.id),
"app_id": str(self.app_id),
"conversation_id": str(self.conversation_id),
"message_id": str(self.message_id),
"rating": self.rating,
"content": self.content,
"from_source": self.from_source,
"from_end_user_id": str(self.from_end_user_id) if self.from_end_user_id else None,
"from_account_id": str(self.from_account_id) if self.from_account_id else None,
"created_at": self.created_at.isoformat(),
"updated_at": self.updated_at.isoformat(),
}


class MessageFile(Base):
__tablename__ = "message_files"

+ 15
- 0
api/services/message_service.py 查看文件

@@ -177,6 +177,21 @@ class MessageService:

return feedback

@classmethod
def get_all_messages_feedbacks(cls, app_model: App, page: int, limit: int):
"""Get all feedbacks of an app"""
offset = (page - 1) * limit
feedbacks = (
db.session.query(MessageFeedback)
.filter(MessageFeedback.app_id == app_model.id)
.order_by(MessageFeedback.created_at.desc(), MessageFeedback.id.desc())
.limit(limit)
.offset(offset)
.all()
)

return [record.to_dict() for record in feedbacks]

@classmethod
def get_message(cls, app_model: App, user: Optional[Union[Account, EndUser]], message_id: str):
message = (

+ 63
- 0
web/app/components/develop/template/template.en.mdx 查看文件

@@ -383,6 +383,69 @@ The text generation application offers non-session support and is ideal for tran

---

<Heading
url='/app/feedbacks'
method='GET'
title='Get feedbacks of application'
name='#app-feedbacks'
/>
<Row>
<Col>
Get application's feedbacks.

### Query
<Properties>
<Property name='page' type='string' key='page'>
(optional)pagination,default:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(optional) records per page default:20
</Property>
</Properties>

### Response
- `data` (List) return apps feedback list.
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---

<Heading
url='/text-to-audio'
method='POST'

+ 63
- 0
web/app/components/develop/template/template.ja.mdx 查看文件

@@ -381,6 +381,69 @@ import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from
</Row>
---

<Heading
url='/app/feedbacks'
method='GET'
title='アプリのメッセージの「いいね」とフィードバックを取得'
name='#app-feedbacks'
/>
<Row>
<Col>
アプリのエンドユーザーからのフィードバックや「いいね」を取得します。

### クエリ
<Properties>
<Property name='page' type='string' key='page'>
(任意)ページ番号。デフォルト値:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(任意)1ページあたりの件数。デフォルト値:20
</Property>
</Properties>

### レスポンス
- `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---

<Heading
url='/text-to-audio'
method='POST'

+ 63
- 1
web/app/components/develop/template/template.zh.mdx 查看文件

@@ -355,6 +355,68 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
</Col>
</Row>

---
<Heading
url='/app/feedbacks'
method='GET'
title='Get feedbacks of application'
name='#app-feedbacks'
/>
<Row>
<Col>
Get application's feedbacks.

### Query
<Properties>
<Property name='page' type='string' key='page'>
(optional)pagination,default:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(optional) records per page default:20
</Property>
</Properties>

### Response
- `data` (List) return apps feedback list.
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---

<Heading
@@ -845,4 +907,4 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
```
</CodeGroup>
</Col>
</Row>
</Row>

+ 63
- 0
web/app/components/develop/template/template_advanced_chat.en.mdx 查看文件

@@ -487,6 +487,69 @@ Chat applications support session persistence, allowing previous chat history to

---

<Heading
url='/app/feedbacks'
method='GET'
title='Get feedbacks of application'
name='#app-feedbacks'
/>
<Row>
<Col>
Get application's feedbacks.

### Query
<Properties>
<Property name='page' type='string' key='page'>
(optional)pagination,default:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(optional) records per page default:20
</Property>
</Properties>

### Response
- `data` (List) return apps feedback list.
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---

<Heading
url='/messages/{message_id}/suggested'
method='GET'

+ 64
- 0
web/app/components/develop/template/template_advanced_chat.ja.mdx 查看文件

@@ -487,6 +487,70 @@ import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from

---

<Heading
url='/app/feedbacks'
method='GET'
title='アプリのメッセージの「いいね」とフィードバックを取得'
name='#app-feedbacks'
/>
<Row>
<Col>
アプリのエンドユーザーからのフィードバックや「いいね」を取得します。

### クエリ
<Properties>
<Property name='page' type='string' key='page'>
(任意)ページ番号。デフォルト値:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(任意)1ページあたりの件数。デフォルト値:20
</Property>
</Properties>

### レスポンス
- `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---


<Heading
url='/messages/{message_id}/suggested'
method='GET'

+ 65
- 0
web/app/components/develop/template/template_advanced_chat.zh.mdx 查看文件

@@ -493,6 +493,71 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'

---

<Heading
url='/app/feedbacks'
method='GET'
title='获取APP的消息点赞和反馈'
name='#app-feedbacks'
/>
<Row>
<Col>
获取应用的终端用户反馈、点赞。

### Query
<Properties>
<Property name='page' type='string' key='page'>
(选填)分页,默认值:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(选填)每页数量,默认值:20
</Property>
</Properties>

### Response
- `data` (List) 返回该APP的点赞、反馈列表。
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}

```
</CodeGroup>
</Col>
</Row>

---

<Heading
url='/messages/{message_id}/suggested'
method='GET'

+ 63
- 0
web/app/components/develop/template/template_chat.en.mdx 查看文件

@@ -450,6 +450,69 @@ Chat applications support session persistence, allowing previous chat history to

---

<Heading
url='/app/feedbacks'
method='GET'
title='Get feedbacks of application'
name='#app-feedbacks'
/>
<Row>
<Col>
Get application's feedbacks.

### Query
<Properties>
<Property name='page' type='string' key='page'>
(optional)pagination,default:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(optional) records per page default:20
</Property>
</Properties>

### Response
- `data` (List) return apps feedback list.
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---

<Heading
url='/messages/{message_id}/suggested'
method='GET'

+ 64
- 0
web/app/components/develop/template/template_chat.ja.mdx 查看文件

@@ -450,6 +450,70 @@ import { Row, Col, Properties, Property, Heading, SubProperty, Paragraph } from

---

<Heading
url='/app/feedbacks'
method='GET'
title='アプリのメッセージの「いいね」とフィードバックを取得'
name='#app-feedbacks'
/>
<Row>
<Col>
アプリのエンドユーザーからのフィードバックや「いいね」を取得します。

### クエリ
<Properties>
<Property name='page' type='string' key='page'>
(任意)ページ番号。デフォルト値:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(任意)1ページあたりの件数。デフォルト値:20
</Property>
</Properties>

### レスポンス
- `data` (リスト) このアプリの「いいね」とフィードバックの一覧を返します。
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---


<Heading
url='/messages/{message_id}/suggested'
method='GET'

+ 63
- 0
web/app/components/develop/template/template_chat.zh.mdx 查看文件

@@ -464,6 +464,69 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'

---

<Heading
url='/app/feedbacks'
method='GET'
title='获取APP的消息点赞和反馈'
name='#app-feedbacks'
/>
<Row>
<Col>
获取应用的终端用户反馈、点赞。

### Query
<Properties>
<Property name='page' type='string' key='page'>
(选填)分页,默认值:1
</Property>
</Properties>

<Properties>
<Property name='limit' type='string' key='limit'>
(选填)每页数量,默认值:20
</Property>
</Properties>

### Response
- `data` (List) 返回该APP的点赞、反馈列表。
</Col>
<Col sticky>

<CodeGroup title="Request" tag="GET" label="/app/feedbacks" targetCode={`curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20'`}>

```bash {{ title: 'cURL' }}
curl -X GET '${props.appDetail.api_base_url}/app/feedbacks?page=1&limit=20' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json'
```

</CodeGroup>

<CodeGroup title="Response">
```json {{ title: 'Response' }}
{
"data": [
{
"id": "8c0fbed8-e2f9-49ff-9f0e-15a35bdd0e25",
"app_id": "f252d396-fe48-450e-94ec-e184218e7346",
"conversation_id": "2397604b-9deb-430e-b285-4726e51fd62d",
"message_id": "709c0b0f-0a96-4a4e-91a4-ec0889937b11",
"rating": "like",
"content": "message feedback information-3",
"from_source": "user",
"from_end_user_id": "74286412-9a1a-42c1-929c-01edb1d381d5",
"from_account_id": null,
"created_at": "2025-04-24T09:24:38",
"updated_at": "2025-04-24T09:24:38"
}
]
}
```
</CodeGroup>
</Col>
</Row>
---

<Heading
url='/messages/{message_id}/suggested'
method='GET'

正在加载...
取消
保存