-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_usage.py
More file actions
34 lines (27 loc) · 834 Bytes
/
basic_usage.py
File metadata and controls
34 lines (27 loc) · 834 Bytes
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
33
34
"""
Basic usage example for LessTokens SDK
"""
import asyncio
import os
from lesstokens_sdk import LessTokensSDK
async def main():
# Initialize SDK
sdk = LessTokensSDK(
api_key=os.getenv("LESSTOKENS_API_KEY", "your-less-tokens-api-key"), provider="openai"
)
# Process prompt
response = await sdk.process_prompt(
{
"prompt": "Explain what artificial intelligence is",
"llm_config": {
"api_key": os.getenv("OPENAI_API_KEY", "your-openai-api-key"),
"model": "gpt-4",
"temperature": 0.7,
},
}
)
print("Response:", response.content)
print(f"Tokens saved: {response.usage.savings}%")
print(f"Total tokens: {response.usage.total_tokens}")
if __name__ == "__main__":
asyncio.run(main())