24 lines
No EOL
561 B
Python
24 lines
No EOL
561 B
Python
import asyncio
|
|
|
|
from lambda_agent_api.agent_api import AgentApi
|
|
from lambda_agent_api.server import MsgEventTextChunk
|
|
|
|
|
|
def my_callback(message):
|
|
print(f"Callback: {message}")
|
|
|
|
|
|
async def main():
|
|
api = AgentApi("agent-1", "ws://localhost:8000/agent_ws/", callback=my_callback)
|
|
|
|
await api.connect()
|
|
try:
|
|
async for chunk in api.send_message("Привет, агент!"):
|
|
if isinstance(chunk, MsgEventTextChunk):
|
|
print(chunk.text, end="", flush=True)
|
|
|
|
finally:
|
|
await api.close()
|
|
|
|
|
|
asyncio.run(main()) |