REPL в ручном тесте
This commit is contained in:
parent
f9289b92fa
commit
d832f27909
1 changed files with 14 additions and 6 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import asyncio
|
||||
import traceback
|
||||
|
||||
from lambda_agent_api.agent_api import AgentApi
|
||||
from lambda_agent_api.server import MsgEventTextChunk
|
||||
|
|
@ -12,13 +13,20 @@ 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)
|
||||
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()
|
||||
|
||||
finally:
|
||||
await api.close()
|
||||
await api.close()
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue