The OpenSearch search development workbench enables API calls to large model services, including the RAG-specific large model built on Alibaba's proprietary model foundation. This service is ideal for RAG scenarios, enhancing answer accuracy and reducing hallucination rates when used alongside document processing and retrieval services.
Service name | Service ID (service_id) | Service description |
OpenSearch-Qwen-Turbo | ops-qwen-turbo | Leverages the qwen-turbo large-scale language model for supervised fine-tuning, enhancing retrieval capabilities and reducing harmfulness. |
Qwen-Turbo | qwen-turbo | A large-scale language model, Qwen-Turbo supports inputs in multiple languages, including Chinese and English. |
Qwen-Plus | qwen-plus | An enhanced version of the Qwen large-scale language model, Qwen-Plus supports inputs in various languages, including Chinese and English. |
Qwen-Max | qwen-max | Also referred to as Qwen 2.0, this trillion-scale large language model supports inputs in multiple languages, such as Chinese and English. |
Prerequisites
Get authentication information
When invoking the OpenSearch Search Development Console service through APIs, you need to authenticate the caller's identity.
Get service access address
Supports invoking the service through both public network and VPC. For more information, see Get service registration address.
Request description
General description
The request body must not exceed 8MB.
HTTP request method
POST
URL
{host}/v3/openapi/workspaces/{workspace_name}/text-generation/{service_id}
Parameter description:
host: The address for calling the service, accessible via both public network and VPC environments. For more information, see the referenced document.
workspace_name: The name of the workspace, such as 'default'.
service_id: The system's built-in service ID, for example, 'ops-qwen-turbo'.
Request parameters
Header parameters
API-KEY authentication
Parameter | Type | Required | Description | Example value |
Content-Type | String | Yes | The MIME type of the request, specified as 'application/json'. | application/json |
Authorization | String | Yes | The API key for authentication. | Bearer OS-d1**2a |
Body parameters
Parameter | Type | Required | Description | Example value |
messages | List | Yes | The conversation history between the user and the model. Each list element is a JSON object with 'role' and 'content' keys. The 'role' can be 'system', 'user', or 'assistant'.
| |
stream | Boolean | No | Indicates whether to return results in streaming mode. By default, this is set to false. When true, each output is the entire sequence generated up to that point, with the last output being the final complete result. | false |
parameters | Map | No | A set of adjustable parameters for the large model request. |
Note: The maximum token limit for ops-qwen-turbo is 4000.
Response parameters
Parameter | Type | Description | Example value |
result.text | String | The text generated by the model during the current interaction. | Zhengzhou is a... |
usage.output_tokens | Integer | The number of tokens in the content generated by the model. | 100 |
usage.input_tokens | Integer | The number of tokens in the user's input content. | 100 |
usage.total_tokens | Integer | The combined token count of the user's input and the model's generated content. | 200 |
Curl request example
curl -XPOST -H "Content-Type: application/json"
"http://****-hangzhou.opensearch.aliyuncs.com/v3/openapi/workspaces/default/text-generation/ops-qwen-turbo"
-H "Authorization: Bearer Your-API-KEY"
-d "{
\"messages\":[
{
\"role\":\"system\",
\"content\":\"You are a robot assistant\"
},
{
\"role\":\"user\",
\"content\":\"What is the capital of Henan\"
},
{
\"role\":\"assistant\",
\"content\":\"Zhengzhou\"
},
{
\"role\":\"user\",
\"content\":\"What are some fun places there\"
}
],
\"stream\":false
}"
Response example
Normal response example
{
"request_id": "450fcb80-f796-****-8d69-e1e86d29aa9f",
"latency": 564.903929,
"result": {
"text": "Zhengzhou is a city with a long history and modernity, offering many fun places to visit. Here are some recommended tourist attractions:
Songshan Shaolin Temple: As the birthplace of Shaolin martial arts, Songshan Shaolin Temple has always been a place that tourists yearn for. Here, you can enjoy wonderful martial arts performances and appreciate the charm of Shaolin Kung Fu.
Yellow River Scenic Area: The Yellow River is the mother river of the Chinese nation. In Zhengzhou, you can take a boat tour to enjoy the various sceneries of the Yellow River and feel the beauty of the great river.
Zhengzhou Zoo: This is a family-friendly attraction with various rare animals such as giant pandas and golden monkeys, allowing children to get close to animals and broaden their knowledge.
Zhengzhou Museum: If you are interested in history and culture, Zhengzhou Museum is a good choice. It houses a large number of precious cultural relics, showcasing the historical changes and cultural heritage of the Zhengzhou area.
Zhengzhou Century Park: This is a large urban park with beautiful lakes, gardens, and recreational facilities. Here, you can take a walk, jog, and enjoy the tranquility and harmony of nature.
These are just some of the many fun places in Zhengzhou. In fact, there are many other attractions worth visiting in Zhengzhou. Hope you have a pleasant trip in Zhengzhou!"
},
"usage": {
"output_tokens": 6320,
"input_tokens": 35,
"total_tokens": 6355
}
}
Abnormal response example
In the event of an error during the request, the output will provide the error reason through a code and message.
{
"request_id": "45C8C9E5-6BCB-****-80D3-E298F788512B",
"latency": 0,
"code": "InvalidParameter",
"message": "JSON parse error: Unexpected character ..."
}
Status code description
For detailed information on status codes, see the referenced document.