22# -*- coding: utf-8 -*-
33
44import pytest
5+ from decimal import Decimal
56from tokencost .costs import (
67 count_message_tokens ,
78 count_string_tokens ,
@@ -129,21 +130,21 @@ def test_count_string_invalid_model():
129130@pytest .mark .parametrize (
130131 "prompt,model,expected_output" ,
131132 [
132- (MESSAGES , "gpt-3.5-turbo" , 2250 ),
133- (MESSAGES , "gpt-3.5-turbo-0301" , 2550 ),
134- (MESSAGES , "gpt-3.5-turbo-0613" , 2250 ),
135- (MESSAGES , "gpt-3.5-turbo-16k" , 4500 ),
136- (MESSAGES , "gpt-3.5-turbo-16k-0613" , 4500 ),
137- (MESSAGES , "gpt-3.5-turbo-1106" , 750 ),
138- (MESSAGES , "gpt-3.5-turbo-instruct" , 2250 ),
139- (MESSAGES , "gpt-4" , 45000 ),
140- (MESSAGES , "gpt-4-0314" , 45000 ),
141- (MESSAGES , "gpt-4-32k" , 90000 ),
142- (MESSAGES , "gpt-4-32k-0314" , 90000 ),
143- (MESSAGES , "gpt-4-0613" , 45000 ),
144- (MESSAGES , "gpt-4-1106-preview" , 15000 ),
145- (MESSAGES , "gpt-4-vision-preview" , 15000 ),
146- (STRING , "text-embedding-ada-002" , 40 ),
133+ (MESSAGES , "gpt-3.5-turbo" , Decimal ( '0.0000225' ) ),
134+ (MESSAGES , "gpt-3.5-turbo-0301" , Decimal ( '0.0000255' ) ),
135+ (MESSAGES , "gpt-3.5-turbo-0613" , Decimal ( '0.0000225' ) ),
136+ (MESSAGES , "gpt-3.5-turbo-16k" , Decimal ( '0.000045' ) ),
137+ (MESSAGES , "gpt-3.5-turbo-16k-0613" , Decimal ( '0.000045' ) ),
138+ (MESSAGES , "gpt-3.5-turbo-1106" , Decimal ( '0.000015' ) ),
139+ (MESSAGES , "gpt-3.5-turbo-instruct" , Decimal ( '0.0000225' ) ),
140+ (MESSAGES , "gpt-4" , Decimal ( '0.00045' ) ),
141+ (MESSAGES , "gpt-4-0314" , Decimal ( '0.00045' ) ),
142+ (MESSAGES , "gpt-4-32k" , Decimal ( '0.00090' ) ),
143+ (MESSAGES , "gpt-4-32k-0314" , Decimal ( '0.00090' ) ),
144+ (MESSAGES , "gpt-4-0613" , Decimal ( '0.00045' ) ),
145+ (MESSAGES , "gpt-4-1106-preview" , Decimal ( '0.00015' ) ),
146+ (MESSAGES , "gpt-4-vision-preview" , Decimal ( '0.00015' ) ),
147+ (STRING , "text-embedding-ada-002" , Decimal ( '0.0000004' ) ),
147148 ],
148149)
149150def test_calculate_prompt_cost (prompt , model , expected_output ):
@@ -163,20 +164,20 @@ def test_invalid_prompt_format():
163164@pytest .mark .parametrize (
164165 "prompt,model,expected_output" ,
165166 [
166- (STRING , "gpt-3.5-turbo" , 800 ),
167- (STRING , "gpt-3.5-turbo-0301" , 800 ),
168- (STRING , "gpt-3.5-turbo-0613" , 800 ),
169- (STRING , "gpt-3.5-turbo-16k" , 1600 ),
170- (STRING , "gpt-3.5-turbo-16k-0613" , 1600 ),
171- (STRING , "gpt-3.5-turbo-1106" , 600 ),
172- (STRING , "gpt-3.5-turbo-instruct" , 800 ),
173- (STRING , "gpt-4" , 24000 ),
174- (STRING , "gpt-4-0314" , 24000 ),
175- (STRING , "gpt-4-32k" , 48000 ),
176- (STRING , "gpt-4-32k-0314" , 48000 ),
177- (STRING , "gpt-4-0613" , 24000 ),
178- (STRING , "gpt-4-1106-preview" , 12000 ),
179- (STRING , "gpt-4-vision-preview" , 12000 ),
167+ (STRING , "gpt-3.5-turbo" , Decimal ( '0.000008' ) ),
168+ (STRING , "gpt-3.5-turbo-0301" , Decimal ( '0.000008' ) ),
169+ (STRING , "gpt-3.5-turbo-0613" , Decimal ( '0.000008' ) ),
170+ (STRING , "gpt-3.5-turbo-16k" , Decimal ( '0.000016' ) ),
171+ (STRING , "gpt-3.5-turbo-16k-0613" , Decimal ( '0.000016' ) ),
172+ (STRING , "gpt-3.5-turbo-1106" , Decimal ( '0.000008' ) ),
173+ (STRING , "gpt-3.5-turbo-instruct" , Decimal ( '0.000008' ) ),
174+ (STRING , "gpt-4" , Decimal ( '0.00024' ) ),
175+ (STRING , "gpt-4-0314" , Decimal ( '0.00024' ) ),
176+ (STRING , "gpt-4-32k" , Decimal ( '0.00048' ) ),
177+ (STRING , "gpt-4-32k-0314" , Decimal ( '0.00048' ) ),
178+ (STRING , "gpt-4-0613" , Decimal ( '0.00024' ) ),
179+ (STRING , "gpt-4-1106-preview" , Decimal ( '0.00012' ) ),
180+ (STRING , "gpt-4-vision-preview" , Decimal ( '0.00012' ) ),
180181 (STRING , "text-embedding-ada-002" , 0 ),
181182 ],
182183)
0 commit comments