⚡️ sema4ai-actions
A Python library designed to simplify the development of Python actions (AI or otherwise) to be run with the Sema4.ai Action Server.
Getting started
If you have not setup Action Server already, see the 🏃♂️ Quickstart on how to do that.
Decorate your Python function with the @action decorator:
from sema4ai.actions import action
@action
def sum_numbers(a: float, b: float) -> float:
...
And your function is now an ⚡️Action!
You can now run and debug your action by Starting Action Server with action-server start and accessing the UI at http://localhost:8080.
Note: Action inputs and outputs support only
int,float,strandbooltypes.
Describe your action
For an action's purpose and usage to be understood by AI models (and humans) it needs to be documented correctly.
To do that, use Google Style Docstring to write a clear and concise description on what your action does and document the action inputs and expected output:
@action
def get_weather_forecast(city: str, days: int, scale: str = "celsius") -> str:
"""
Returns weather conditions forecast for a given city.
Args:
city (str): Target city to get the weather conditions for
days: How many day forecast to return
scale (str): Temperature scale to use, should be one of "celsius" or "fahrenheit"
Returns:
str: The requested weather conditions forecast
"""
...
Tip: Experiment with and iterate the exact documentation wording to get more predictable results when using your action with AI apps.
Consequential flag
You can explicitly provide the is_consequential flag for an action to mark it's operations as "must always prompt the user for confirmation before running" by OpenAI GPTs (and possibly by other providers). If set to False, the user will be provided with an "always allow" feature.
@action(is_consequential=True)
def get_weather_forecast(city: str, days: int, scale: str = "celsius") -> str:
Working with Secrets
Actions can work with sensitive credentials by using the Secret type from the sema4ai.actions library. Secrets are handled securely and will not be exposed in logs or the API documentation.
from sema4ai.actions import action, Secret
@action
def process_document(document_url: str, credentials: Secret) -> str:
"""Process a document using secure credentials."""
api_key = credentials.value
...
For more details on secrets, including tagged secrets with SecretSpec, OAuth2 secrets, and passing secrets in development and production modes, see the Secrets Guide.
Execution
To get the full benefits of your actions, the suggested way to run them is using Action Server. But it's also possible to do that directly in command line by passing the named arguments:
python -m sema4ai.actions run -- --city=Helsinki --days=3
Guides
API Reference
Explore our API for extensive documentation.
Changelog
A list of releases and corresponding changes can be found in the changelog.
Release files for sema4ai-actions 1.6.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sema4ai_actions-1.6.6.tar.gz | 78.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sema4ai_actions-1.6.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 175.2 kB
Release files / sema4ai_actions-1.6.6.tar.gz
| Download URL | sema4ai_actions-1.6.6.tar.gz |
|---|---|
| Size | 78.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83d16618764eaf38955ccf746560491e91aefe951ebd0b6dc8d9002717cf3355
|
|
BLAKE2b-256 checksum How to use checksums |
a8e2b95e0908c04e4924ff97119466164f222c2168e8e273e7588051ff5fa74d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
|
Release files / sema4ai_actions-1.6.6-py3-none-any.whl
| Download URL | sema4ai_actions-1.6.6-py3-none-any.whl |
|---|---|
| Size | 96.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1dd4c20106690afec3854b09cc39ba669621b402348876449658fe228966bf77
|
|
BLAKE2b-256 checksum How to use checksums |
a4349886bba684b09ceea99daf4a3dd9b1272ffd6a7bcf5b64f4e4eb81bf24a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
|