Answer generation
Function
This API is used to input content to the model and use the model to generate answers.
Note:
-
When chat_id is empty, chat_create_flag is set to 1, indicating that a new chat needs to be started. If chat_id is set, chat_create_flag can be set to 0, indicating that no new chat needs to be started. The API supports multi-turn dialogs.
-
The number of elements in messages must be an odd number. For a single-turn dialog, the number is 1. For a multi-turn dialog, the number is 3, 5, 7, and so on, for example, [question1, answer1, question2].
-
In a multi-turn dialog, the chat history is from old to new.
URI
POST /v1/{project_id}/applications/{application_id}/uni-search/experience/chat
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Definition: Project ID. For details about how to obtain the project ID, see Obtaining a Project ID. Constraints: N/A Value range: The value can contain 1 to 64 characters. Only digits, letters, hyphens (-), and underscores (_) are allowed. The value must start with a letter. Default value: N/A |
application_id |
Yes |
String |
Definition: Application ID. For details about how to obtain the application ID, see Obtaining an Application ID. Constraints: Character string Value range: The value can contain 1 to 64 characters. Only digits, letters, hyphens (-), and underscores (_) are allowed. The value must start with a letter. Default value: N/A |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition: Token used for API authentication. For details about how to obtain the token, see Obtaining an IAM User Token. Constraints: N/A Value range: N/A Default value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
chat_id |
No |
String |
Definition: Chat ID. Constraints: N/A Value range: The maximum length is 64 characters. Default value: N/A |
repo_id |
Yes |
String |
Definition: Knowledge base ID. Constraints: N/A Value range: The maximum length is 64 characters. Default value: N/A |
extra_repo_ids |
No |
Array of strings |
Definition: Multi-knowledge base Q&A. Constraints: N/A Value range: The list length is less than 9. The value can contain a maximum of 64 characters. Default value: N/A |
messages |
Yes |
Array of ChatMessage objects |
Definition: Chat content. Constraints: N/A Value range: The list length cannot exceed 19. Default value: N/A |
chat_create_flag |
Yes |
String |
Definition: Chat start flag. Constraints: N/A Value range:
Default value: N/A |
refresh_flag |
Yes |
String |
Definition: Q&A update flag. Constraints: N/A Value range:
Default value: N/A |
stream |
No |
Boolean |
Definition: Streaming output flag. Constraints: N/A Value range: N/A Default value: N/A |
filter_string |
No |
String |
Definition: RAG search phase filtering A query string with syntax. A parser with strict syntax is used to return documents based on the provided query string. Example: tags: (Shanghai OR capital) AND category:"city" Constraints:
Value range: N/A Default value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
role |
No |
String |
Definition: Role in a dialogue. The value can be system or user. Constraints: N/A Value range:
Default value: N/A |
content |
Yes |
String |
Definition: Chat content. Constraints: N/A Value range: The length cannot exceed 4,096 characters. Default value: N/A |
Response Parameters
Status code: 200
Parameter |
Type |
Description |
---|---|---|
chat_id |
String |
Definition: Chat ID. Value range: N/A |
chat_result |
ChatResult object |
Definition: Dialog result. Value range: N/A |
references |
Array of ChatReferenceInfo objects |
Definition: Reference result. Value range: N/A |
reference_total |
Integer |
Definition: Total reference sources. Value range: N/A |
sub_queries |
Array of strings |
Definition: Query used for search, including the original query and rewritten query. Value range: N/A |
category |
String |
Definition: Query type returned by the search planning model. Value range: N/A |
rac |
Map<String,RacResponse> |
Definition: Whether to include both image and text in replies. Value range: N/A |
sql_info |
SQLInfo object |
Definition: Process data of tableRAG, including SQL, table schema, and SQL query result. Value range: N/A |
Parameter |
Type |
Description |
---|---|---|
index |
Integer |
Definition: No. Value range: N/A |
message |
String |
Definition: Text content. Value range: N/A |
question_id |
String |
Definition: Q&A ID. Value range: N/A |
Parameter |
Type |
Description |
---|---|---|
file_id |
String |
Definition: File ID (or FAQ ID). Value range: N/A |
chunk_id |
String |
Definition: Block ID. Value range: N/A |
title |
String |
Definition: Title. Value range: N/A |
subtitle |
String |
Definition: Document subheading. Value range: N/A |
content |
String |
Definition: Text content. Value range: N/A |
big_content |
String |
Definition: Content context, for example, the original table that is not segmented. Note: (1) The search API may have a value. (2) The Q&A API replaces big_content with content, and this field is cleared. Value range: N/A |
doc_type |
String |
Definition: Document type. The value can be doc or faq. Value range: N/A |
file_path |
String |
Definition: Document archive path. Value range: N/A |
category |
String |
Definition: Document directory, which corresponds to the leaf nodes in the directory tree. This parameter has only one value. Value range: N/A |
tags |
Array of strings |
Definition: Document tag list. Value range: N/A |
update_date_time |
String |
Definition: Update time. Value range: N/A |
repo_id |
String |
Definition: Knowledge base ID. Value range: N/A |
page_num |
Long |
Definition: Page number. Value range: N/A |
component_num |
Long |
Definition: Chunk sequence number. Value range: N/A |
score |
Float |
Definition: ES score. Value range: N/A |
additional_fields |
Map<String,Object> |
Definition: Used to store unknown fields. Value range: N/A |
elements |
Array of strings |
Definition: Data element in HTML. Value range: N/A Constraints: This parameter is supported only in clusters 25.7.T1 or later. |
pdf_coordinate |
Object |
Definition: Metadata used for PDF parsing and text locating. Example value: [ [ 202, 687 ], [ 1031, 687 ] ] Value range: N/A Constraints: This parameter is supported only in clusters 25.7.T1 or later. |
Parameter |
Type |
Description |
---|---|---|
index |
Array of integers |
Definition: Reference sequence number associated with an answer. Value range: N/A |
images |
Array of ImageItem objects |
Definition: Information about the inserted image. If no image is inserted, an empty list is returned. Value range: N/A |
ret |
Integer |
Definition: Response code. Value range: N/A |
data |
String |
Definition: Response result. Value range: N/A |
rac_index |
Integer |
Definition: It is used to identify the sequence. Value range: N/A |
Parameter |
Type |
Description |
---|---|---|
id |
String |
Definition: Unique image ID. Value range: N/A |
extra_info |
ImageExtraInfo object |
Definition: Store the returned image data. Value range: N/A |
Parameter |
Type |
Description |
---|---|---|
image_height |
Integer |
Definition: Height of the image. Value range: N/A |
image_width |
Integer |
Definition: Width of the image. Value range: N/A |
image_base64 |
String |
Definition: Base64 code of an image Value range: N/A |
doc_name |
String |
Definition: Information about the document to which the image belongs. This field is optional. Value range: N/A |
title_name |
String |
Definition: Image name. Value range: N/A |
title_no |
String |
Definition: Image ID. Value range: N/A |
Parameter |
Type |
Description |
---|---|---|
sql |
String |
Definition: SQL statement generated by the model based on the query and table schema. Value range: N/A |
schemas |
String |
Definition: Schema of the related table retrieved based on the query. Value range: N/A |
sql_results |
String |
Definition: Table data queried from the database based on the SQL statement. Value range: N/A |
table_ids |
Array of strings |
Definition: Table ID used in the reference document. Value range: N/A |
Example Requests
The preceding is an example of the response body of a multi-round dialog request.
Note:
-
When chat_id is empty, chat_create_flag is set to 1, indicating that a new chat needs to be started. If chat_id is set, chat_create_flag can be set to 0, indicating that no new chat needs to be started.
-
The number of elements in messages is always an odd number. For a single-turn dialog, the number is 1. For multiple rounds of dialog, the number is 3, 5, 7, and so on.
As shown in the preceding example, message[0]["content"] is the query in the first round, message[1]["content"] is the answer in the first round, and message[2]["content"] is the query in the second round.
/v1/123/applications/1233453/uni-search/experience/chat { "repo_id" : "9d261b1c-e9b6-464f-881a-687251504edd", "chat_create_flag" : "0", "chat_id" : "cc84be57-3fc1-4365-a54d-417f098e8a19", "messages" : [ { "role" : "user", "content" : "What is the recommended maintenance cycle for the 2023 Honda Accord?" }, { "role" : "user", "content" : "For the 2023 Honda Accord, I recommend that you pay attention to the following aspects of regular maintenance: regularly replace the engine oil and oil filter. According to the manufacturer's recommendation, replace the engine oil and oil filter every 5,000-10,000 km." }, { "role" : "user", "content" : "What else should I pay attention to?" } ], "refresh_flag" : "0" }
Example Responses
Status code: 200
Response body containing the model generation result
{ "chat_id" : "cc84be57-3fc1-4365-a54d-417f098e8a19", "chat_result" : { "index" : 0, "message" : "When performing maintenance, pay attention to the following: Check the tire condition, including the tire pressure and tread depth. Replace tires that are severely worn out in time. Check the brake system, including brake pads and brake fluid. If there is wear, repair and replace it in time. Check the engine cooling system regularly and replace the coolant and antifreeze. Check the battery status to ensure that the battery works properly. Maintain the vehicle regularly, such as four-wheel alignment and air conditioning maintenance, to extend the service life of the vehicle.", "question_id" : "12453567446" }, "references" : [ { "file_id" : "123", "title" : "Automobile Maintenance Precautions.pdf", "content" : "Check the tire condition, including the tire pressure and tread depth. Replace tires that are severely worn out in time. Check the brake system, including brake pads and brake fluid.", "update_date_time" : "1234554456", "doc_type" : "doc", "file_path" : "uni-search/v2/Document name.doc" }, { "file_id" : "123", "title" : "Automobile Maintenance Precautions.pdf", "content" : "If there is wear, repair and replace it in time. Check the engine cooling system regularly and replace the coolant and antifreeze.", "update_date_time" : "1234554456", "doc_type" : "doc", "file_path" : "uni-search/v2/Document name.doc" }, { "file_id" : "123", "title" : "Automobile Maintenance Precautions.pdf", "content" : "Check the battery status to ensure that the battery works properly. Maintain the vehicle regularly, such as four-wheel alignment and air conditioning maintenance, to extend the service life of the vehicle.", "update_date_time" : "1234554456", "doc_type" : "doc", "file_path" : "uni-search/v2/Document name.doc" } ], "sql_info" : { "sql" : "", "schemas" : [ ], "sql_results" : "", "table_ids" : [ ] }, "reference_total" : "3" }
Status Codes
Status Code |
Description |
---|---|
200 |
Response body containing the model generation result |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot