AutoGPT
AutoGPT copied to clipboard
Make Auto-GPT aware of its running cost
Background
This pull request addresses issue #6, which aims to make Auto-GPT aware of its running cost. The changes centralize all OpenAI Chat Completion calls through a single method that counts tokens and adds to a dollar amount based on the model used. The total dollar amount spent is constantly displayed to the user and is shown to the AI as well.
The user is also asked to provide an optional API budget dollar amount. If they enter nothing, there is no monetary limit, but if they define a budget then the AI will be told to shut down gracefully once it has come within 1 cent of its limit, and to shut down immediately once it has exceeded its limit. The AI is always aware of its initial and remaining budget.
Changes
- Centralized chat completion API calls through
ApiManager
class inapi_manager.py
- Removed openai imports from other files to prevent accidental API calls
- Updated
AIConfig
class to include an optionalapi_budget
parameter - Modified
chat_with_ai
function to includeapi_budget
and display remaining budget to the AI - Updated
browse.py
,call_ai_function.py
,chat.py
, andmain.py
to use the centralizedApiManager
- Added input for API budget to
load_variables
andconstruct_prompt
functions inmain.py
Documentation
There are Docstrings and in-code comments documenting things where necessary
Test Plan
I have tested this feature in the following ways:
- Various different prompts were used, assigning Auto-GPT to various different tasks, and it did not encounter any more errors than before the change
- I put an empty string for the budget, and the AI proceeded as if it had infinite budget
- I put a dollar amount for the budget, and the AI proceeded as if it had a limited budget, hurrying itself up as the budget depleted
- The AI shuts itself down once the budget is exceeded
- The total running cost is being printed to the console for the user to see upon every chat completion, and the amount makes sense for the models used
PR Quality Checklist
- [x] My pull request is atomic and focuses on a single change.
- [x] I have thoroughly tested my changes with multiple different prompts.
- [x] I have considered potential risks and mitigations for my changes.
- [x] I have documented my changes clearly and comprehensively.
- [x] I have not snuck in any "extra" small tweaks changes
I hope this gets added - it's pretty fundamental information for Auto-GPT, especially Entrepreneur-GPT (the default agent).
The change scope is too big and it needs to be split. So I suggest just to extract the api_manager from the code first, preserving the current behavior. And then change the behavior in a separate PR.
Sure! I could make a new PR with just the first two commits. Those only deal with adding the api_manager, routing chat completions through it, and printing the total running cost to the console.
EDIT:
oops, I lied. It also prints the total running cost to the AI. Should I remove that part in my new pull request?
create_chat_message(
"system", f"Your current running cost is ${api_manager.get_total_cost():.3f}"),
@Torantulino we need you to approve the plan
@nponeccop @Torantulino Shall I implement the plan detailed above? In my new PR, I can also update the code with the latest changes to master.
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
I'll take those bot messages as a sign I should stay in this pull request, merge in master, and get everything working with the latest changes? Okay, will do!
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.
I am so pleased someone created this PR, thanks @Vwing. This does not track the cost of the embedding calls. While this could be it be added in a future PR, it may confuse end users when their bill is larger than they expect. I am happy to contribute this extra feature if you want, just let me know.
Sure, @rob-luke. That would be much appreciated!
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.
@rob-luke Heads up, I merged in master to resolve the conflicts.
Almost there, please fix the linting errors 🥁
@Pwuts done!
I dont want to block this from getting merged, so I will just create a follow up PR once this is merged
I added the tracking of embedding costs and opened a PR in to this branch here: https://github.com/Vwing/Auto-GPT/pull/1 But if you merge this branch as is, then I will just open a fresh PR in to master of this repo later. Thanks again for the great package and for this PR.
I merged in your changes, @rob-luke, they look good! Just make sure next time to run the linter
@BillSchumacher I don't know if you've started reviewing this PR yet, but just to let you know I merged in @rob-luke's changes so it tracks embedding costs.
Thanks Vwing, and sorry for missing the linting. Thanks for fixing my errors
Can you update from the latest? theres some changes to the pipelines that need to run @Vwing
Yep! I'm on it.
Give it a bit, you’ll have to do it twice if not
This pull request has conflicts with the base branch, please resolve those so we can evaluate the pull request.
Okay, I screwed up and merged too soon 😅
I'm going to try to clean up my history. I'll be a moment...
Conflicts have been resolved! 🎉 A maintainer will review the pull request shortly.
Heads up this may need scheduled in
Oops, some tests failed. I can fix that...
Hi @ntindle, I notice that the test is failing because it's using the "gpt2" model, which isn't an option for OpenAI chat completions. I'm wondering how we should proceed in this case. Should I check for invalid models and fail quietly, or do you think it's better to update the test to use a valid model? Looking forward to your guidance, thanks!