llmops-observability 8.0.0__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.
- llmops_observability/__init__.py +27 -0
- llmops_observability/asgi_middleware.py +146 -0
- llmops_observability/config.py +79 -0
- llmops_observability/llm.py +580 -0
- llmops_observability/models.py +32 -0
- llmops_observability/pricing.py +132 -0
- llmops_observability/trace_manager.py +641 -0
- llmops_observability-8.0.0.dist-info/METADATA +263 -0
- llmops_observability-8.0.0.dist-info/RECORD +11 -0
- llmops_observability-8.0.0.dist-info/WHEEL +5 -0
- llmops_observability-8.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# pricing.py
|
|
2
|
+
"""
|
|
3
|
+
AWS Bedrock pricing calculator for token-based cost estimation.
|
|
4
|
+
Prices as of 2024 - update as needed.
|
|
5
|
+
"""
|
|
6
|
+
from typing import Dict, Optional
|
|
7
|
+
|
|
8
|
+
# AWS Bedrock pricing per 1K tokens (USD)
|
|
9
|
+
# https://aws.amazon.com/bedrock/pricing/
|
|
10
|
+
BEDROCK_PRICING = {
|
|
11
|
+
# Claude 3.5 Sonnet
|
|
12
|
+
"anthropic.claude-3-5-sonnet-20240620-v1:0": {
|
|
13
|
+
"input": 0.003, # $3 per 1M tokens
|
|
14
|
+
"output": 0.015, # $15 per 1M tokens
|
|
15
|
+
},
|
|
16
|
+
"anthropic.claude-3-5-sonnet-20241022-v2:0": {
|
|
17
|
+
"input": 0.003,
|
|
18
|
+
"output": 0.015,
|
|
19
|
+
},
|
|
20
|
+
# Claude 3 Sonnet
|
|
21
|
+
"anthropic.claude-3-sonnet-20240229-v1:0": {
|
|
22
|
+
"input": 0.003, # $3 per 1M tokens
|
|
23
|
+
"output": 0.015, # $15 per 1M tokens
|
|
24
|
+
},
|
|
25
|
+
# Claude 3 Haiku
|
|
26
|
+
"anthropic.claude-3-haiku-20240307-v1:0": {
|
|
27
|
+
"input": 0.00025, # $0.25 per 1M tokens
|
|
28
|
+
"output": 0.00125, # $1.25 per 1M tokens
|
|
29
|
+
},
|
|
30
|
+
# Claude 3 Opus
|
|
31
|
+
"anthropic.claude-3-opus-20240229-v1:0": {
|
|
32
|
+
"input": 0.015, # $15 per 1M tokens
|
|
33
|
+
"output": 0.075, # $75 per 1M tokens
|
|
34
|
+
},
|
|
35
|
+
# Claude 2.1
|
|
36
|
+
"anthropic.claude-v2:1": {
|
|
37
|
+
"input": 0.008, # $8 per 1M tokens
|
|
38
|
+
"output": 0.024, # $24 per 1M tokens
|
|
39
|
+
},
|
|
40
|
+
# Claude 2.0
|
|
41
|
+
"anthropic.claude-v2": {
|
|
42
|
+
"input": 0.008,
|
|
43
|
+
"output": 0.024,
|
|
44
|
+
},
|
|
45
|
+
# Claude Instant
|
|
46
|
+
"anthropic.claude-instant-v1": {
|
|
47
|
+
"input": 0.0008, # $0.80 per 1M tokens
|
|
48
|
+
"output": 0.0024, # $2.40 per 1M tokens
|
|
49
|
+
},
|
|
50
|
+
# Amazon Titan Text models
|
|
51
|
+
"amazon.titan-text-express-v1": {
|
|
52
|
+
"input": 0.0002, # $0.20 per 1M tokens
|
|
53
|
+
"output": 0.0006, # $0.60 per 1M tokens
|
|
54
|
+
},
|
|
55
|
+
"amazon.titan-text-lite-v1": {
|
|
56
|
+
"input": 0.00015, # $0.15 per 1M tokens
|
|
57
|
+
"output": 0.0002, # $0.20 per 1M tokens
|
|
58
|
+
},
|
|
59
|
+
# Cohere Command
|
|
60
|
+
"cohere.command-text-v14": {
|
|
61
|
+
"input": 0.0015, # $1.50 per 1M tokens
|
|
62
|
+
"output": 0.002, # $2 per 1M tokens
|
|
63
|
+
},
|
|
64
|
+
"cohere.command-light-text-v14": {
|
|
65
|
+
"input": 0.0003, # $0.30 per 1M tokens
|
|
66
|
+
"output": 0.0006, # $0.60 per 1M tokens
|
|
67
|
+
},
|
|
68
|
+
# AI21 Jurassic
|
|
69
|
+
"ai21.j2-ultra-v1": {
|
|
70
|
+
"input": 0.0125, # $12.50 per 1M tokens
|
|
71
|
+
"output": 0.0125,
|
|
72
|
+
},
|
|
73
|
+
"ai21.j2-mid-v1": {
|
|
74
|
+
"input": 0.0188, # $18.80 per 1M tokens (per 1K)
|
|
75
|
+
"output": 0.0188,
|
|
76
|
+
},
|
|
77
|
+
# Meta Llama models
|
|
78
|
+
"meta.llama2-13b-chat-v1": {
|
|
79
|
+
"input": 0.00075, # $0.75 per 1M tokens
|
|
80
|
+
"output": 0.001, # $1 per 1M tokens
|
|
81
|
+
},
|
|
82
|
+
"meta.llama2-70b-chat-v1": {
|
|
83
|
+
"input": 0.00195, # $1.95 per 1M tokens
|
|
84
|
+
"output": 0.00256, # $2.56 per 1M tokens
|
|
85
|
+
},
|
|
86
|
+
"meta.llama3-8b-instruct-v1:0": {
|
|
87
|
+
"input": 0.0003, # $0.30 per 1M tokens
|
|
88
|
+
"output": 0.0006, # $0.60 per 1M tokens
|
|
89
|
+
},
|
|
90
|
+
"meta.llama3-70b-instruct-v1:0": {
|
|
91
|
+
"input": 0.00265, # $2.65 per 1M tokens
|
|
92
|
+
"output": 0.0035, # $3.50 per 1M tokens
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def calculate_cost(
|
|
98
|
+
input_tokens: int,
|
|
99
|
+
output_tokens: int,
|
|
100
|
+
model_id: Optional[str] = None
|
|
101
|
+
) -> Dict[str, float]:
|
|
102
|
+
"""
|
|
103
|
+
Calculate cost based on token counts and model.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
input_tokens: Number of input tokens
|
|
107
|
+
output_tokens: Number of output tokens
|
|
108
|
+
model_id: AWS Bedrock model ID
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
Dict with input, output, and total cost
|
|
112
|
+
"""
|
|
113
|
+
if not model_id or model_id not in BEDROCK_PRICING:
|
|
114
|
+
# Unknown model - return zeros
|
|
115
|
+
return {
|
|
116
|
+
"input": 0.0,
|
|
117
|
+
"output": 0.0,
|
|
118
|
+
"total": 0.0,
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
pricing = BEDROCK_PRICING[model_id]
|
|
122
|
+
|
|
123
|
+
# Prices are per 1K tokens, so divide by 1000
|
|
124
|
+
input_cost = (input_tokens / 1000) * pricing["input"]
|
|
125
|
+
output_cost = (output_tokens / 1000) * pricing["output"]
|
|
126
|
+
total_cost = input_cost + output_cost
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
"input": round(input_cost, 6),
|
|
130
|
+
"output": round(output_cost, 6),
|
|
131
|
+
"total": round(total_cost, 6),
|
|
132
|
+
}
|