python-fastllm 0.0.64__py3-none-any.whl → 0.0.65__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastllm/__init__.py +1 -1
- fastllm/anthropic.py +9 -12
- fastllm/model_prices.json +3890 -964
- fastllm/openai_chat.py +4 -8
- fastllm/types.py +19 -15
- {python_fastllm-0.0.64.dist-info → python_fastllm-0.0.65.dist-info}/METADATA +1 -1
- python_fastllm-0.0.65.dist-info/RECORD +18 -0
- python_fastllm-0.0.64.dist-info/RECORD +0 -18
- {python_fastllm-0.0.64.dist-info → python_fastllm-0.0.65.dist-info}/WHEEL +0 -0
- {python_fastllm-0.0.64.dist-info → python_fastllm-0.0.65.dist-info}/entry_points.txt +0 -0
- {python_fastllm-0.0.64.dist-info → python_fastllm-0.0.65.dist-info}/top_level.txt +0 -0
fastllm/__init__.py
CHANGED
fastllm/anthropic.py
CHANGED
|
@@ -11,7 +11,6 @@ __all__ = ['ant_tc_types', 'norm_tool_call', 'norm_tool_calls', 'norm_usage', 'f
|
|
|
11
11
|
|
|
12
12
|
# %% ../nbs/06_anthropic.ipynb #02afd3d7
|
|
13
13
|
import json, copy
|
|
14
|
-
from collections import Counter
|
|
15
14
|
from fastcore.utils import *
|
|
16
15
|
from fastcore.meta import *
|
|
17
16
|
from fasttransport.errors import api_error_from_event
|
|
@@ -337,7 +336,9 @@ def apply_cache_idxs(
|
|
|
337
336
|
def mk_payload(msgs, model, **kwargs):
|
|
338
337
|
sp = kwargs.get('system')
|
|
339
338
|
if (ci:=kwargs.get('cache_idxs')) is not None: sp = apply_cache_idxs(msgs, ci, sp, kwargs.get('ttl'))
|
|
340
|
-
|
|
339
|
+
max_tokens = kwargs.get('max_tokens')
|
|
340
|
+
if max_tokens is None: max_tokens = get_model_info(model, 'anthropic').get('max_output_tokens') or 1024
|
|
341
|
+
payload = dict(model=model, messages=denorm_msgs(msgs), max_tokens=max_tokens)
|
|
341
342
|
if kwargs.get('stream'): payload['stream'] = True
|
|
342
343
|
if sp: payload['system'] = denorm_system(sp)
|
|
343
344
|
if tools:=kwargs.get('tools'): payload['tools'] = denorm_tool_schs(tools)
|
|
@@ -358,17 +359,13 @@ def get_hdrs(api_key=None, oauth_token=None):
|
|
|
358
359
|
# %% ../nbs/06_anthropic.ipynb #0d03643a
|
|
359
360
|
def cost(usage, m):
|
|
360
361
|
raw = usage.raw
|
|
361
|
-
in_tok = raw['input_tokens']
|
|
362
|
-
cache_read = raw.get('cache_read_input_tokens', 0)
|
|
363
362
|
cc = raw.get('cache_creation', {}) or {}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
cost += cache_1h * m.get('cache_creation_input_token_cost_above_1hr', 0)
|
|
371
|
-
return cost
|
|
363
|
+
prompt = dict(input_cost_per_token=raw['input_tokens'], cache_read_input_token_cost=raw.get('cache_read_input_tokens', 0),
|
|
364
|
+
cache_creation_input_token_cost=cc.get('ephemeral_5m_input_tokens', raw.get('cache_creation_input_tokens', 0)),
|
|
365
|
+
cache_creation_input_token_cost_above_1hr=cc.get('ephemeral_1h_input_tokens', 0))
|
|
366
|
+
tier = price_tier(m, sum(prompt.values()))
|
|
367
|
+
toks = prompt | dict(output_cost_per_token=raw['output_tokens'])
|
|
368
|
+
return sum(n * tier_rate(m, k, tier) for k,n in toks.items())
|
|
372
369
|
|
|
373
370
|
# %% ../nbs/06_anthropic.ipynb #f7c0b989
|
|
374
371
|
api_registry.register('anthropic', norm_tool_calls=norm_tool_calls, norm_parts=norm_parts, norm_finish=norm_finish, norm_usage=norm_usage,
|