Skip to content

Commit ac2a5ec

Browse files
authored
Merge pull request #97 from WorkflowAI/docs/add-cost-latency-example
docs: add cost and latency tracking example
2 parents 841e707 + 9ccd56c commit ac2a5ec

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,28 @@ https://github.com/user-attachments/assets/65d0f34e-2bb7-42bf-ab5c-be1cca96a2c6
8383

8484
- **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).
8585

86+
```python
87+
class AnswerQuestionInput(BaseModel):
88+
question: str
89+
90+
class AnswerQuestionOutput(BaseModel):
91+
answer: str
92+
93+
@workflowai.agent(id="answer-question")
94+
async def answer_question(input: AnswerQuestionInput) -> AnswerQuestionOutput:
95+
"""
96+
Answer a question.
97+
"""
98+
...
99+
100+
run = await answer_question.run(AnswerQuestionInput(question="What is the history of Paris?"))
101+
print(f"Cost: $ {run.cost_usd:.5f}")
102+
print(f"Latency: {run.duration_seconds:.2f}s")
103+
104+
# Cost: $ 0.00745
105+
# Latency: 8.99s
106+
```
107+
86108
## Get Started
87109

88110
`workflowai` requires Python 3.9 or higher.

0 commit comments

Comments
 (0)