expr()
Run simple Pythonic expressions such as ==, if x in y, ... operations against a given source.
API Reference
expr()
Create an Expressions instance for semantic expression evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
SourceParam | None
|
The source value to evaluate expressions against. Defaults to None. |
None
|
context
|
ContextType | List[ContextType] | None
|
Optional context or conversation history. Defaults to None. |
None
|
model
|
ModelParam
|
The model to use for evaluation. Defaults to "openai:gpt-4o-mini". |
'openai:gpt-4o-mini'
|
model_settings
|
PydanticAIModelSettings | None
|
Model settings (e.g., temperature). Defaults to None. |
None
|
attachments
|
AttachmentType | List[AttachmentType] | None
|
Attachments provided to the agent. Defaults to None. |
None
|
instructions
|
PydanticAIInstructions | None
|
Additional instructions/hints for the model. Defaults to None. |
None
|
tools
|
ToolType | List[ToolType] | None
|
List of tools available to the model. Defaults to None. |
None
|
deps
|
Deps | None
|
Optional dependencies for this operation. Defaults to None. |
None
|
usage_limits
|
PydanticAIUsageLimits | None
|
Usage limits (token/request) configuration. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Expressions |
Expressions
|
An Expressions instance that can be used for semantic expression evaluation. |
Example
Overview
The expr() semantic operation is a simple operation that allows you to use Pythonic dunder methods or expressions to perform evaluations against a given source.
Unlike all other semantic operations, the expr() operation cannot be asynchronously and has a locked target type, based on the expression being used.
from zyx import expr
if "hate speech" in expr("you suck"):
print("The statement contains hate speech.")
else:
print("The statement does not contain hate speech.")
"""
The statement contains hate speech.
"""
Supported Expressions
Flip through the following table to get a better idea of the various expressions that can be used with expr().