3030 StandardModelParamNames ,
3131 StandardModelParams ,
3232)
33- from ._tokens import get_token_pricing , tokens_log
33+ from ._tokens import get_token_pricing
3434from ._tools import Tool , basemodel_to_param_schema
3535from ._turn import Turn , user_turn
3636from ._utils import split_http_client_kwargs
@@ -242,28 +242,6 @@ def list_models(self):
242242
243243 return res
244244
245- @overload
246- def chat_perform (
247- self ,
248- * ,
249- stream : Literal [False ],
250- turns : list [Turn ],
251- tools : dict [str , Tool ],
252- data_model : Optional [type [BaseModel ]] = None ,
253- kwargs : Optional ["SubmitInputArgs" ] = None ,
254- ): ...
255-
256- @overload
257- def chat_perform (
258- self ,
259- * ,
260- stream : Literal [True ],
261- turns : list [Turn ],
262- tools : dict [str , Tool ],
263- data_model : Optional [type [BaseModel ]] = None ,
264- kwargs : Optional ["SubmitInputArgs" ] = None ,
265- ): ...
266-
267245 def chat_perform (
268246 self ,
269247 * ,
@@ -276,28 +254,6 @@ def chat_perform(
276254 kwargs = self ._chat_perform_args (stream , turns , tools , data_model , kwargs )
277255 return self ._client .messages .create (** kwargs ) # type: ignore
278256
279- @overload
280- async def chat_perform_async (
281- self ,
282- * ,
283- stream : Literal [False ],
284- turns : list [Turn ],
285- tools : dict [str , Tool ],
286- data_model : Optional [type [BaseModel ]] = None ,
287- kwargs : Optional ["SubmitInputArgs" ] = None ,
288- ): ...
289-
290- @overload
291- async def chat_perform_async (
292- self ,
293- * ,
294- stream : Literal [True ],
295- turns : list [Turn ],
296- tools : dict [str , Tool ],
297- data_model : Optional [type [BaseModel ]] = None ,
298- kwargs : Optional ["SubmitInputArgs" ] = None ,
299- ): ...
300-
301257 async def chat_perform_async (
302258 self ,
303259 * ,
@@ -411,6 +367,17 @@ def stream_turn(self, completion, has_data_model) -> Turn:
411367 def value_turn (self , completion , has_data_model ) -> Turn :
412368 return self ._as_turn (completion , has_data_model )
413369
370+ def value_tokens (self , completion ):
371+ usage = completion .usage
372+ # N.B. Currently, Anthropic doesn't cache by default and we currently do not support
373+ # manual caching in chatlas. Note also that this only tracks reads, NOT writes, which
374+ # have their own cost. To track that properly, we would need another caching category and per-token cost.
375+ return (
376+ completion .usage .input_tokens ,
377+ completion .usage .output_tokens ,
378+ usage .cache_read_input_tokens if usage .cache_read_input_tokens else 0 ,
379+ )
380+
414381 def token_count (
415382 self ,
416383 * args : Content | str ,
@@ -619,23 +586,9 @@ def _as_turn(self, completion: Message, has_data_model=False) -> Turn:
619586 )
620587 )
621588
622- usage = completion .usage
623- # N.B. Currently, Anthropic doesn't cache by default and we currently do not support
624- # manual caching in chatlas. Note also that this only tracks reads, NOT writes, which
625- # have their own cost. To track that properly, we would need another caching category and per-token cost.
626-
627- tokens = (
628- completion .usage .input_tokens ,
629- completion .usage .output_tokens ,
630- usage .cache_read_input_tokens if usage .cache_read_input_tokens else 0 ,
631- )
632-
633- tokens_log (self , tokens )
634-
635589 return Turn (
636590 "assistant" ,
637591 contents ,
638- tokens = tokens ,
639592 finish_reason = completion .stop_reason ,
640593 completion = completion ,
641594 )
0 commit comments