Make your first API call using the AI Search Open Platform Python SDK. This guide uses the document split service (ops-document-split-001) as an example.
Prerequisites
Before you begin, make sure you have:
Python 3 installed
An API key for the AI Search Open Platform. See Obtain an API key.
The service endpoint for your instance. See Obtain a service registration address.
Install the SDK
pip install alibabacloud_tea_openapi alibabacloud_searchplat20240529Call the document split service
The request body must not exceed 8 MB.
from alibabacloud_tea_openapi.models import Config
from alibabacloud_searchplat20240529.client import Client
from alibabacloud_searchplat20240529.models import GetDocumentSplitRequest
if __name__ == '__main__':
config = Config(
bearer_token='OS-****',
endpoint='****.platform-cn-shanghai.opensearch.aliyuncs.com',
protocol='http'
)
client = Client(config=config)
request = GetDocumentSplitRequest().from_map({
"document": {
"content": "test123",
"content_type": "text"
},
"strategy": {
"max_chunk_size": 300,
"need_sentence": False
}
})
response = client.get_document_split("default", "ops-document-split-001", request)
print(response)Replace
bearer_tokenwith your API key. For more information, see Obtain an API key.endpointis the service invocation address of the AI Search Open Platform. For more information, see Obtain a service registration address. Note that you need to remove thehttp://prefix.
What's next
Explore other available services and operators in the AI Search Open Platform API reference.
Learn how to configure chunking strategies using the
max_chunk_sizeandneed_sentenceparameters.