Fix agent API wrapper constructor compatibility
This commit is contained in:
parent
730ea70f78
commit
4533118b68
2 changed files with 112 additions and 5 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import inspect
|
||||
import logging
|
||||
import sys
|
||||
import re
|
||||
|
|
@ -43,13 +44,30 @@ class AgentApiWrapper(AgentApi):
|
|||
self._base_url = self._normalize_base_url(base_url or url or "")
|
||||
self._init_kwargs = dict(kwargs)
|
||||
self.chat_id = chat_id
|
||||
super().__init__(
|
||||
agent_id=agent_id,
|
||||
url=self._build_ws_url(self._base_url, chat_id),
|
||||
**kwargs,
|
||||
)
|
||||
if self._supports_modern_constructor():
|
||||
super().__init__(
|
||||
agent_id=agent_id,
|
||||
base_url=self._base_url,
|
||||
chat_id=chat_id,
|
||||
**kwargs,
|
||||
)
|
||||
else:
|
||||
super().__init__(
|
||||
agent_id=agent_id,
|
||||
url=self._build_ws_url(self._base_url, chat_id),
|
||||
**kwargs,
|
||||
)
|
||||
self.last_tokens_used = 0
|
||||
|
||||
@staticmethod
|
||||
def _supports_modern_constructor() -> bool:
|
||||
try:
|
||||
parameters = inspect.signature(AgentApi.__init__).parameters
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
|
||||
return "base_url" in parameters and "chat_id" in parameters
|
||||
|
||||
@staticmethod
|
||||
def _normalize_base_url(base_url: str) -> str:
|
||||
parsed = urlsplit(base_url)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue