Semantic Operations
What are Semantic Operations?
The core generative, or LLM-powered methods within ZYX are called semantic operations. A semantic operation is a function that leverages language models to:
- Take in some input Context (prompts, instructions, message history, data) and a Source for specific operations.
- Execute any Tools or interact with any interactive Attachments as needed.
- Check-off or complete a Condition (Goal) or/and return a Target value.
What are the different Semantic Operations?
The following cards illustrate the different semantic operations provided by ZYX.
-
Make
Generate outputs based on a target type or value.
-
Select
Perform a LLM-based selection of one or more options.
-
Edit
Edit a target value, using automatically determined and type-specific editing strategies.
-
Query
Query a grounded source object or value, returning a target value with confidence and accuracy scores.
-
Expressions
Run a Pythonic expression (
==,if x in y, etc.) against some context or a source object or value. -
Parse
Parse a source object or value into a target result.
-
Validate
Parse a source object or value into a target result, as well as validating the result against a set of constraints.
-
Run
Run an agent or model on an arbitrary task, and optionally return a target value.
Common Parameters
Most semantic operations share a consistent set of parameters. These three are especially useful when you want richer runtime behavior.
confidence
Enable log-probability based confidence scoring on the returned Result. This only works for models that expose log-probabilities.
from zyx import parse
from pydantic import BaseModel
class Info(BaseModel):
title: str
result = parse(
source="The Hobbit is a novel by J. R. R. Tolkien.",
target=Info,
confidence=True,
)
print(result.confidence)
observe
Enable CLI observation of tool calls and progress. Pass True for the default observer, or provide a custom Observer instance.
from zyx import edit
data = {
"name": "John Doe",
"age": 30,
"email": "john.doe@example.com",
}
result = edit(
target=data,
context="Change the name to 'Jane Doe'.",
merge=False,
observe=True,
)
"""
╭─ ▶ Operation ─╮
│ Edit │
╰───────────────╯
⟳ Processing (edit)...
╭─ ✨ Fields Generated ─╮
│ • name │
╰───────────────────────╯
✓ Edit complete
"""
stream
Stream results as they are generated. When enabled, the operation returns a Stream[T] instead of a Result[T].