|
9 | 9 |
|
10 | 10 | async def main(): |
11 | 11 | sdk = LessTokensSDK( |
12 | | - api_key=os.getenv("LESSTOKENS_API_KEY", "your-less-tokens-api-key"), |
13 | | - provider="openai" |
| 12 | + api_key=os.getenv("LESSTOKENS_API_KEY", "your-less-tokens-api-key"), provider="openai" |
14 | 13 | ) |
15 | 14 |
|
16 | 15 | # First message |
17 | | - response1 = await sdk.process_prompt({ |
18 | | - "prompt": "What is the capital of France?", |
19 | | - "llm_config": { |
20 | | - "api_key": os.getenv("OPENAI_API_KEY", "your-openai-api-key"), |
21 | | - "model": "gpt-4", |
| 16 | + response1 = await sdk.process_prompt( |
| 17 | + { |
| 18 | + "prompt": "What is the capital of France?", |
| 19 | + "llm_config": { |
| 20 | + "api_key": os.getenv("OPENAI_API_KEY", "your-openai-api-key"), |
| 21 | + "model": "gpt-4", |
| 22 | + }, |
22 | 23 | } |
23 | | - }) |
| 24 | + ) |
24 | 25 |
|
25 | 26 | print("User: What is the capital of France?") |
26 | 27 | print(f"Assistant: {response1.content}\n") |
27 | 28 |
|
28 | 29 | # Second message with conversation history |
29 | | - response2 = await sdk.process_prompt({ |
30 | | - "prompt": "What is its population?", |
31 | | - "llm_config": { |
32 | | - "api_key": os.getenv("OPENAI_API_KEY", "your-openai-api-key"), |
33 | | - "model": "gpt-4", |
34 | | - }, |
35 | | - "messages": [ |
36 | | - {"role": "user", "content": "What is the capital of France?"}, |
37 | | - {"role": "assistant", "content": response1.content}, |
38 | | - ] |
39 | | - }) |
| 30 | + response2 = await sdk.process_prompt( |
| 31 | + { |
| 32 | + "prompt": "What is its population?", |
| 33 | + "llm_config": { |
| 34 | + "api_key": os.getenv("OPENAI_API_KEY", "your-openai-api-key"), |
| 35 | + "model": "gpt-4", |
| 36 | + }, |
| 37 | + "messages": [ |
| 38 | + {"role": "user", "content": "What is the capital of France?"}, |
| 39 | + {"role": "assistant", "content": response1.content}, |
| 40 | + ], |
| 41 | + } |
| 42 | + ) |
40 | 43 |
|
41 | 44 | print("User: What is its population?") |
42 | 45 | print(f"Assistant: {response2.content}") |
43 | 46 |
|
44 | 47 |
|
45 | 48 | if __name__ == "__main__": |
46 | 49 | asyncio.run(main()) |
47 | | - |
48 | | - |
|
0 commit comments