-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemantic-cache.py
More file actions
32 lines (25 loc) · 1.02 KB
/
semantic-cache.py
File metadata and controls
32 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Cost Katana Python SDK: Cortex Semantic Caching
Cache optimized Cortex structures for maximum savings.
"""
import cost_katana as ck
def main():
print("\n🥷 Cost Katana Python SDK - Cortex Semantic Cache\n")
prompt = "Write a guide on Kubernetes deployment strategies"
# First request with Cortex - will cache
print("Request 1 (fresh, with Cortex):")
r1 = ck.ai('gpt-4', prompt, cortex=True, cache=True)
print(f" Cached: {r1.cached}")
print(f" Cost: ${r1.cost:.6f}")
print(f" Cortex Optimized: {r1.optimized}\n")
# Second request - hits Cortex cache
print("Request 2 (cached, with Cortex):")
r2 = ck.ai('gpt-4', prompt, cortex=True, cache=True)
print(f" Cached: {r2.cached}")
print(f" Cost: ${r2.cost:.6f} (FREE!)")
print(f" Total Savings: 100%\n")
print("💰 Cortex + Caching = Ultimate Savings!")
print(" First request: 40-75% savings with Cortex")
print(" Repeat requests: 100% free from cache\n")
if __name__ == '__main__':
main()