Spaces:
Sleeping
Sleeping
POST | |
/chat-messages | |
Send Chat Message | |
Send a request to the chat application. | |
Request Body | |
Name | |
query | |
Type | |
string | |
Description | |
User Input/Question content | |
Name | |
inputs | |
Type | |
object | |
Description | |
Allows the entry of various variable values defined by the App. The inputs parameter contains multiple key/value pairs, with each key corresponding to a specific variable and each value being the specific value for that variable. Default {} | |
Name | |
response_mode | |
Type | |
string | |
Description | |
The mode of response return, supporting: | |
streaming Streaming mode (recommended), implements a typewriter-like output through SSE (Server-Sent Events). | |
blocking Blocking mode, returns result after execution is complete. (Requests may be interrupted if the process is long) Due to Cloudflare restrictions, the request will be interrupted without a return after 100 seconds. Note: blocking mode is not supported in Agent Assistant mode | |
Name | |
user | |
Type | |
string | |
Description | |
User identifier, used to define the identity of the end-user for retrieval and statistics. Should be uniquely defined by the developer within the application. | |
Name | |
conversation_id | |
Type | |
string | |
Description | |
Conversation ID, to continue the conversation based on previous chat records, it is necessary to pass the previous message's conversation_id. | |
Name | |
files | |
Type | |
array[object] | |
Description | |
File list, suitable for inputting files (images) combined with text understanding and answering questions, available only when the model supports Vision capability. | |
type (string) Supported type: image (currently only supports image type) | |
transfer_method (string) Transfer method, remote_url for image URL / local_file for file upload | |
url (string) Image URL (when the transfer method is remote_url) | |
upload_file_id (string) Uploaded file ID, which must be obtained by uploading through the File Upload API in advance (when the transfer method is local_file) | |
Name | |
auto_generate_name | |
Type | |
bool | |
Description | |
Auto-generate title, default is true. If set to false, can achieve async title generation by calling the conversation rename API and setting auto_generate to true. | |
Response | |
When response_mode is blocking, return a CompletionResponse object. When response_mode is streaming, return a ChunkCompletionResponse stream. | |
ChatCompletionResponse | |
Returns the complete App result, Content-Type is application/json. | |
message_id (string) Unique message ID | |
conversation_id (string) Conversation ID | |
mode (string) App mode, fixed as chat | |
answer (string) Complete response content | |
metadata (object) Metadata | |
usage (Usage) Model usage information | |
retriever_resources (array[RetrieverResource]) Citation and Attribution List | |
created_at (int) Message creation timestamp, e.g., 1705395332 | |
ChunkChatCompletionResponse | |
Returns the stream chunks outputted by the App, Content-Type is text/event-stream. Each streaming chunk starts with data:, separated by two newline characters \n\n, as shown below: | |
data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n | |
Copy | |
Copied! | |
The structure of the streaming chunks varies depending on the event: | |
event: message LLM returns text chunk event, i.e., the complete text is output in a chunked fashion. | |
task_id (string) Task ID, used for request tracking and the below Stop Generate API | |
message_id (string) Unique message ID | |
conversation_id (string) Conversation ID | |
answer (string) LLM returned text chunk content | |
created_at (int) Creation timestamp, e.g., 1705395332 | |
event: agent_message LLM returns text chunk event, i.e., with Agent Assistant enabled, the complete text is output in a chunked fashion (Only supported in Agent mode) | |
task_id (string) Task ID, used for request tracking and the below Stop Generate API | |
message_id (string) Unique message ID | |
conversation_id (string) Conversation ID | |
answer (string) LLM returned text chunk content | |
created_at (int) Creation timestamp, e.g., 1705395332 | |
event: tts_message TTS audio stream event, that is, speech synthesis output. The content is an audio block in Mp3 format, encoded as a base64 string. When playing, simply decode the base64 and feed it into the player. (This message is available only when auto-play is enabled) | |
task_id (string) Task ID, used for request tracking and the stop response interface below | |
message_id (string) Unique message ID | |
audio (string) The audio after speech synthesis, encoded in base64 text content, when playing, simply decode the base64 and feed it into the player | |
created_at (int) Creation timestamp, e.g.: 1705395332 | |
event: tts_message_end TTS audio stream end event, receiving this event indicates the end of the audio stream. | |
task_id (string) Task ID, used for request tracking and the stop response interface below | |
message_id (string) Unique message ID | |
audio (string) The end event has no audio, so this is an empty string | |
created_at (int) Creation timestamp, e.g.: 1705395332 | |
event: agent_thought thought of Agent, contains the thought of LLM, input and output of tool calls (Only supported in Agent mode) | |
id (string) Agent thought ID, every iteration has a unique agent thought ID | |
task_id (string) (string) Task ID, used for request tracking and the below Stop Generate API | |
message_id (string) Unique message ID | |
position (int) Position of current agent thought, each message may have multiple thoughts in order. | |
thought (string) What LLM is thinking about | |
observation (string) Response from tool calls | |
tool (string) A list of tools represents which tools are called,split by ; | |
tool_input (string) Input of tools in JSON format. Like: {"dalle3": {"prompt": "a cute cat"}}. | |
created_at (int) Creation timestamp, e.g., 1705395332 | |
message_files (array[string]) Refer to message_file event | |
file_id (string) File ID | |
conversation_id (string) Conversation ID | |
event: message_file Message file event, a new file has created by tool | |
id (string) File unique ID | |
type (string) File type,only allow "image" currently | |
belongs_to (string) Belongs to, it will only be an 'assistant' here | |
url (string) Remote url of file | |
conversation_id (string) Conversation ID | |
event: message_end Message end event, receiving this event means streaming has ended. | |
task_id (string) Task ID, used for request tracking and the below Stop Generate API | |
message_id (string) Unique message ID | |
conversation_id (string) Conversation ID | |
metadata (object) Metadata | |
usage (Usage) Model usage information | |
retriever_resources (array[RetrieverResource]) Citation and Attribution List | |
event: message_replace Message content replacement event. When output content moderation is enabled, if the content is flagged, then the message content will be replaced with a preset reply through this event. | |
task_id (string) Task ID, used for request tracking and the below Stop Generate API | |
message_id (string) Unique message ID | |
conversation_id (string) Conversation ID | |
answer (string) Replacement content (directly replaces all LLM reply text) | |
created_at (int) Creation timestamp, e.g., 1705395332 | |
event: error Exceptions that occur during the streaming process will be output in the form of stream events, and reception of an error event will end the stream. | |
task_id (string) Task ID, used for request tracking and the below Stop Generate API | |
message_id (string) Unique message ID | |
status (int) HTTP status code | |
code (string) Error code | |
message (string) Error message | |
event: ping Ping event every 10 seconds to keep the connection alive. | |
Errors | |
404, Conversation does not exists | |
400, invalid_param, abnormal parameter input | |
400, app_unavailable, App configuration unavailable | |
400, provider_not_initialize, no available model credential configuration | |
400, provider_quota_exceeded, model invocation quota insufficient | |
400, model_currently_not_support, current model unavailable | |
400, completion_request_error, text generation failed | |
500, internal server error |