메인 콘텐츠로 건너뛰기

Documentation Index

Fetch the complete documentation index at: https://wb-21fd5541-feature-automate-reference-docs-generation.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Weave op는 모든 호출을 자동으로 기록하는 버전 관리된 함수입니다.
op를 만들려면 Python 함수를 weave.op()
showLineNumbers
import weave

@weave.op()
def track_me(v):
    return v + 5

weave.init('intro-example')
track_me(15)
op를 호출하면 코드가 마지막 호출과 다른 경우 새 op 버전이 생성되고 함수의 입력과 출력이 기록됩니다.:::note @weave.op()로 장식된 함수는 weave.init('your-project-name')를 호출하기 전에 호출하면 정상적으로 작동합니다(코드 버전 관리 및 추적 없이). :::Ops는 served 또는 deployed Weave 툴벨트를 사용하여 할 수 있습니다.

표시 이름 사용자 정의

op의 표시 이름을 name 매개변수를 @weave.op decorator:
@weave.op(name="custom_name")
def func():
    ...

기록된 입력 및 출력 사용자 정의

원래 함수를 수정하지 않고 weave에 기록되는 데이터를 변경하려면(예: 민감한 데이터를 숨기기 위해) postprocess_inputspostprocess_output를 op 데코레이터에 전달할 수 있습니다.postprocess_inputs는 키가 인수 이름이고 값이 인수 값인 dict를 입력으로 받아 변환된 입력이 있는 dict를 반환합니다.postprocess_output는 함수에서 일반적으로 반환되는 모든 값을 입력으로 받아 변환된 출력을 반환합니다.
from dataclasses import dataclass
from typing import Any
import weave

@dataclass
class CustomObject:
    x: int
    secret_password: str

def postprocess_inputs(inputs: dict[str, Any]) -> dict[str, Any]:
    return {k:v for k,v in inputs.items() if k != "hide_me"}

def postprocess_output(output: CustomObject) -> CustomObject:
    return CustomObject(x=output.x, secret_password="REDACTED")

@weave.op(
    postprocess_inputs=postprocess_inputs,
    postprocess_output=postprocess_output,
)
def func(a: int, hide_me: str) -> CustomObject:
    return CustomObject(x=a, secret_password=hide_me)

weave.init('hide-data-example') # 🐝
func(a=1, hide_me="password123")

샘플링 비율 제어

op 호출이 추적되는 빈도를 tracing_sample_rate 매개변수를 @weave.op 데코레이터에서 설정하여 제어할 수 있습니다. 이는 호출의 일부만 추적하면 되는 고빈도 op에 유용합니다.샘플링 비율은 루트 호출에만 적용됩니다. op에 샘플 비율이 있지만 먼저 다른 op에 의해 호출되는 경우 해당 샘플링 비율은 무시됩니다.
@weave.op(tracing_sample_rate=0.1)  # Only trace ~10% of calls
def high_frequency_op(x: int) -> int:
    return x + 1

@weave.op(tracing_sample_rate=1.0)  # Always trace (default)
def always_traced_op(x: int) -> int:
    return x + 1
op의 호출이 샘플링되지 않을 때:
  • 함수가 정상적으로 실행됩니다
  • Weave에 추적 데이터가 전송되지 않습니다
  • 해당 호출에 대한 하위 op도 추적되지 않습니다
샘플링 비율은 0.0에서 1.0 사이여야 합니다(포함).

호출 링크 출력 제어

로깅 중 호출 링크 인쇄를 억제하려면 WEAVE_PRINT_CALL_LINK 환경 변수를 false로 설정할 수 있습니다. 이는 출력 상세도를 줄이고 로그의 혼잡을 줄이려는 경우 유용할 수 있습니다.
export WEAVE_PRINT_CALL_LINK=false

op 삭제

op의 버전을 삭제하려면 op 참조에서 .delete()를 호출합니다.
weave.init('intro-example')
my_op_ref = weave.ref('track_me:v1')
my_op_ref.delete()
삭제된 op에 액세스하려고 하면 오류가 발생합니다.