MetaGPT icon indicating copy to clipboard operation
MetaGPT copied to clipboard

How to check total cost use

Open phanchauthang opened this issue 1 year ago • 3 comments

Hello MetaGPT, i have use metaGPT many time and it save to one 1 log with many project i have create, so how can i check total cost and token use in each project, thanks you so much.

phanchauthang avatar Jun 05 '24 13:06 phanchauthang

For now, MetaGPT will calculate the cost each time calling the API and the cost will be accumulated when running a project. The cost of one project is the last cost calculation message in the log. Since the log of different project may be saved to the same log.txt like 20240605.txt and the calculation will be mixed. you can use grep "Total running cost" -n path/to/your_log.txt to manually extract the cost.

usamimeri avatar Jun 05 '24 13:06 usamimeri

@garylin2099 Is it able to set the log_name for a particular project?

usamimeri avatar Jun 05 '24 13:06 usamimeri

@garylin2099 Is it able to set the log_name for a particular project?

I know this, we can do something like this, In main.py file:

from metagpt.logs import logger, define_log_level

def set_log_name():
    global logger
    logger = define_log_level(name="MY_PROJECT")  # This will create a file as: MY_PROJECT_20240605.txt

set_log_name()

Or, we could define a custom define_log_level to change the name of file to anything else.

Kaushal-26 avatar Jun 05 '24 16:06 Kaushal-26

Since no further responses are needed, we will close it. Please reopen it if necessary.

better629 avatar Oct 09 '24 17:10 better629