Step
Using the decorator on a function
If you want to create a step from a function, you should use the@literalai_client.step decorator.
The step is automatically ended and sent to the platform when the function returns.
Another advantage of using the decorator is that you get several variables automatically set for you:
- name: The name of the step. This is automatically set to the function name.
- input: The input of the step. This is automatically set to the arguments of the function.
- output: The output of the step. This is automatically set to the return value of the function.
get_current_step method:
Using the with statement
If you want to create a step from a block of code, you should use the with statement.
The step is automatically ended and sent to the platform when the code exits the with block.
step method:
Using the start_step method
This method should be used as a last resort because it doesn’t automatically end the step.
You must call the end method on the step object to end the step and send it to the platform.
start_step method, or set them directly on the step object:
Step parameters
uuid
The id of the thread
uuid
The id of the step. If not provided, a random uuid will be generated. Use
custom ones to match your own system. Step ids must be unique across your
project.
string
default:""
The name of the step (automatically set to the function name if using the
decorator)
StepType
default:"undefined"
The type of the step. A Step can be one of the following types:
run: A generic steptool: A step that runs a toolllm: A step that runs a language modelembedding: A step that runs an embedding modelretrieval: A step that retrieves documentsrerank: A step that reranks documentsundefined: An undefined step
dict
default:"{}"
Metadata associated with the step. This enables you to add custom fields to
your steps.
uuid
The id of the parent step. This enables you to create nested steps.
string
The start time of the step.
string
The end time of the step.
string
The server-side creation time of the step.
dict
A dictionary symbolizing an input.
Prefer using
content key to store a message.dict
A dictionary symbolizing an output.
Prefer using
content key to store a message.List[str]
default:"[]"
The tags of the step. This is a complimentary field to the metadata field. It
enables you to add custom tags to your steps.
BaseGeneration
The generation object associated with the step.
List[Attachment]
default:"[]"
The attachments associated with the step.