Skip to main content
Ops produce Calls. An Op is a function or method that you decorate with @weave.op. By default, the Op’s name is the function name, and the associated Calls have the same display name. You can override the display name for all Calls of a given Op in several ways.
  1. Change the display name at the time of calling the Op. The following example uses the __weave dictionary to set the Call display name that will take precedence over the Op display name:
result = my_function("World", __weave={"display_name": "My Custom Display Name"})
  1. Change the display name on a per-Call basis. The following example uses the Op.call method to return a call object, which you can then use to set the display name using call.set_display_name:
result, call = my_function.call("World")
call.set_display_name("My Custom Display Name")
  1. Change the display name for all Calls of a given Op. The following example sets the new display name in the @weave.op function decorator itself to affect all Calls for the Op:
@weave.op(call_display_name="My Custom Display Name")
def my_function(name: str):
    return f"Hello, {name}!"
The call_display_name can also be a function that takes in a call object and returns a string. Weave passes the call object automatically when the function runs, so you can use it to dynamically generate names based on the function’s name, Call inputs, fields, and so on.One common use case is appending a timestamp to the function’s name.
from datetime import datetime

@weave.op(call_display_name=lambda call: f"{call.func_name}__{datetime.now()}")
def func():
    return ...
You can also log custom metadata using .attributes.
def custom_attribute_name(call):
    model = call.attributes["model"]
    revision = call.attributes["revision"]
    now = call.attributes["date"]

    return f"{model}__{revision}__{now}"

@weave.op(call_display_name=custom_attribute_name)
def func():
    return ...

with weave.attributes(
    {
        "model": "finetuned-llama-3.1-8b",
        "revision": "v0.1.2",
        "date": "2024-08-01",
    }
):
    func()  # the display name will be "finetuned-llama-3.1-8b__v0.1.2__2024-08-01"

    with weave.attributes(
        {
            "model": "finetuned-gpt-4o",
            "revision": "v0.1.3",
            "date": "2024-08-02",
        }
    ):
        func()  # the display name will be "finetuned-gpt-4o__v0.1.3__2024-08-02"
  1. Change the display name of the Op itself. Calls associated with an Op have the same display name. If you override the name of the Op itself, the display name of the Call also changes. You can do this in two ways:
  • Set the name property of the Op before any Calls are logged:
my_function.name = "My Custom Op Name"
  • Set the name option on the Op decorator:
@weave.op(name="My Custom Op Name")
You can also update a call’s display name after execution.