Implement API Cost Estimation and Logging for Agent Interactions (Fixes #66) #67
+85
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Overview
This pull request introduces a new feature to estimate the cost of each API interaction and log it, as outlined in Issue #66: Estimate cost of each API interaction and log it. The modifications include the creation of a cost tracking module, updates to existing functionalities, and integrated logging capabilities.
Summary of Changes
New Module -
cost_tracker.py
:cost_tracker.py
has been added to theutils
directory. This module includes:CostTracker
class: Responsible for tracking API costs associated with different agent types.api_costs.log
file, ensuring all interactions are logged with timestamps and cost breakdowns.Modifications to
agent_market.py
:get_pr_title
andget_pr_body
to incorporate cost tracking for OpenAI API calls.Updates to
utils/__init__.py
:cost_tracker
instance into the module exports.__all__
list to includecost_tracker
, ensuring accessibility across other modules.Implementation Outcome
This implementation effectively addresses the requirements set out in Issue #66 by providing a robust cost tracking and logging system for API interactions. The new functionality:
With this enhancement, the project now offers better financial transparency in API interactions, supporting both developers and users in understanding and managing their API usage costs.
Closing Notes
Please review the changes and provide feedback or suggestions for further improvements. This pull request aims to enhance the overall functionality and maintainability of the project.
Fixes #66