Documentation Index
Fetch the complete documentation index at: https://translations.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
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)
# 프로젝트의 모든 호출(calls)을 가져옵니다
calls = list(
client.get_calls(filter={"trace_roots_only": True}, include_costs=True)
)
for call in calls:
# 호출에 비용 정보가 있으면 총 비용에 더합니다
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"]
# 총 비용, 요청 수, 호출(calls) 수를 반환합니다
return {
"total_cost": total_cost,
"requests": requests,
"calls": len(calls),
}
# 함수에 @weave.op() 데코레이터를 사용했기 때문에,
# 총합이 weave에 저장되어 이후 비용 총계 계산에 사용할 수 있습니다
get_costs_for_project("my_custom_cost_model")
이 기능은 아직 TypeScript에서는 사용할 수 없습니다. 곧 제공될 예정입니다!
사용자 정의 비용이 적용된 커스텀 모델 설정하기
커스텀 모델에 비용 설정하기 쿡북을 참고하세요.