поддержка chat_id
This commit is contained in:
parent
bb20a84741
commit
649834beae
2 changed files with 7 additions and 3 deletions
|
|
@ -2,6 +2,7 @@ import logging
|
||||||
from typing import Callable, Optional, AsyncIterator
|
from typing import Callable, Optional, AsyncIterator
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from urllib.parse import urljoin
|
||||||
|
|
||||||
from lambda_agent_api.server import *
|
from lambda_agent_api.server import *
|
||||||
from lambda_agent_api.client import *
|
from lambda_agent_api.client import *
|
||||||
|
|
@ -27,10 +28,12 @@ class AgentApi:
|
||||||
agent_id: str,
|
agent_id: str,
|
||||||
url: str,
|
url: str,
|
||||||
callback: Optional[Callable[[ServerMessage], None]] = None,
|
callback: Optional[Callable[[ServerMessage], None]] = None,
|
||||||
on_disconnect: Optional[Callable[['AgentApi'], None]] = None
|
on_disconnect: Optional[Callable[['AgentApi'], None]] = None,
|
||||||
|
chat_id: int = 0 # значение по умолчанию для обратной совместимости
|
||||||
):
|
):
|
||||||
self.id = agent_id # ID агента для словаря
|
self.id = agent_id # ID агента для словаря
|
||||||
self.url = url
|
self.chat_id = chat_id
|
||||||
|
self.url = urljoin(url, f"{chat_id}/")
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.on_disconnect = on_disconnect
|
self.on_disconnect = on_disconnect
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ from lambda_agent_api.server import MsgEventTextChunk, MsgEventToolCallChunk, Ms
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
api = AgentApi("agent-1", "ws://localhost:8000/agent_ws/")
|
chat_id = input("Chat id: ") or 0
|
||||||
|
api = AgentApi("agent-1", "ws://localhost:8000/agent_ws/", chat_id=chat_id)
|
||||||
|
|
||||||
await api.connect()
|
await api.connect()
|
||||||
while True:
|
while True:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue