@ -5,21 +5,33 @@ from langchain.callbacks.base import BaseCallbackHandler
from langchain . schema import AgentAction , AgentFinish , LLMResult
from langchain . schema import AgentAction , AgentFinish , LLMResult
MODEL_COST_PER_1K_TOKENS = {
MODEL_COST_PER_1K_TOKENS = {
# GPT-4 input
" gpt-4 " : 0.03 ,
" gpt-4 " : 0.03 ,
" gpt-4-0314 " : 0.03 ,
" gpt-4-0314 " : 0.03 ,
" gpt-4-completion " : 0.06 ,
" gpt-4-0613 " : 0.03 ,
" gpt-4-0314-completion " : 0.06 ,
" gpt-4-32k " : 0.06 ,
" gpt-4-32k " : 0.06 ,
" gpt-4-32k-0314 " : 0.06 ,
" gpt-4-32k-0314 " : 0.06 ,
" gpt-4-32k-0613 " : 0.06 ,
# GPT-4 output
" gpt-4-completion " : 0.06 ,
" gpt-4-0314-completion " : 0.06 ,
" gpt-4-0613-completion " : 0.06 ,
" gpt-4-32k-completion " : 0.12 ,
" gpt-4-32k-completion " : 0.12 ,
" gpt-4-32k-0314-completion " : 0.12 ,
" gpt-4-32k-0314-completion " : 0.12 ,
" gpt-4-0613 " : 0.06 ,
" gpt-4-32k-0613-completion " : 0.12 ,
" gpt-4-32k-0613 " : 0.12 ,
# GPT-3.5 input
" gpt-3.5-turbo " : 0.002 ,
" gpt-3.5-turbo " : 0.0015 ,
" gpt-3.5-turbo-0301 " : 0.002 ,
" gpt-3.5-turbo-0301 " : 0.0015 ,
" gpt-3.5-turbo-16k " : 0.004 ,
" gpt-3.5-turbo-0613 " : 0.0015 ,
" gpt-3.5-turbo-0613 " : 0.002 ,
" gpt-3.5-turbo-16k " : 0.003 ,
" gpt-3.5-turbo-16k-0613 " : 0.004 ,
" gpt-3.5-turbo-16k-0613 " : 0.003 ,
# GPT-3.5 output
" gpt-3.5-turbo-completion " : 0.002 ,
" gpt-3.5-turbo-0301-completion " : 0.002 ,
" gpt-3.5-turbo-0613-completion " : 0.002 ,
" gpt-3.5-turbo-16k-completion " : 0.004 ,
" gpt-3.5-turbo-16k-0613-completion " : 0.004 ,
# Others
" text-ada-001 " : 0.0004 ,
" text-ada-001 " : 0.0004 ,
" ada " : 0.0004 ,
" ada " : 0.0004 ,
" text-babbage-001 " : 0.0005 ,
" text-babbage-001 " : 0.0005 ,
@ -43,7 +55,9 @@ def standardize_model_name(
model_name = model_name . lower ( )
model_name = model_name . lower ( )
if " ft- " in model_name :
if " ft- " in model_name :
return model_name . split ( " : " ) [ 0 ] + " -finetuned "
return model_name . split ( " : " ) [ 0 ] + " -finetuned "
elif is_completion and model_name . startswith ( " gpt-4 " ) :
elif is_completion and (
model_name . startswith ( " gpt-4 " ) or model_name . startswith ( " gpt-3.5 " )
) :
return model_name + " -completion "
return model_name + " -completion "
else :
else :
return model_name
return model_name