mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 00:35:00 +00:00
compute cost
This commit is contained in:
parent
d2b9cb9e98
commit
5c432592cd
2 changed files with 34 additions and 4 deletions
|
@ -38,6 +38,7 @@ class Coder:
|
||||||
last_asked_for_commit_time = 0
|
last_asked_for_commit_time = 0
|
||||||
repo_map = None
|
repo_map = None
|
||||||
functions = None
|
functions = None
|
||||||
|
total_cost = 0.0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
|
@ -526,12 +527,22 @@ class Coder:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
prompt_tokens = completion.usage.prompt_tokens
|
||||||
|
completion_tokens = completion.usage.completion_tokens
|
||||||
|
|
||||||
|
tokens = f"{prompt_tokens} prompt tokens, {completion_tokens} completion tokens"
|
||||||
|
if self.main_model.prompt_price:
|
||||||
|
cost = prompt_tokens * self.main_model.prompt_price / 1000
|
||||||
|
cost += completion_tokens * self.main_model.completion_price / 1000
|
||||||
|
tokens += f", ${cost:.6f} cost"
|
||||||
|
self.total_cost += cost
|
||||||
|
|
||||||
show_resp = self.render_incremental_response(True)
|
show_resp = self.render_incremental_response(True)
|
||||||
if self.pretty:
|
if self.pretty:
|
||||||
md = Markdown(show_resp, style=self.assistant_output_color, code_theme="default")
|
show_resp = Markdown(show_resp, style=self.assistant_output_color, code_theme="default")
|
||||||
self.io.console.print(md)
|
|
||||||
else:
|
self.io.console.print(show_resp)
|
||||||
print(show_resp)
|
self.io.console.print(tokens)
|
||||||
|
|
||||||
def show_send_output_stream(self, completion, silent):
|
def show_send_output_stream(self, completion, silent):
|
||||||
live = None
|
live = None
|
||||||
|
|
|
@ -11,6 +11,9 @@ class Model:
|
||||||
use_repo_map = False
|
use_repo_map = False
|
||||||
send_undo_reply = False
|
send_undo_reply = False
|
||||||
|
|
||||||
|
prompt_price = None
|
||||||
|
completion_price = None
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
@ -33,11 +36,27 @@ class Model:
|
||||||
self.edit_format = "diff"
|
self.edit_format = "diff"
|
||||||
self.use_repo_map = True
|
self.use_repo_map = True
|
||||||
self.send_undo_reply = True
|
self.send_undo_reply = True
|
||||||
|
|
||||||
|
if tokens == 8:
|
||||||
|
self.prompt_price = 0.03
|
||||||
|
self.completion_price = 0.06
|
||||||
|
elif tokens == 32:
|
||||||
|
self.prompt_price = 0.06
|
||||||
|
self.completion_price = 0.12
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.is_gpt35():
|
if self.is_gpt35():
|
||||||
self.edit_format = "whole-func"
|
self.edit_format = "whole-func"
|
||||||
self.always_available = True
|
self.always_available = True
|
||||||
|
|
||||||
|
if tokens == 4:
|
||||||
|
self.prompt_price = 0.0015
|
||||||
|
self.completion_price = 0.002
|
||||||
|
elif tokens == 16:
|
||||||
|
self.prompt_price = 0.003
|
||||||
|
self.completion_price = 0.004
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
raise ValueError(f"Unsupported model: {name}")
|
raise ValueError(f"Unsupported model: {name}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue