Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: service suggested api (#1452)

crazywoolaa9ee18300e62
diff --git a/api/controllers/service_api/app/message.py b/api/controllers/service_api/app/message.py
index 98ba1cb44a4..614af376536 100644
--- a/api/controllers/service_api/app/message.py
+++ b/api/controllers/service_api/app/message.py
@@ -11,7 +11,7 @@ from controllers.service_api.wraps import AppApiResource
from libs.helper import TimestampField, uuid_value
from services.message_service import MessageService
from extensions.ext_database import db
-from models.model import Account, Message
+from models.model import Message, EndUser
class MessageListApi(AppApiResource):
@@ -103,24 +103,26 @@ class MessageSuggestedApi(AppApiResource):
message_id = str(message_id)
if app_model.mode != 'chat':
raise NotChatAppError()
-
try:
message = db.session.query(Message).filter(
Message.id == message_id,
Message.app_id == app_model.id,
).first()
- if end_user is None and message.from_account_id is not None:
- user = db.session.get(Account, message.from_account_id)
- elif end_user is None and message.from_end_user_id is not None:
- user = create_or_update_end_user_for_user_id(app_model, message.from_end_user_id)
+ if end_user is None and message.from_end_user_id is not None:
+ user = db.session.query(EndUser) \
+ .filter(
+ EndUser.tenant_id == app_model.tenant_id,
+ EndUser.id == message.from_end_user_id,
+ EndUser.type == 'service_api'
+ ).first()
else:
user = end_user
-
questions = MessageService.get_suggested_questions_after_answer(
app_model=app_model,
user=user,
- message_id=message_id
+ message_id=message_id,
+ check_enabled=False
)
except services.errors.message.MessageNotExistsError:
raise NotFound("Message Not Exists.")
diff --git a/web/app/components/develop/template/template_chat.zh.mdx b/web/app/components/develop/template/template_chat.zh.mdx
index 22f94d84db7..c191c9fb7c5 100644
--- a/web/app/components/develop/template/template_chat.zh.mdx
+++ b/web/app/components/develop/template/template_chat.zh.mdx
@@ -196,10 +196,10 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx'
</Col>
<Col sticky>
- <CodeGroup title="Request" tag="GET" label="/messages/{message_id}/suggested" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json'`}>
+ <CodeGroup title="Request" tag="GET" label="/messages/{message_id}/suggested" targetCode={`curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \\\n--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \\\n--header 'Content-Type: application/json'`}>
```bash {{ title: 'cURL' }}
- curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggeste' \
+ curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggested' \
--header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \
--header 'Content-Type: application/json' \
```