diff --git a/api/controllers/console/app/message.py b/api/controllers/console/app/message.py index d6f9172e57..3f2947b0a3 100644 --- a/api/controllers/console/app/message.py +++ b/api/controllers/console/app/message.py @@ -295,8 +295,8 @@ class MessageSuggestedQuestionApi(Resource): try: questions = MessageService.get_suggested_questions_after_answer( app_model=app_model, - user=current_user, message_id=message_id, + user=current_user, check_enabled=False ) except MessageNotExistsError: diff --git a/api/controllers/service_api/app/conversation.py b/api/controllers/service_api/app/conversation.py index 2fabfdd133..e111ea2ebc 100644 --- a/api/controllers/service_api/app/conversation.py +++ b/api/controllers/service_api/app/conversation.py @@ -54,6 +54,7 @@ class ConversationDetailApi(AppApiResource): raise NotFound("Conversation Not Exists.") return {"result": "success"}, 204 + class ConversationRenameApi(AppApiResource): @marshal_with(simple_conversation_fields) diff --git a/api/controllers/service_api/app/message.py b/api/controllers/service_api/app/message.py index e482d16d4f..98ba1cb44a 100644 --- a/api/controllers/service_api/app/message.py +++ b/api/controllers/service_api/app/message.py @@ -10,6 +10,8 @@ from controllers.service_api.app.error import NotChatAppError 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 class MessageListApi(AppApiResource): @@ -96,5 +98,36 @@ class MessageFeedbackApi(AppApiResource): return {'result': 'success'} +class MessageSuggestedApi(AppApiResource): + def get(self, app_model, end_user, message_id): + 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) + else: + user = end_user + + questions = MessageService.get_suggested_questions_after_answer( + app_model=app_model, + user=user, + message_id=message_id + ) + except services.errors.message.MessageNotExistsError: + raise NotFound("Message Not Exists.") + + return {'result': 'success', 'data': questions} + + api.add_resource(MessageListApi, '/messages') api.add_resource(MessageFeedbackApi, '/messages//feedbacks') +api.add_resource(MessageSuggestedApi, '/messages//suggested') diff --git a/web/app/components/develop/template/template.en.mdx b/web/app/components/develop/template/template.en.mdx index 644c4e373a..3654b50097 100644 --- a/web/app/components/develop/template/template.en.mdx +++ b/web/app/components/develop/template/template.en.mdx @@ -63,7 +63,7 @@ For high-quality text generation, such as articles, summaries, and translations, ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/completion-messages' \ + curl --location --request POST '${props.appDetail.api_base_url}/completion-messages' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -130,7 +130,7 @@ For high-quality text generation, such as articles, summaries, and translations, ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \ + curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -168,6 +168,55 @@ For high-quality text generation, such as articles, summaries, and translations, --- + + + + Get next questions suggestions for the current message + + ### Path Params + + + + Message ID + + + + + + + + + ```bash {{ title: 'cURL' }} + 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' \ + ``` + + + + + ```json {{ title: 'Response' }} + { + "result": "success", + "data": [ + "a", + "b", + "c" + ] + ] + } + ``` + + + + +--- + ```bash {{ title: 'cURL' }} - curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \ + curl --location --request GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' ``` diff --git a/web/app/components/develop/template/template.zh.mdx b/web/app/components/develop/template/template.zh.mdx index 157cd91bb3..d00171d106 100644 --- a/web/app/components/develop/template/template.zh.mdx +++ b/web/app/components/develop/template/template.zh.mdx @@ -63,7 +63,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/completion-messages' \ + curl --location --request POST '${props.appDetail.api_base_url}/completion-messages' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -130,7 +130,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \ + curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -168,6 +168,55 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' --- + + + + 获取针对当前问题的下一步问题建议 + + ### Path Params + + + + 消息 ID + + + + + + + + + ```bash {{ title: 'cURL' }} + 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' \ + ``` + + + + + ```json {{ title: 'Response' }} + { + "result": "success", + "data": [ + "a", + "b", + "c" + ] + ] + } + ``` + + + + +--- + ```bash {{ title: 'cURL' }} - curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \ + curl --location --request GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' ``` diff --git a/web/app/components/develop/template/template_chat.en.mdx b/web/app/components/develop/template/template_chat.en.mdx index f3ab219741..72377555b4 100644 --- a/web/app/components/develop/template/template_chat.en.mdx +++ b/web/app/components/develop/template/template_chat.en.mdx @@ -69,7 +69,7 @@ For versatile conversational apps using a Q&A format, call the chat-messages API ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/chat-messages' \ + curl --location --request POST '${props.appDetail.api_base_url}/chat-messages' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -138,7 +138,7 @@ For versatile conversational apps using a Q&A format, call the chat-messages API ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \ + curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -176,6 +176,54 @@ For versatile conversational apps using a Q&A format, call the chat-messages API --- + + + + Get next questions suggestions for the current message + + ### Path Params + + + + Message ID + + + + + + + + ```bash {{ title: 'cURL' }} + 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' \ + ``` + + + + + ```json {{ title: 'Response' }} + { + "result": "success", + "data": [ + "a", + "b", + "c" + ] + ] + } + ``` + + + + +--- + ```bash {{ title: 'cURL' }} - curl --location --request GET 'https://cloud.langgenius.dev/api/messages?user=abc-123&conversation_id=' + curl --location --request GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id=' --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' ``` @@ -270,7 +318,7 @@ For versatile conversational apps using a Q&A format, call the chat-messages API ```bash {{ title: 'cURL' }} - curl --location --request GET 'https://cloud.langgenius.dev/api/conversations?user=abc-123&last_id=&limit=20' \ + curl --location --request GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' ``` @@ -331,7 +379,7 @@ For versatile conversational apps using a Q&A format, call the chat-messages API ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/conversations/{converation_id}/name' \ + curl --location --request POST '${props.appDetail.api_base_url}/conversations/{converation_id}/name' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --data-raw '{ @@ -378,7 +426,7 @@ For versatile conversational apps using a Q&A format, call the chat-messages API ```bash {{ title: 'cURL' }} - curl --location --request DELETE 'https://cloud.langgenius.dev/api/conversations/{convsation_id}' \ + curl --location --request DELETE '${props.appDetail.api_base_url}/conversations/{convsation_id}' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ @@ -415,7 +463,7 @@ For versatile conversational apps using a Q&A format, call the chat-messages API - Audio file. + Audio file. File uploads are currently limited to 15 MB and the following input file types are supported: mp3, mp4, mpeg, mpga, m4a, wav, and webm. @@ -425,7 +473,7 @@ For versatile conversational apps using a Q&A format, call the chat-messages API ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/conversations/name' \ + curl --location --request POST '${props.appDetail.api_base_url}/conversations/name' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --form 'file=@localfile;type=audio/mp3' ``` @@ -467,7 +515,7 @@ For versatile conversational apps using a Q&A format, call the chat-messages API ```bash {{ title: 'cURL' }} - curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \ + curl --location --request GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' ``` diff --git a/web/app/components/develop/template/template_chat.zh.mdx b/web/app/components/develop/template/template_chat.zh.mdx index 25ce17de52..22f94d84db 100644 --- a/web/app/components/develop/template/template_chat.zh.mdx +++ b/web/app/components/develop/template/template_chat.zh.mdx @@ -69,7 +69,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/chat-messages' \ + curl --location --request POST '${props.appDetail.api_base_url}/chat-messages' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -138,7 +138,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/messages/{message_id}/feedbacks' \ + curl --location --request POST '${props.appDetail.api_base_url}/messages/{message_id}/feedbacks' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -176,6 +176,54 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' --- + + + + 获取针对当前问题的下一步问题建议 + + ### Path Params + + + + 消息 ID + + + + + + + + ```bash {{ title: 'cURL' }} + curl --location --request GET '${props.appDetail.api_base_url}/messages/{message_id}/suggeste' \ + --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ + --header 'Content-Type: application/json' \ + ``` + + + + + ```json {{ title: 'Response' }} + { + "result": "success", + "data": [ + "a", + "b", + "c" + ] + ] + } + ``` + + + + +--- + ```bash {{ title: 'cURL' }} - curl --location --request GET 'https://cloud.langgenius.dev/api/messages?user=abc-123&conversation_id=' + curl --location --request GET '${props.appDetail.api_base_url}/messages?user=abc-123&conversation_id=' --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' ``` @@ -270,7 +318,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request GET 'https://cloud.langgenius.dev/api/conversations?user=abc-123&last_id=&limit=20' \ + curl --location --request GET '${props.appDetail.api_base_url}/conversations?user=abc-123&last_id=&limit=20' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' ``` @@ -331,7 +379,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/conversations/{converation_id}/name' \ + curl --location --request POST '${props.appDetail.api_base_url}/conversations/{converation_id}/name' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --header 'Content-Type: application/json' \ --data-raw '{ @@ -377,7 +425,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request DELETE 'https://cloud.langgenius.dev/api/conversations/{convsation_id}' \ + curl --location --request DELETE '${props.appDetail.api_base_url}/conversations/{convsation_id}' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ @@ -414,7 +462,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' - 语音文件。 + 语音文件。 文件上传当前限制为 15 MB,并且支持以下输入文件类型:mp3、mp4、mpeg、mpga、m4a、wav 和 webm。 @@ -424,7 +472,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request POST 'https://cloud.langgenius.dev/api/conversations/name' \ + curl --location --request POST '${props.appDetail.api_base_url}/conversations/name' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' \ --form 'file=@localfile;type=audio/mp3' ``` @@ -466,7 +514,7 @@ import { Row, Col, Properties, Property, Heading, SubProperty } from '../md.tsx' ```bash {{ title: 'cURL' }} - curl --location --request GET 'https://cloud.langgenius.dev/api/parameters?user=abc-123' \ + curl --location --request GET '${props.appDetail.api_base_url}/parameters?user=abc-123' \ --header 'Authorization: Bearer ENTER-YOUR-SECRET-KEY' ```