From 9ccd56ca75623fd338717fdd60d38674f9b8c0ef Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 12 Apr 2025 15:32:13 -0700 Subject: [PATCH] docs: add cost and latency tracking example --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/README.md b/README.md index dd96f03..602f3a7 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,28 @@ https://github.com/user-attachments/assets/65d0f34e-2bb7-42bf-ab5c-be1cca96a2c6 - **Cost tracking**: Automatically calculates and tracks the cost of each AI model run, providing transparency and helping you manage your AI budget effectively. Learn more about [cost tracking](https://docs.workflowai.com/python-sdk/agent#cost-latency). +```python +class AnswerQuestionInput(BaseModel): + question: str + +class AnswerQuestionOutput(BaseModel): + answer: str + +@workflowai.agent(id="answer-question") +async def answer_question(input: AnswerQuestionInput) -> AnswerQuestionOutput: + """ + Answer a question. + """ + ... + +run = await answer_question.run(AnswerQuestionInput(question="What is the history of Paris?")) +print(f"Cost: $ {run.cost_usd:.5f}") +print(f"Latency: {run.duration_seconds:.2f}s") + +# Cost: $ 0.00745 +# Latency: 8.99s +``` + ## Get Started `workflowai` requires Python 3.9 or higher.