Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return number of tokens spent on a task #127

Open
fjrdomingues opened this issue Apr 27, 2023 · 1 comment
Open

return number of tokens spent on a task #127

fjrdomingues opened this issue Apr 27, 2023 · 1 comment

Comments

@fjrdomingues
Copy link
Owner

fjrdomingues commented Apr 27, 2023

I need the main function on ui.js to also return the number of tokens that were spent on a task.
There are already modules in the project to calculate the number of tokens for all gpt calls, but those counts don't happen on the ui.js file. Use the ui.js on the root of the project.
There should be a variable that stores the total tokens, on the ui.js, and that gets incremented each time there's an API call to gpt, which happens on different modules. You also need to make sure that the app gets the value from the module that runs gpt calls and is able to provide that context to the ui.js file.

Present a solution to implement this on the current app.

Repository owner deleted a comment from codeautopilot bot Apr 27, 2023
Repository owner deleted a comment from codeautopilot bot Apr 27, 2023
Repository owner deleted a comment from codeautopilot bot Apr 27, 2023
@codeautopilot
Copy link

codeautopilot bot commented Apr 27, 2023

🤖 This is my suggestion:

I am moderately confident in the solution provided. Here's a summary of the changes you need to make to implement the requested feature:

  1. Modify the modules/gpt.js file to export the totalTokensUsed variable and create a function to reset it.
  2. In the ui.js file, create a variable totalTokensSpent to store the total tokens spent on a task.
  3. Modify the runAgent function in the modules/interactiveAgent.js file to return the number of tokens spent on the API call.
  4. Update the calls to runAgent in the ui.js file to handle the new return value and increment the totalTokensSpent variable.
  5. Modify the main function in the ui.js file to return the totalTokensSpent variable along with the solutions array.

Here are the code snippets for each step:

modules/gpt.js:

module.exports.totalTokensUsed = totalTokensUsed;

function resetTotalTokensUsed() {
  totalTokensUsed = 0;
}

module.exports.resetTotalTokensUsed = resetTotalTokensUsed;

ui.js:

let totalTokensSpent = 0;

const { result: relevantFilesChunk, tokensSpent } = await runAgent(getRelevantFiles, task, summaries, interactive);
totalTokensSpent += tokensSpent;

return { solutions, totalTokensSpent };

Please note that this solution assumes that the runAgent function in the modules/interactiveAgent.js file is modified to return the number of tokens spent on the API call. If this is not the case, you may need to adjust the solution accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant