비용 계산하기
대규모로 AI 기능을 배포하기 전에 비용을 추정하는 것은 필수입니다. 비용은 사용한 입력/출력 토큰 수와 선택한 모델에 따라 달라집니다.
여러분의 과제는 고객 채팅 기록을 요약하는 데 드는 비용을 계산하는 것입니다.
OpenAI client와 prompt, max_tokens는 미리 로드되어 있습니다.
이 연습은 강의의 일부입니다
Python으로 DeepSeek 활용하기
연습 안내
response에서 입력 토큰 사용량을 추출하세요.- 출력 토큰 비용을 더하도록 비용 계산을 완성하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4-Pro",
messages=[{"role": "user", "content": prompt}],
max_tokens=max_tokens
)
input_token_price = 2.1 / 1_000_000
output_token_price = 4.4 / 1_000_000
# Extract token usage
input_tokens = response.____.____
output_tokens = max_tokens
# Calculate cost
cost = (input_tokens * input_token_price + ____ * ____)
print(f"Estimated cost: ${cost}")