diff --git a/pyproject.toml b/pyproject.toml index 0e1d7a5..f04ccb2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "superagent-py" -version = "v0.0.45" +version = "v0.0.46" description = "" readme = "README.md" authors = [] @@ -10,8 +10,8 @@ packages = [ [tool.poetry.dependencies] python = "^3.7" -pydantic = "^1.9.2" httpx = "0.23.3" +pydantic = "^1.9.2" [tool.poetry.dev-dependencies] mypy = "0.971" diff --git a/src/superagent/resources/agent/client.py b/src/superagent/resources/agent/client.py index 0d2593a..2dffcf0 100644 --- a/src/superagent/resources/agent/client.py +++ b/src/superagent/resources/agent/client.py @@ -44,11 +44,17 @@ def create_agent( *, name: str, type: str, + description: typing.Optional[str] = OMIT, + avatar_url: typing.Optional[str] = OMIT, llm: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, has_memory: typing.Optional[bool] = OMIT, prompt_id: typing.Optional[str] = OMIT, ) -> typing.Any: _request: typing.Dict[str, typing.Any] = {"name": name, "type": type} + if description is not OMIT: + _request["description"] = description + if avatar_url is not OMIT: + _request["avatarUrl"] = avatar_url if llm is not OMIT: _request["llm"] = llm if has_memory is not OMIT: @@ -74,6 +80,23 @@ def create_agent( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + def list_library_agents(self) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agents/library"), + headers=remove_none_from_headers( + {"Authorization": f"Bearer {self._token}" if self._token is not None else None} + ), + timeout=60, + ) + if 200 <= _response.status_code < 300: + return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore + try: + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + def get_agent(self, agent_id: str) -> typing.Any: _response = httpx.request( "GET", @@ -193,11 +216,17 @@ async def create_agent( *, name: str, type: str, + description: typing.Optional[str] = OMIT, + avatar_url: typing.Optional[str] = OMIT, llm: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, has_memory: typing.Optional[bool] = OMIT, prompt_id: typing.Optional[str] = OMIT, ) -> typing.Any: _request: typing.Dict[str, typing.Any] = {"name": name, "type": type} + if description is not OMIT: + _request["description"] = description + if avatar_url is not OMIT: + _request["avatarUrl"] = avatar_url if llm is not OMIT: _request["llm"] = llm if has_memory is not OMIT: @@ -224,6 +253,24 @@ async def create_agent( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) + async def list_library_agents(self) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agents/library"), + headers=remove_none_from_headers( + {"Authorization": f"Bearer {self._token}" if self._token is not None else None} + ), + timeout=60, + ) + if 200 <= _response.status_code < 300: + return pydantic.parse_obj_as(typing.Any, _response.json()) # type: ignore + try: + _response_json = _response.json() + except JSONDecodeError: + raise ApiError(status_code=_response.status_code, body=_response.text) + raise ApiError(status_code=_response.status_code, body=_response_json) + async def get_agent(self, agent_id: str) -> typing.Any: async with httpx.AsyncClient() as _client: _response = await _client.request(