-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathllm_chat.py
More file actions
37 lines (29 loc) · 985 Bytes
/
llm_chat.py
File metadata and controls
37 lines (29 loc) · 985 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
35
36
37
import asyncio
import logging
import os
import opengradient as og
logging.basicConfig()
logging.getLogger("opengradient").setLevel(logging.DEBUG)
async def main():
llm = og.LLM(private_key=os.environ.get("OG_PRIVATE_KEY"))
llm.ensure_opg_approval(min_allowance=0.1)
messages = [
{"role": "user", "content": "What model are you?"},
]
# Run inference with full public settlement
result = await llm.chat(
model=og.TEE_LLM.GPT_5_5,
messages=messages,
max_tokens=300,
x402_settlement_mode=og.x402SettlementMode.INDIVIDUAL_FULL,
)
print(result.chat_output["content"])
# Print inference settlement details
print("\n" + "=" * 40)
tx_hash = result.data_settlement_transaction_hash
if tx_hash:
print(f"Settlement tx: {tx_hash}")
print(f"Explorer: https://explorer.opengradient.ai/tx/{tx_hash}?tab=index")
else:
print("No settlement tx hash returned")
asyncio.run(main())