-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_turn.py
More file actions
49 lines (40 loc) · 1.29 KB
/
multi_turn.py
File metadata and controls
49 lines (40 loc) · 1.29 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Multi-turn conversation example for LessTokens SDK
"""
import asyncio
import os
from lesstokens_sdk import LessTokensSDK
async def main():
sdk = LessTokensSDK(
api_key=os.getenv("LESSTOKENS_API_KEY", "your-less-tokens-api-key"), provider="openai"
)
# First message
response1 = await sdk.process_prompt(
{
"prompt": "What is the capital of France?",
"llm_config": {
"api_key": os.getenv("OPENAI_API_KEY", "your-openai-api-key"),
"model": "gpt-4",
},
}
)
print("User: What is the capital of France?")
print(f"Assistant: {response1.content}\n")
# Second message with conversation history
response2 = await sdk.process_prompt(
{
"prompt": "What is its population?",
"llm_config": {
"api_key": os.getenv("OPENAI_API_KEY", "your-openai-api-key"),
"model": "gpt-4",
},
"messages": [
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": response1.content},
],
}
)
print("User: What is its population?")
print(f"Assistant: {response2.content}")
if __name__ == "__main__":
asyncio.run(main())