Documentation Index
Fetch the complete documentation index at: https://wb-21fd5541-john-wbdocs-2044-rename-serverless-products.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
W&B Weave는 token 사용량을 추적하고 사용한 모델의 가격을 적용해 각 LLM call의 비용을 자동으로 계산하므로, 트레이스와 평가에서 애플리케이션 비용을 직접 모니터링하고 분석할 수 있습니다.
또한 다른 가격 기준이 필요하거나 내부 비용 모델을 사용해야 하거나 Weave가 자동으로 가격을 책정하지 않는 오퍼레이션의 비용을 추적해야 하는 경우에는 사용자 정의 비용도 추적할 수 있습니다.
add_cost 방법을 사용해 사용자 정의 비용을 추가할 수 있습니다.
필수 필드는 llm_id, prompt_token_cost, completion_token_cost의 세 가지입니다.
llm_id는 LLM의 이름(예: gpt-4o)입니다. prompt_token_cost와 completion_token_cost는 LLM의 토큰당 비용입니다(LLM 가격이 백만 토큰 기준으로 지정된 경우 값을 반드시 변환하세요).
effective_date를 datetime으로 설정해 특정 날짜부터 비용이 적용되도록 할 수도 있으며, 기본값은 현재 날짜입니다.import weave
from datetime import datetime
client = weave.init("my_custom_cost_model")
client.add_cost(
llm_id="your_model_name",
prompt_token_cost=0.01,
completion_token_cost=0.02
)
client.add_cost(
llm_id="your_model_name",
prompt_token_cost=10,
completion_token_cost=20,
# 예를 들어 특정 날짜 이후에 모델 가격을 올리려는 경우
effective_date=datetime(2025, 4, 22),
)
이 기능은 아직 TypeScript에서 사용할 수 없습니다. 조금만 기다려 주세요!
query_costs 방법을 사용해 비용을 쿼리할 수 있습니다.
비용을 쿼리하는 방법은 몇 가지가 있으며, 단일 비용 ID를 전달하거나 LLM 모델 이름 목록을 전달할 수 있습니다.import weave
client = weave.init("my_custom_cost_model")
costs = client.query_costs(llm_ids=["your_model_name"])
cost = client.query_costs(costs[0].id)
이 기능은 아직 TypeScript에서 사용할 수 없습니다. 조금만 기다려 주세요!
purge_costs 방법을 사용해 사용자 정의 비용을 삭제할 수 있습니다. 비용 ID 목록을 전달하면 해당 ID를 가진 비용이 삭제됩니다.import weave
client = weave.init("my_custom_cost_model")
costs = client.query_costs(llm_ids=["your_model_name"])
client.purge_costs([cost.id for cost in costs])
이 기능은 아직 TypeScript에서 사용할 수 없습니다. 곧 지원될 예정입니다!
약간의 설정만 거치면 calls_query를 사용하고 include_costs=True를 추가해 프로젝트 비용을 계산할 수 있습니다.import weave
weave.init("project_costs")
@weave.op()
def get_costs_for_project(project_name: str):
total_cost = 0
requests = 0
client = weave.init(project_name)
# 프로젝트의 모든 call을 가져옵니다
calls = list(
client.get_calls(filter={"trace_roots_only": True}, include_costs=True)
)
for call in calls:
# call에 비용이 있으면 총비용에 더합니다
if call.summary["weave"] is not None and call.summary["weave"].get("costs", None) is not None:
for k, cost in call.summary["weave"]["costs"].items():
requests += cost["requests"]
total_cost += cost["prompt_tokens_total_cost"]
total_cost += cost["completion_tokens_total_cost"]
# 총비용, 요청 수, call 수를 반환합니다
return {
"total_cost": total_cost,
"requests": requests,
"calls": len(calls),
}
# 함수를 @weave.op()으로 데코레이팅했기 때문에
# 총합은 과거 비용 총계를 계산할 수 있도록 Weave에 저장됩니다
get_costs_for_project("my_custom_cost_model")
이 기능은 아직 TypeScript에서 사용할 수 없습니다. Stay tuned!
사용자 정의 비용을 사용하는 맞춤형 모델 설정하기
맞춤형 모델에 사용자 정의 비용 설정하기 쿡북을 사용해 보세요.