Appearance
Error handling
Any time you send a request using our SDK, we recommend you include a try/except
block in the request to handle any potential errors.
ERROR HANDLING
For simplicity, error handling is not included in the majority of the request samples in the documentation, but you should always include it when sending a request yourself.
See the following sample request for an example of the correct implementation of error handling in a request.
python
from calypsoai import CalypsoAI
from calypsoai.datatypes import GenAIScannerConfig, ScanContext, ScannerDirection
# Define the URL and token for CalypsoAI
CALYPSOAI_URL="https://www.us1.calypsoai.app"
CALYPSOAI_TOKEN="ADD-YOUR-TOKEN-HERE"
# Initialize the CalypsoAI client
cai = CalypsoAI(url=CALYPSOAI_URL, token=CALYPSOAI_TOKEN)
# Configure the scanner
config = GenAIScannerConfig(input="Political figures", type="custom",
scanContext=ScanContext.DIRECTIONAL)
try: # Begin the try/except block
response = cai.scanners.create(name='ADD-YOUR-SCANNER-NAME-HERE', config=config,
direction=ScannerDirection.BOTH, published=False)
print(response.model_dump_json(indent=2))
except Exception as e:
print(e) # End the try/except block
# Continue with the rest of your code