watsonx.ai_Function_Deployment_MNB / cos_stream_schema_examples.py
MilanM's picture
Upload 2 files
1602ff5 verified
# Define input data schema as a proper Python list (not a string)
input_schema = [
{
'id': '1',
'type': 'struct',
'fields': [
{
'name': 'cos_config',
'type': 'object',
'nullable': False,
'metadata': {
'description': 'Cloud Object Storage configuration'
}
},
{
'name': 'source_urls',
'type': 'array',
'nullable': False,
'metadata': {
'description': 'URLs of files to download and upload to COS'
}
},
{
'name': 'prefix',
'type': 'string',
'nullable': True,
'metadata': {
'description': 'Optional prefix to add to the file names in COS'
}
},
{
'name': 'http_method',
'type': 'string',
'nullable': True,
'metadata': {
'description': 'HTTP method to use for downloading files'
}
}
]
}
]
# Define output data schema as a proper Python list (not a string)
output_schema = [
{
'id': '1',
'type': 'struct',
'fields': [
{
'name': 'status',
'type': 'string',
'nullable': False,
'metadata': {
'description': 'Status of the operation (success or error)'
}
},
{
'name': 'data',
'type': 'object',
'nullable': True,
'metadata': {
'description': 'Response data containing upload details'
}
},
{
'name': 'message',
'type': 'string',
'nullable': True,
'metadata': {
'description': 'Error message if status is error'
}
}
]
}
]
# Define sample scoring input
sample_input = {
'input_data': [
{
'fields': ['cos_config', 'source_urls', 'prefix', 'http_method'],
'values': [
[
{
'bucket_name': 'my-bucket',
'api_key': '<your-cos-api-key>',
'instance_id': '<your-cos-instance-id>',
'auth_endpoint': 'https://iam.cloud.ibm.com/identity/token',
'endpoint_url': 'https://s3.eu-de.cloud-object-storage.appdomain.cloud'
},
[
'https://example.com/sample-file.pdf',
'https://example.com/another-file.csv'
],
'uploads/files',
'GET'
]
]
}
]
}