File tree Expand file tree Collapse file tree 4 files changed +153
-65
lines changed Expand file tree Collapse file tree 4 files changed +153
-65
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,10 @@ format:
4141	poetry run pyupgrade --py310-plus --exit-zero-even-if-changed ${SRCFILES} 
4242	poetry run black ${SRCDIRS} 
4343
44+ update-models :
45+ 	wayback_url=$$(curl "https://archive.org/wayback/available?url=openai.com/api/pricing/" | jq -r '.archived_snapshots.closest.url' )  &&  \ 
46+ 		gptme ' update the model metadata from this page' " $$ {wayback_url}" 
47+ 
4448precommit : format lint typecheck test
4549
4650docs/.clean : docs/conf.py
Original file line number Diff line number Diff line change 44
55from  .constants  import  TEMPERATURE , TOP_P 
66from  .message  import  Message , msgs2dicts 
7+ from  .models  import  ModelMeta 
78
89if  TYPE_CHECKING :
910    from  openai  import  OpenAI 
Original file line number Diff line number Diff line change 1+ from  typing  import  TypedDict 
2+ from  typing_extensions  import  NotRequired 
3+ 
4+ class  _ModelDictMeta (TypedDict ):
5+     context : int 
6+     max_output : NotRequired [int ]
7+     price_input : NotRequired [float ]
8+     price_output : NotRequired [float ]
9+ 
10+ OPENAI_MODELS : dict [str , _ModelDictMeta ] =  {
11+     # GPT-4o 
12+     "gpt-4o" : {
13+         "context" : 128_000 ,
14+         "price_input" : 5 ,
15+         "price_output" : 15 ,
16+     },
17+     "gpt-4o-2024-08-06" : {
18+         "context" : 128_000 ,
19+         "price_input" : 2.5 ,
20+         "price_output" : 10 ,
21+     },
22+     "gpt-4o-2024-05-13" : {
23+         "context" : 128_000 ,
24+         "price_input" : 5 ,
25+         "price_output" : 15 ,
26+     },
27+     # GPT-4o mini 
28+     "gpt-4o-mini" : {
29+         "context" : 128_000 ,
30+         "price_input" : 0.15 ,
31+         "price_output" : 0.6 ,
32+     },
33+     "gpt-4o-mini-2024-07-18" : {
34+         "context" : 128_000 ,
35+         "price_input" : 0.15 ,
36+         "price_output" : 0.6 ,
37+     },
38+     # OpenAI o1-preview 
39+     "o1-preview" : {
40+         "context" : 128_000 ,
41+         "price_input" : 15 ,
42+         "price_output" : 60 ,
43+     },
44+     "o1-preview-2024-09-12" : {
45+         "context" : 128_000 ,
46+         "price_input" : 15 ,
47+         "price_output" : 60 ,
48+     },
49+     # OpenAI o1-mini 
50+     "o1-mini" : {
51+         "context" : 128_000 ,
52+         "price_input" : 3 ,
53+         "price_output" : 12 ,
54+     },
55+     "o1-mini-2024-09-12" : {
56+         "context" : 128_000 ,
57+         "price_input" : 3 ,
58+         "price_output" : 12 ,
59+     },
60+     # GPT-4 Turbo 
61+     "gpt-4-turbo" : {
62+         "context" : 128_000 ,
63+         "price_input" : 10 ,
64+         "price_output" : 30 ,
65+     },
66+     "gpt-4-turbo-2024-04-09" : {
67+         "context" : 128_000 ,
68+         "price_input" : 10 ,
69+         "price_output" : 30 ,
70+     },
71+     "gpt-4-0125-preview" : {
72+         "context" : 128_000 ,
73+         "price_input" : 10 ,
74+         "price_output" : 30 ,
75+     },
76+     "gpt-4-1106-preview" : {
77+         "context" : 128_000 ,
78+         "price_input" : 10 ,
79+         "price_output" : 30 ,
80+     },
81+     "gpt-4-vision-preview" : {
82+         "context" : 128_000 ,
83+         "price_input" : 10 ,
84+         "price_output" : 30 ,
85+     },
86+     # GPT-4 
87+     "gpt-4" : {
88+         "context" : 8192 ,
89+         "price_input" : 30 ,
90+         "price_output" : 60 ,
91+     },
92+     "gpt-4-32k" : {
93+         "context" : 32768 ,
94+         "price_input" : 60 ,
95+         "price_output" : 120 ,
96+     },
97+     # GPT-3.5 Turbo 
98+     "gpt-3.5-turbo-0125" : {
99+         "context" : 16385 ,
100+         "price_input" : 0.5 ,
101+         "price_output" : 1.5 ,
102+     },
103+     "gpt-3.5-turbo" : {
104+         "context" : 16385 ,
105+         "price_input" : 0.5 ,
106+         "price_output" : 1.5 ,
107+     },
108+     "gpt-3.5-turbo-instruct" : {
109+         "context" : 4096 ,
110+         "price_input" : 1.5 ,
111+         "price_output" : 2 ,
112+     },
113+     # Deprecated models (kept for reference) 
114+     "gpt-3.5-turbo-1106" : {
115+         "context" : 16385 ,
116+         "price_input" : 1 ,
117+         "price_output" : 2 ,
118+     },
119+     "gpt-3.5-turbo-0613" : {
120+         "context" : 4096 ,
121+         "price_input" : 1.5 ,
122+         "price_output" : 2 ,
123+     },
124+     "gpt-3.5-turbo-16k-0613" : {
125+         "context" : 16385 ,
126+         "price_input" : 3 ,
127+         "price_output" : 4 ,
128+     },
129+     "gpt-3.5-turbo-0301" : {
130+         "context" : 4096 ,
131+         "price_input" : 1.5 ,
132+         "price_output" : 2 ,
133+     },
134+     # Other models 
135+     "davinci-002" : {
136+         "context" : 4096 ,  # Assuming default context size 
137+         "price_input" : 2 ,
138+         "price_output" : 2 ,
139+     },
140+     "babbage-002" : {
141+         "context" : 4096 ,  # Assuming default context size 
142+         "price_input" : 0.4 ,
143+         "price_output" : 0.4 ,
144+     },
145+ }
Original file line number Diff line number Diff line change 44
55from  typing_extensions  import  NotRequired 
66
7+ from  .llm_openai_models  import  OPENAI_MODELS 
8+ 
79logger  =  logging .getLogger (__name__ )
810
911
@@ -38,71 +40,7 @@ class _ModelDictMeta(TypedDict):
3840# known models metadata 
3941# TODO: can we get this from the API? 
4042MODELS : dict [str , dict [str , _ModelDictMeta ]] =  {
41-     "openai" : {
42-         # gpt-3.5 
43-         "gpt-3.5-turbo" : {
44-             "context" : 4097 ,
45-             "price_input" : 1 ,
46-             "price_output" : 2 ,
47-         },
48-         "gpt-3.5-turbo-16k" : {
49-             "context" : 16385 ,
50-         },
51-         "gpt-3.5-turbo-1106" : {
52-             "context" : 16385 ,
53-         },
54-         # gpt-4 
55-         "gpt-4" : {
56-             "context" : 8193 ,
57-             "price_input" : 30 ,
58-             "price_output" : 60 ,
59-         },
60-         "gpt-4-32k" : {
61-             "context" : 32769 ,
62-             "price_input" : 60 ,
63-             "price_output" : 120 ,
64-         },
65-         # gpt-4-turbo 
66-         # https://openai.com/blog/new-models-and-developer-products-announced-at-devday 
67-         "gpt-4-1106-preview" : {
68-             "context" : 128_000 ,
69-         },
70-         "gpt-4-vision-preview" : {
71-             "context" : 128_000 ,
72-         },
73-         "gpt-4-turbo" : {
74-             "context" : 128_000 ,
75-             "price_input" : 10 ,
76-             "price_output" : 30 ,
77-         },
78-         "gpt-4o" : {
79-             "context" : 128_000 ,
80-             "price_input" : 5 ,
81-             "price_output" : 15 ,
82-         },
83-         "gpt-4o-2024-08-06" : {
84-             "context" : 128_000 ,
85-             "price_input" : 2.5 ,
86-             "price_output" : 10 ,
87-         },
88-         "gpt-4o-mini" : {
89-             "context" : 128_000 ,
90-             "price_input" : 0.15 ,
91-             "price_output" : 0.6 ,
92-         },
93-         "o1-mini" : {
94-             "context" : 128_000 ,
95-             "max_output" : 65536 ,
96-             "price_input" : 3 ,
97-             "price_output" : 12 ,
98-         },
99-         "o1-preview" : {
100-             "context" : 128_000 ,
101-             "max_output" : 32768 ,
102-             "price_input" : 15 ,
103-             "price_output" : 60 ,
104-         },
105-     },
43+     "openai" : OPENAI_MODELS ,
10644    "anthropic" : {
10745        "claude-3-opus-20240229" : {
10846            "context" : 200_000 ,
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments