32 lines
No EOL
824 B
Python
32 lines
No EOL
824 B
Python
import asyncio
|
|
import traceback
|
|
|
|
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()
|
|
while True:
|
|
try:
|
|
prompt = await asyncio.get_event_loop().run_in_executor(None, input, ">>> ")
|
|
print("Agent: ", end="")
|
|
async for chunk in api.send_message(prompt):
|
|
if isinstance(chunk, MsgEventTextChunk):
|
|
print(chunk.text, end="", flush=True)
|
|
print("\n")
|
|
except KeyboardInterrupt:
|
|
break
|
|
except:
|
|
traceback.print_exc()
|
|
|
|
await api.close()
|
|
|
|
|
|
asyncio.run(main()) |