AgentAPI принимает base_url (по идее ws://host:port) и сам дописывает нужный эндпоинт
This commit is contained in:
parent
8256453bbf
commit
4c3e7253c7
3 changed files with 5 additions and 5 deletions
|
|
@ -1,11 +1,11 @@
|
|||
from lambda_agent_api import AgentApi
|
||||
|
||||
# Lambda Agent API
|
||||
|
||||
WebSocket API SDK для взаимодействия с AI-агентом.
|
||||
|
||||
## Release Notes
|
||||
# v1.1
|
||||
- **CRITICAL**: `AgentAPI` вместо `url` принимает `base_url` и сам дописывает нужный эндпоинт.
|
||||
Раньше: `AgentAPI(url="ws://localhost:8000/agent_ws/")`. Сейчас: `AgentAPI(base_url="ws://localhost:8000/")`
|
||||
- Добавлен параметр `chat_id` в конструктор `AgentAPI`. Нужен для разделения истории сообщений по чатам/веткам.
|
||||
- `AgentAPI.connect()` вызывает `AgentBusyException`, если выбранный чат уже занят другим API клиентом.
|
||||
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@ class AgentApi:
|
|||
def __init__(
|
||||
self,
|
||||
agent_id: str,
|
||||
url: str,
|
||||
base_url: str,
|
||||
callback: Optional[Callable[[ServerMessage], None]] = None,
|
||||
on_disconnect: Optional[Callable[['AgentApi'], None]] = None,
|
||||
chat_id: int = 0 # значение по умолчанию для обратной совместимости
|
||||
):
|
||||
self.id = agent_id # ID агента для словаря
|
||||
self.chat_id = chat_id
|
||||
self.url = urljoin(url, f"{chat_id}/")
|
||||
self.url = urljoin(base_url, f"/v1/agent_ws/{chat_id}/")
|
||||
self.callback = callback
|
||||
self.on_disconnect = on_disconnect
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from lambda_agent_api.server import MsgEventTextChunk, MsgEventToolCallChunk, Ms
|
|||
|
||||
async def main():
|
||||
chat_id = input("Chat id: ") or 0
|
||||
api = AgentApi("agent-1", "ws://localhost:8000/agent_ws/", chat_id=chat_id)
|
||||
api = AgentApi("agent-1", "ws://localhost:8000/", chat_id=chat_id)
|
||||
|
||||
try:
|
||||
await api.connect()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue