mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 06:44:59 +00:00
token pricing
This commit is contained in:
parent
c9bb22d6d5
commit
3662a4680b
3 changed files with 20 additions and 16 deletions
|
@ -508,7 +508,7 @@ class Coder:
|
|||
messages += self.cur_messages
|
||||
|
||||
# Add the reminder prompt if we still have room to include it.
|
||||
if total_tokens < self.main_model.max_context_tokens:
|
||||
if total_tokens < self.main_model.info.get("max_input_tokens", 0):
|
||||
messages += reminder_message
|
||||
|
||||
return messages
|
||||
|
@ -707,10 +707,10 @@ class Coder:
|
|||
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
|
||||
if self.main_model.completion_price:
|
||||
cost += completion_tokens * self.main_model.completion_price / 1000
|
||||
if self.main_model.info.get("input_cost_per_token"):
|
||||
cost = prompt_tokens * self.main_model.info.get("input_cost_per_token")
|
||||
if self.main_model.info.get("output_cost_per_token"):
|
||||
cost += completion_tokens * self.main_model.info.get("output_cost_per_token")
|
||||
tokens += f", ${cost:.6f} cost"
|
||||
self.total_cost += cost
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ class Commands:
|
|||
self.io.tool_output()
|
||||
|
||||
width = 8
|
||||
cost_width = 7
|
||||
cost_width = 9
|
||||
|
||||
def fmt(v):
|
||||
return format(int(v), ",").rjust(width)
|
||||
|
@ -188,13 +188,13 @@ class Commands:
|
|||
total_cost = 0.0
|
||||
for tk, msg, tip in res:
|
||||
total += tk
|
||||
cost = tk * (self.coder.main_model.prompt_price / 1000)
|
||||
cost = tk * self.coder.main_model.info.get("input_cost_per_token", 0)
|
||||
total_cost += cost
|
||||
msg = msg.ljust(col_width)
|
||||
self.io.tool_output(f"${cost:5.2f} {fmt(tk)} {msg} {tip}")
|
||||
self.io.tool_output(f"${cost:7.4f} {fmt(tk)} {msg} {tip}")
|
||||
|
||||
self.io.tool_output("=" * (width + cost_width + 1))
|
||||
self.io.tool_output(f"${total_cost:5.2f} {fmt(total)} tokens total")
|
||||
self.io.tool_output(f"${total_cost:7.4f} {fmt(total)} tokens total")
|
||||
|
||||
# only switch to image model token count if gpt4 and openai and image in files
|
||||
image_in_chat = False
|
||||
|
@ -203,7 +203,7 @@ class Commands:
|
|||
is_image_file(relative_fname)
|
||||
for relative_fname in self.coder.get_inchat_relative_files()
|
||||
)
|
||||
limit = 128000 if image_in_chat else self.coder.main_model.max_context_tokens
|
||||
limit = 128000 if image_in_chat else self.coder.main_model.info.get("max_input_tokens")
|
||||
|
||||
remaining = limit - total
|
||||
if remaining > 1024:
|
||||
|
|
|
@ -4,22 +4,26 @@ import math
|
|||
import litellm
|
||||
from PIL import Image
|
||||
|
||||
from aider.dump import dump
|
||||
|
||||
|
||||
class Model:
|
||||
name = None
|
||||
edit_format = "whole"
|
||||
max_context_tokens = 0
|
||||
max_chat_history_tokens = 1024
|
||||
|
||||
always_available = False
|
||||
use_repo_map = False
|
||||
send_undo_reply = False
|
||||
|
||||
prompt_price = None
|
||||
completion_price = None
|
||||
max_chat_history_tokens = 1024
|
||||
|
||||
def __init__(self, model):
|
||||
self.name = model
|
||||
self.info = litellm.get_model_info(model)
|
||||
dump(self.info)
|
||||
|
||||
if self.info.get("max_input_tokens", 0) < 32 * 1024:
|
||||
self.max_chat_history_tokens = 1024
|
||||
else:
|
||||
self.max_chat_history_tokens = 2 * 1024
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue