ElementalInference / Client / create_function
create_function¶
- ElementalInference.Client.create_function(**kwargs)¶
Creates a function. A function analyzes a feed by building a request from the feed’s media and metadata, optionally sending that request to an Amazon Bedrock model in your account, and publishing the result to the feed’s metadata timeline.
A function runs only after you attach it to a feed as a function output. For more information, see Using functions in the AWS Elemental Inference User Guide.
See also: AWS API Documentation
Request Syntax
response = client.create_function( name='string', target={ 'bedrock': { 'api': 'INVOKE_MODEL', 'model': 'string' }, 'passthrough': {} }, requestExpression='string', responseExpression='string', description='string', eventBridgeDelivery='ENABLED'|'DISABLED', tags={ 'string': 'string' } )
- Parameters:
name (string) –
[REQUIRED]
A name for this function.
target (dict) –
[REQUIRED]
The destination for the request that the function builds.
Note
This is a Tagged Union structure. Only one of the following top level keys can be set:
bedrock,passthrough.bedrock (dict) –
Send the request to an Amazon Bedrock model.
api (string) – [REQUIRED]
The Amazon Bedrock API to call. The only valid value is INVOKE_MODEL.
model (string) – [REQUIRED]
The model to invoke. Specify one of the following:
A model ID.
An inference profile ID.
The ARN of a custom model.
The ARN of a provisioned model.
Elemental Inference invokes the model in the Region of the feed. To use a model in other Regions, specify a cross-Region inference profile ID. A custom or provisioned model must be in the Region of the feed.
The request expression must produce a request body that this model accepts, and the model must accept the kind of media that the request expression references. For example, a text-only model can’t accept a request that references media.frames.
passthrough (dict) –
Send the request nowhere. Use this target to reshape the metadata that Elemental Inference already produces, with no model invocation and no model charges.
requestExpression (string) –
[REQUIRED]
The JSONata expression that builds the request. Elemental Inference evaluates it against the media object of the feed, which holds the media and metadata that the function asked for. Maximum length: 5,120 characters.
When you save the function, Elemental Inference evaluates the expression against sample media and rejects it if the evaluation fails. For a Bedrock target, the result must be a JSON object; Elemental Inference doesn’t check that the object is a valid request body for the model. The expression can reference at most one of media.transcript, media.contextual, and media.clip. For a passthrough target, it can’t reference media.frames.
responseExpression (string) –
The JSONata expression that selects what to store. Elemental Inference evaluates it against the result as its root: the model response for a Bedrock target, or the output of the request expression for a passthrough target. If a function has no response expression, Elemental Inference stores the entire result. Maximum length: 5,120 characters.
When you save the function, Elemental Inference checks that the expression is valid JSONata. For a passthrough target, it also evaluates the request and response expressions together against sample media, and rejects them if they produce no value.
description (string) – The description of the function. Maximum length: 1,024 characters.
eventBridgeDelivery (string) –
Specifies whether Elemental Inference also sends this function’s results to Amazon EventBridge. Elemental Inference sends a result only when the result is a JSON object with a top-level
eventBridgefield set totrue. It sends the result, unchanged, as a Function Metadata Generated event to the default event bus in your account, after the result is available from GetMetadata. If the result is larger than 64 KB, the event hasresultOmittedset totruein place of the result.Valid values:
ENABLED – Elemental Inference sends each marked result as an event.
DISABLED (default) – Elemental Inference doesn’t send events.
For a Bedrock target, ENABLED requires a response expression, because the model response itself never has a top-level
eventBridgefield. A feed output that runs a function with ENABLED can’t use a fixedInterval trigger shorter than 4 seconds.tags (dict) –
The tags to associate with this function.
(string) –
(string) –
- Return type:
dict
- Returns:
Response Syntax
{ 'name': 'string', 'target': { 'bedrock': { 'api': 'INVOKE_MODEL', 'model': 'string' }, 'passthrough': {} }, 'requestExpression': 'string', 'responseExpression': 'string', 'description': 'string', 'eventBridgeDelivery': 'ENABLED'|'DISABLED', 'arn': 'string', 'id': 'string', 'status': 'CREATING'|'AVAILABLE'|'REFERENCED'|'DELETING'|'DELETED', 'references': [ 'string', ], 'contextTypes': [ 'FRAMES'|'SUBTITLES'|'CONTEXTUAL_METADATA'|'CLIP_METADATA', ], 'tags': { 'string': 'string' } }
Response Structure
(dict) –
name (string) –
The name of the function.
target (dict) –
The destination for the request that the function builds.
Note
This is a Tagged Union structure. Only one of the following top level keys will be set:
bedrock,passthrough. If a client receives an unknown member it will setSDK_UNKNOWN_MEMBERas the top level key, which maps to the name or tag of the unknown member. The structure ofSDK_UNKNOWN_MEMBERis as follows:'SDK_UNKNOWN_MEMBER': {'name': 'UnknownMemberName'}
bedrock (dict) –
Send the request to an Amazon Bedrock model.
api (string) –
The Amazon Bedrock API to call. The only valid value is INVOKE_MODEL.
model (string) –
The model to invoke. Specify one of the following:
A model ID.
An inference profile ID.
The ARN of a custom model.
The ARN of a provisioned model.
Elemental Inference invokes the model in the Region of the feed. To use a model in other Regions, specify a cross-Region inference profile ID. A custom or provisioned model must be in the Region of the feed.
The request expression must produce a request body that this model accepts, and the model must accept the kind of media that the request expression references. For example, a text-only model can’t accept a request that references media.frames.
passthrough (dict) –
Send the request nowhere. Use this target to reshape the metadata that Elemental Inference already produces, with no model invocation and no model charges.
requestExpression (string) –
The JSONata expression that builds the request. Elemental Inference evaluates it against the media object of the feed, which holds the media and metadata that the function asked for.
responseExpression (string) –
The JSONata expression that selects what to store. Elemental Inference evaluates it against the result as its root: the model response for a Bedrock target, or the output of the request expression for a passthrough target. If a function has no response expression, Elemental Inference stores the entire result.
description (string) –
The description of the function.
eventBridgeDelivery (string) –
Indicates whether Elemental Inference also sends this function’s results to Amazon EventBridge. With ENABLED, each result that is a JSON object with a top-level
eventBridgefield set totrueis also sent as a Function Metadata Generated event to the default event bus in your account.arn (string) –
The ARN of the function.
id (string) –
The ID of the function.
status (string) –
The status of the function. A successful request returns CREATING. The function is ready to use as soon as the request succeeds.
references (list) –
The IDs of the feeds that have a function output, enabled or disabled, that references this function. While this list isn’t empty, the function can’t be deleted, and its name and target can’t be changed.
(string) –
contextTypes (list) –
The kinds of media context that this function uses. Elemental Inference derives this field from the media paths that the request expression references; you can’t set it. An empty list means that the expression references no media, so Elemental Inference supplies none at run time.
(string) –
One kind of media context that a function reads. Elemental Inference derives this value from the media paths that the request expression references:
FRAMES – Derived from media.frames.
SUBTITLES – Derived from media.transcript.
CONTEXTUAL_METADATA – Derived from media.contextual.
CLIP_METADATA – Derived from media.clip.
A request expression can reference at most one of SUBTITLES, CONTEXTUAL_METADATA, and CLIP_METADATA, in addition to FRAMES.
tags (dict) –
The tags associated with the function.
(string) –
(string) –
Exceptions