From f7e3d238330e51c315a78e36ca6a33728ad576b4 Mon Sep 17 00:00:00 2001 From: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Date: Wed, 28 Jun 2023 08:07:34 +0000 Subject: [PATCH] Release v.0.0.24 --- .github/workflows/ci.yml | 44 +++ .gitignore | 4 + pyproject.toml | 21 ++ src/superagent/__init__.py | 22 ++ src/superagent/client.py | 46 +++ src/superagent/core/__init__.py | 8 + src/superagent/core/api_error.py | 15 + src/superagent/core/datetime_utils.py | 28 ++ src/superagent/core/jsonable_encoder.py | 101 ++++++ .../core/remove_none_from_headers.py | 11 + src/superagent/errors/__init__.py | 5 + .../errors/unprocessable_entity_error.py | 9 + src/superagent/py.typed | 0 src/superagent/resources/__init__.py | 16 + src/superagent/resources/agent/__init__.py | 2 + src/superagent/resources/agent/client.py | 305 ++++++++++++++++++ .../resources/agent_documents/__init__.py | 2 + .../resources/agent_documents/client.py | 186 +++++++++++ .../resources/agent_tools/__init__.py | 2 + .../resources/agent_tools/client.py | 186 +++++++++++ .../resources/api_token/__init__.py | 2 + src/superagent/resources/api_token/client.py | 180 +++++++++++ src/superagent/resources/auth/__init__.py | 2 + src/superagent/resources/auth/client.py | 135 ++++++++ .../resources/documents/__init__.py | 2 + src/superagent/resources/documents/client.py | 221 +++++++++++++ src/superagent/resources/prompts/__init__.py | 2 + src/superagent/resources/prompts/client.py | 223 +++++++++++++ src/superagent/resources/tools/__init__.py | 2 + src/superagent/resources/tools/client.py | 207 ++++++++++++ src/superagent/resources/traces/__init__.py | 2 + src/superagent/resources/traces/client.py | 58 ++++ src/superagent/resources/user/__init__.py | 2 + src/superagent/resources/user/client.py | 99 ++++++ src/superagent/types/__init__.py | 7 + src/superagent/types/http_validation_error.py | 25 ++ src/superagent/types/validation_error.py | 27 ++ .../types/validation_error_loc_item.py | 5 + 38 files changed, 2214 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 pyproject.toml create mode 100644 src/superagent/__init__.py create mode 100644 src/superagent/client.py create mode 100644 src/superagent/core/__init__.py create mode 100644 src/superagent/core/api_error.py create mode 100644 src/superagent/core/datetime_utils.py create mode 100644 src/superagent/core/jsonable_encoder.py create mode 100644 src/superagent/core/remove_none_from_headers.py create mode 100644 src/superagent/errors/__init__.py create mode 100644 src/superagent/errors/unprocessable_entity_error.py create mode 100644 src/superagent/py.typed create mode 100644 src/superagent/resources/__init__.py create mode 100644 src/superagent/resources/agent/__init__.py create mode 100644 src/superagent/resources/agent/client.py create mode 100644 src/superagent/resources/agent_documents/__init__.py create mode 100644 src/superagent/resources/agent_documents/client.py create mode 100644 src/superagent/resources/agent_tools/__init__.py create mode 100644 src/superagent/resources/agent_tools/client.py create mode 100644 src/superagent/resources/api_token/__init__.py create mode 100644 src/superagent/resources/api_token/client.py create mode 100644 src/superagent/resources/auth/__init__.py create mode 100644 src/superagent/resources/auth/client.py create mode 100644 src/superagent/resources/documents/__init__.py create mode 100644 src/superagent/resources/documents/client.py create mode 100644 src/superagent/resources/prompts/__init__.py create mode 100644 src/superagent/resources/prompts/client.py create mode 100644 src/superagent/resources/tools/__init__.py create mode 100644 src/superagent/resources/tools/client.py create mode 100644 src/superagent/resources/traces/__init__.py create mode 100644 src/superagent/resources/traces/client.py create mode 100644 src/superagent/resources/user/__init__.py create mode 100644 src/superagent/resources/user/client.py create mode 100644 src/superagent/types/__init__.py create mode 100644 src/superagent/types/http_validation_error.py create mode 100644 src/superagent/types/validation_error.py create mode 100644 src/superagent/types/validation_error_loc_item.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5ed336e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,44 @@ +name: ci + +on: [push] +jobs: + compile: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Set up python + uses: actions/setup-python@v4 + with: + python-version: 3.7 + - name: Bootstrap poetry + run: | + curl -sSL https://install.python-poetry.org | python - -y + - name: Install dependencies + run: poetry install + - name: Compile + run: poetry run mypy . + + publish: + needs: [ compile ] + if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v3 + - name: Set up python + uses: actions/setup-python@v4 + with: + python-version: 3.7 + - name: Bootstrap poetry + run: | + curl -sSL https://install.python-poetry.org | python - -y + - name: Install dependencies + run: poetry install + - name: Publish to pypi + run: | + poetry config repositories.remote https://upload.pypi.org/legacy/ + poetry --no-interaction -v publish --build --repository remote --username "$PYPI_USERNAME" --password "$PYPI_PASSWORD" + env: + PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }} + PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42cb863 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +dist/ +.mypy_cache/ +__pycache__/ +poetry.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..6f4fc62 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[tool.poetry] +name = "superagent-py" +version = "v.0.0.24" +description = "" +readme = "README.md" +authors = [] +packages = [ + { include = "superagent", from = "src"} +] + +[tool.poetry.dependencies] +python = "^3.7" +pydantic = "^1.9.2" +httpx = "0.23.3" + +[tool.poetry.dev-dependencies] +mypy = "0.971" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" diff --git a/src/superagent/__init__.py b/src/superagent/__init__.py new file mode 100644 index 0000000..81f3f0b --- /dev/null +++ b/src/superagent/__init__.py @@ -0,0 +1,22 @@ +# This file was auto-generated by Fern from our API Definition. + +from .errors import UnprocessableEntityError +from .resources import agent, agent_documents, agent_tools, api_token, auth, documents, prompts, tools, traces, user +from .types import HttpValidationError, ValidationError, ValidationErrorLocItem + +__all__ = [ + "HttpValidationError", + "UnprocessableEntityError", + "ValidationError", + "ValidationErrorLocItem", + "agent", + "agent_documents", + "agent_tools", + "api_token", + "auth", + "documents", + "prompts", + "tools", + "traces", + "user", +] diff --git a/src/superagent/client.py b/src/superagent/client.py new file mode 100644 index 0000000..dee40d1 --- /dev/null +++ b/src/superagent/client.py @@ -0,0 +1,46 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +from .resources.agent.client import AgentClient, AsyncAgentClient +from .resources.agent_documents.client import AgentDocumentsClient, AsyncAgentDocumentsClient +from .resources.agent_tools.client import AgentToolsClient, AsyncAgentToolsClient +from .resources.api_token.client import ApiTokenClient, AsyncApiTokenClient +from .resources.auth.client import AsyncAuthClient, AuthClient +from .resources.documents.client import AsyncDocumentsClient, DocumentsClient +from .resources.prompts.client import AsyncPromptsClient, PromptsClient +from .resources.tools.client import AsyncToolsClient, ToolsClient +from .resources.traces.client import AsyncTracesClient, TracesClient +from .resources.user.client import AsyncUserClient, UserClient + + +class Superagent: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + self.agent = AgentClient(environment=self._environment, token=self._token) + self.agent_documents = AgentDocumentsClient(environment=self._environment, token=self._token) + self.agent_tools = AgentToolsClient(environment=self._environment, token=self._token) + self.auth = AuthClient(environment=self._environment, token=self._token) + self.user = UserClient(environment=self._environment, token=self._token) + self.api_token = ApiTokenClient(environment=self._environment, token=self._token) + self.documents = DocumentsClient(environment=self._environment, token=self._token) + self.prompts = PromptsClient(environment=self._environment, token=self._token) + self.tools = ToolsClient(environment=self._environment, token=self._token) + self.traces = TracesClient(environment=self._environment, token=self._token) + + +class AsyncSuperagent: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + self.agent = AsyncAgentClient(environment=self._environment, token=self._token) + self.agent_documents = AsyncAgentDocumentsClient(environment=self._environment, token=self._token) + self.agent_tools = AsyncAgentToolsClient(environment=self._environment, token=self._token) + self.auth = AsyncAuthClient(environment=self._environment, token=self._token) + self.user = AsyncUserClient(environment=self._environment, token=self._token) + self.api_token = AsyncApiTokenClient(environment=self._environment, token=self._token) + self.documents = AsyncDocumentsClient(environment=self._environment, token=self._token) + self.prompts = AsyncPromptsClient(environment=self._environment, token=self._token) + self.tools = AsyncToolsClient(environment=self._environment, token=self._token) + self.traces = AsyncTracesClient(environment=self._environment, token=self._token) diff --git a/src/superagent/core/__init__.py b/src/superagent/core/__init__.py new file mode 100644 index 0000000..b213a1a --- /dev/null +++ b/src/superagent/core/__init__.py @@ -0,0 +1,8 @@ +# This file was auto-generated by Fern from our API Definition. + +from .api_error import ApiError +from .datetime_utils import serialize_datetime +from .jsonable_encoder import jsonable_encoder +from .remove_none_from_headers import remove_none_from_headers + +__all__ = ["ApiError", "jsonable_encoder", "remove_none_from_headers", "serialize_datetime"] diff --git a/src/superagent/core/api_error.py b/src/superagent/core/api_error.py new file mode 100644 index 0000000..2e9fc54 --- /dev/null +++ b/src/superagent/core/api_error.py @@ -0,0 +1,15 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + + +class ApiError(Exception): + status_code: typing.Optional[int] + body: typing.Any + + def __init__(self, *, status_code: typing.Optional[int] = None, body: typing.Any = None): + self.status_code = status_code + self.body = body + + def __str__(self) -> str: + return f"status_code: {self.status_code}, body: {self.body}" diff --git a/src/superagent/core/datetime_utils.py b/src/superagent/core/datetime_utils.py new file mode 100644 index 0000000..7c9864a --- /dev/null +++ b/src/superagent/core/datetime_utils.py @@ -0,0 +1,28 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt + + +def serialize_datetime(v: dt.datetime) -> str: + """ + Serialize a datetime including timezone info. + + Uses the timezone info provided if present, otherwise uses the current runtime's timezone info. + + UTC datetimes end in "Z" while all other timezones are represented as offset from UTC, e.g. +05:00. + """ + + def _serialize_zoned_datetime(v: dt.datetime) -> str: + if v.tzinfo is not None and v.tzinfo.tzname(None) == dt.timezone.utc.tzname(None): + # UTC is a special case where we use "Z" at the end instead of "+00:00" + return v.isoformat().replace("+00:00", "Z") + else: + # Delegate to the typical +/- offset format + return v.isoformat() + + if v.tzinfo is not None: + return _serialize_zoned_datetime(v) + else: + local_tz = dt.datetime.now().astimezone().tzinfo + localized_dt = v.replace(tzinfo=local_tz) + return _serialize_zoned_datetime(localized_dt) diff --git a/src/superagent/core/jsonable_encoder.py b/src/superagent/core/jsonable_encoder.py new file mode 100644 index 0000000..5c3cfac --- /dev/null +++ b/src/superagent/core/jsonable_encoder.py @@ -0,0 +1,101 @@ +# This file was auto-generated by Fern from our API Definition. + +""" +jsonable_encoder converts a Python object to a JSON-friendly dict +(e.g. datetimes to strings, Pydantic models to dicts). + +Taken from FastAPI, and made a bit simpler +https://github.com/tiangolo/fastapi/blob/master/fastapi/encoders.py +""" + +import dataclasses +import datetime as dt +from collections import defaultdict +from enum import Enum +from pathlib import PurePath +from types import GeneratorType +from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union + +from pydantic import BaseModel +from pydantic.json import ENCODERS_BY_TYPE + +from .datetime_utils import serialize_datetime + +SetIntStr = Set[Union[int, str]] +DictIntStrAny = Dict[Union[int, str], Any] + + +def generate_encoders_by_class_tuples( + type_encoder_map: Dict[Any, Callable[[Any], Any]] +) -> Dict[Callable[[Any], Any], Tuple[Any, ...]]: + encoders_by_class_tuples: Dict[Callable[[Any], Any], Tuple[Any, ...]] = defaultdict(tuple) + for type_, encoder in type_encoder_map.items(): + encoders_by_class_tuples[encoder] += (type_,) + return encoders_by_class_tuples + + +encoders_by_class_tuples = generate_encoders_by_class_tuples(ENCODERS_BY_TYPE) + + +def jsonable_encoder(obj: Any, custom_encoder: Optional[Dict[Any, Callable[[Any], Any]]] = None) -> Any: + custom_encoder = custom_encoder or {} + if custom_encoder: + if type(obj) in custom_encoder: + return custom_encoder[type(obj)](obj) + else: + for encoder_type, encoder_instance in custom_encoder.items(): + if isinstance(obj, encoder_type): + return encoder_instance(obj) + if isinstance(obj, BaseModel): + encoder = getattr(obj.__config__, "json_encoders", {}) + if custom_encoder: + encoder.update(custom_encoder) + obj_dict = obj.dict(by_alias=True) + if "__root__" in obj_dict: + obj_dict = obj_dict["__root__"] + return jsonable_encoder(obj_dict, custom_encoder=encoder) + if dataclasses.is_dataclass(obj): + obj_dict = dataclasses.asdict(obj) + return jsonable_encoder(obj_dict, custom_encoder=custom_encoder) + if isinstance(obj, Enum): + return obj.value + if isinstance(obj, PurePath): + return str(obj) + if isinstance(obj, (str, int, float, type(None))): + return obj + if isinstance(obj, dt.date): + return str(obj) + if isinstance(obj, dt.datetime): + return serialize_datetime(obj) + if isinstance(obj, dict): + encoded_dict = {} + allowed_keys = set(obj.keys()) + for key, value in obj.items(): + if key in allowed_keys: + encoded_key = jsonable_encoder(key, custom_encoder=custom_encoder) + encoded_value = jsonable_encoder(value, custom_encoder=custom_encoder) + encoded_dict[encoded_key] = encoded_value + return encoded_dict + if isinstance(obj, (list, set, frozenset, GeneratorType, tuple)): + encoded_list = [] + for item in obj: + encoded_list.append(jsonable_encoder(item, custom_encoder=custom_encoder)) + return encoded_list + + if type(obj) in ENCODERS_BY_TYPE: + return ENCODERS_BY_TYPE[type(obj)](obj) + for encoder, classes_tuple in encoders_by_class_tuples.items(): + if isinstance(obj, classes_tuple): + return encoder(obj) + + try: + data = dict(obj) + except Exception as e: + errors: List[Exception] = [] + errors.append(e) + try: + data = vars(obj) + except Exception as e: + errors.append(e) + raise ValueError(errors) from e + return jsonable_encoder(data, custom_encoder=custom_encoder) diff --git a/src/superagent/core/remove_none_from_headers.py b/src/superagent/core/remove_none_from_headers.py new file mode 100644 index 0000000..21a44ca --- /dev/null +++ b/src/superagent/core/remove_none_from_headers.py @@ -0,0 +1,11 @@ +# This file was auto-generated by Fern from our API Definition. + +from typing import Dict, Optional + + +def remove_none_from_headers(headers: Dict[str, Optional[str]]) -> Dict[str, str]: + new_headers: Dict[str, str] = {} + for header_key, header_value in headers.items(): + if header_value is not None: + new_headers[header_key] = header_value + return new_headers diff --git a/src/superagent/errors/__init__.py b/src/superagent/errors/__init__.py new file mode 100644 index 0000000..cb64e06 --- /dev/null +++ b/src/superagent/errors/__init__.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +from .unprocessable_entity_error import UnprocessableEntityError + +__all__ = ["UnprocessableEntityError"] diff --git a/src/superagent/errors/unprocessable_entity_error.py b/src/superagent/errors/unprocessable_entity_error.py new file mode 100644 index 0000000..47470a7 --- /dev/null +++ b/src/superagent/errors/unprocessable_entity_error.py @@ -0,0 +1,9 @@ +# This file was auto-generated by Fern from our API Definition. + +from ..core.api_error import ApiError +from ..types.http_validation_error import HttpValidationError + + +class UnprocessableEntityError(ApiError): + def __init__(self, body: HttpValidationError): + super().__init__(status_code=422, body=body) diff --git a/src/superagent/py.typed b/src/superagent/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/src/superagent/resources/__init__.py b/src/superagent/resources/__init__.py new file mode 100644 index 0000000..449cf9c --- /dev/null +++ b/src/superagent/resources/__init__.py @@ -0,0 +1,16 @@ +# This file was auto-generated by Fern from our API Definition. + +from . import agent, agent_documents, agent_tools, api_token, auth, documents, prompts, tools, traces, user + +__all__ = [ + "agent", + "agent_documents", + "agent_tools", + "api_token", + "auth", + "documents", + "prompts", + "tools", + "traces", + "user", +] diff --git a/src/superagent/resources/agent/__init__.py b/src/superagent/resources/agent/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/agent/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/agent/client.py b/src/superagent/resources/agent/client.py new file mode 100644 index 0000000..7163206 --- /dev/null +++ b/src/superagent/resources/agent/client.py @@ -0,0 +1,305 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.jsonable_encoder import jsonable_encoder +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + +# this is used as the default value for optional parameters +OMIT = typing.cast(typing.Any, ...) + + +class AgentClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def list_all_agents(self) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agents"), + 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 create_agent( + self, + *, + name: str, + type: str, + 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 llm is not OMIT: + _request["llm"] = llm + if has_memory is not OMIT: + _request["hasMemory"] = has_memory + if prompt_id is not OMIT: + _request["promptId"] = prompt_id + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agents"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agents/{agent_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 patch_agent(self, agent_id: str, *, request: typing.Dict[str, typing.Any]) -> typing.Any: + _response = httpx.request( + "PATCH", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agents/{agent_id}"), + json=jsonable_encoder(request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_agent(self, agent_id: str) -> typing.Any: + _response = httpx.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agents/{agent_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 prompt_agent( + self, agent_id: str, *, input: typing.Dict[str, typing.Any], has_streaming: typing.Optional[bool] = OMIT + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"input": input} + if has_streaming is not OMIT: + _request["has_streaming"] = has_streaming + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agents/{agent_id}/predict"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncAgentClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def list_all_agents(self) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agents"), + 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 create_agent( + self, + *, + name: str, + type: str, + 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 llm is not OMIT: + _request["llm"] = llm + if has_memory is not OMIT: + _request["hasMemory"] = has_memory + if prompt_id is not OMIT: + _request["promptId"] = prompt_id + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agents"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agents/{agent_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 patch_agent(self, agent_id: str, *, request: typing.Dict[str, typing.Any]) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "PATCH", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agents/{agent_id}"), + json=jsonable_encoder(request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_agent(self, agent_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agents/{agent_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 prompt_agent( + self, agent_id: str, *, input: typing.Dict[str, typing.Any], has_streaming: typing.Optional[bool] = OMIT + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"input": input} + if has_streaming is not OMIT: + _request["has_streaming"] = has_streaming + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agents/{agent_id}/predict"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/resources/agent_documents/__init__.py b/src/superagent/resources/agent_documents/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/agent_documents/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/agent_documents/client.py b/src/superagent/resources/agent_documents/client.py new file mode 100644 index 0000000..f3f714c --- /dev/null +++ b/src/superagent/resources/agent_documents/client.py @@ -0,0 +1,186 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.jsonable_encoder import jsonable_encoder +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + + +class AgentDocumentsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def list_agent_documents(self, *, expand: typing.Optional[bool] = None) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agent-documents"), + params={"expand": expand}, + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 create_agent_document(self, *, agent_id: str, document_id: str) -> typing.Any: + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agent-documents"), + json=jsonable_encoder({"agentId": agent_id, "documentId": document_id}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_document(self, agent_document_id: str) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agent-documents/{agent_document_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_agent_document(self, agent_document_id: str) -> typing.Any: + _response = httpx.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agent-documents/{agent_document_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncAgentDocumentsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def list_agent_documents(self, *, expand: typing.Optional[bool] = None) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agent-documents"), + params={"expand": expand}, + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 create_agent_document(self, *, agent_id: str, document_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agent-documents"), + json=jsonable_encoder({"agentId": agent_id, "documentId": document_id}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_document(self, agent_document_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agent-documents/{agent_document_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_agent_document(self, agent_document_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agent-documents/{agent_document_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/resources/agent_tools/__init__.py b/src/superagent/resources/agent_tools/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/agent_tools/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/agent_tools/client.py b/src/superagent/resources/agent_tools/client.py new file mode 100644 index 0000000..49a8edb --- /dev/null +++ b/src/superagent/resources/agent_tools/client.py @@ -0,0 +1,186 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.jsonable_encoder import jsonable_encoder +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + + +class AgentToolsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def list_agent_tools(self, *, expand: typing.Optional[bool] = None) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agent-tools"), + params={"expand": expand}, + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 create_agent_tool(self, *, agent_id: str, tool_id: str) -> typing.Any: + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agent-tools"), + json=jsonable_encoder({"agentId": agent_id, "toolId": tool_id}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_tool(self, agent_tool_id: str) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agent-tools/{agent_tool_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_agent_tool(self, agent_tool_id: str) -> typing.Any: + _response = httpx.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agent-tools/{agent_tool_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncAgentToolsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def list_agent_tools(self, *, expand: typing.Optional[bool] = None) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agent-tools"), + params={"expand": expand}, + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 create_agent_tool(self, *, agent_id: str, tool_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/agent-tools"), + json=jsonable_encoder({"agentId": agent_id, "toolId": tool_id}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_tool(self, agent_tool_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agent-tools/{agent_tool_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_agent_tool(self, agent_tool_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/agent-tools/{agent_tool_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/resources/api_token/__init__.py b/src/superagent/resources/api_token/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/api_token/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/api_token/client.py b/src/superagent/resources/api_token/client.py new file mode 100644 index 0000000..bc74dbb --- /dev/null +++ b/src/superagent/resources/api_token/client.py @@ -0,0 +1,180 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.jsonable_encoder import jsonable_encoder +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + + +class ApiTokenClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def list_api_tokens(self) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/api-tokens"), + 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 create_api_token(self, *, description: str) -> typing.Any: + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/api-tokens"), + json=jsonable_encoder({"description": description}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_api_token(self, token_id: str) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/api-tokens/{token_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_api_token(self, token_id: str) -> typing.Any: + _response = httpx.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/api-tokens/{token_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncApiTokenClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def list_api_tokens(self) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/api-tokens"), + 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 create_api_token(self, *, description: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/api-tokens"), + json=jsonable_encoder({"description": description}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_api_token(self, token_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/api-tokens/{token_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_api_token(self, token_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/api-tokens/{token_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/resources/auth/__init__.py b/src/superagent/resources/auth/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/auth/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/auth/client.py b/src/superagent/resources/auth/client.py new file mode 100644 index 0000000..0ea7040 --- /dev/null +++ b/src/superagent/resources/auth/client.py @@ -0,0 +1,135 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.jsonable_encoder import jsonable_encoder +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + +# this is used as the default value for optional parameters +OMIT = typing.cast(typing.Any, ...) + + +class AuthClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def sign_in(self, *, email: str, password: str) -> typing.Any: + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/auth/sign-in"), + json=jsonable_encoder({"email": email, "password": password}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 sign_up( + self, + *, + email: str, + password: str, + name: typing.Optional[str] = OMIT, + metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"email": email, "password": password} + if name is not OMIT: + _request["name"] = name + if metadata is not OMIT: + _request["metadata"] = metadata + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/auth/sign-up"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncAuthClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def sign_in(self, *, email: str, password: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/auth/sign-in"), + json=jsonable_encoder({"email": email, "password": password}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 sign_up( + self, + *, + email: str, + password: str, + name: typing.Optional[str] = OMIT, + metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"email": email, "password": password} + if name is not OMIT: + _request["name"] = name + if metadata is not OMIT: + _request["metadata"] = metadata + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/auth/sign-up"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/resources/documents/__init__.py b/src/superagent/resources/documents/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/documents/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/documents/client.py b/src/superagent/resources/documents/client.py new file mode 100644 index 0000000..bb87dc8 --- /dev/null +++ b/src/superagent/resources/documents/client.py @@ -0,0 +1,221 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.jsonable_encoder import jsonable_encoder +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + +# this is used as the default value for optional parameters +OMIT = typing.cast(typing.Any, ...) + + +class DocumentsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def list_documents(self) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/documents"), + 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 create_document( + self, + *, + type: str, + url: str, + name: str, + authorization: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + from_page: typing.Optional[int] = OMIT, + to_page: typing.Optional[int] = OMIT, + splitter: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"type": type, "url": url, "name": name} + if authorization is not OMIT: + _request["authorization"] = authorization + if from_page is not OMIT: + _request["from_page"] = from_page + if to_page is not OMIT: + _request["to_page"] = to_page + if splitter is not OMIT: + _request["splitter"] = splitter + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/documents"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_document(self, document_id: str) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/documents/{document_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_document(self, document_id: str) -> typing.Any: + _response = httpx.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/documents/{document_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncDocumentsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def list_documents(self) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/documents"), + 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 create_document( + self, + *, + type: str, + url: str, + name: str, + authorization: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + from_page: typing.Optional[int] = OMIT, + to_page: typing.Optional[int] = OMIT, + splitter: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"type": type, "url": url, "name": name} + if authorization is not OMIT: + _request["authorization"] = authorization + if from_page is not OMIT: + _request["from_page"] = from_page + if to_page is not OMIT: + _request["to_page"] = to_page + if splitter is not OMIT: + _request["splitter"] = splitter + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/documents"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_document(self, document_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/documents/{document_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_document(self, document_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/documents/{document_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/resources/prompts/__init__.py b/src/superagent/resources/prompts/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/prompts/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/prompts/client.py b/src/superagent/resources/prompts/client.py new file mode 100644 index 0000000..ded584c --- /dev/null +++ b/src/superagent/resources/prompts/client.py @@ -0,0 +1,223 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.jsonable_encoder import jsonable_encoder +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + + +class PromptsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def list_prompts(self) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/prompts"), + 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 create_a_prompt(self, *, name: str, input_variables: typing.List[typing.Any], template: str) -> typing.Any: + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/prompts"), + json=jsonable_encoder({"name": name, "input_variables": input_variables, "template": template}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_prompt(self, prompt_id: str) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/prompts/{prompt_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 patch_prompt(self, prompt_id: str, *, request: typing.Dict[str, typing.Any]) -> typing.Any: + _response = httpx.request( + "PATCH", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/prompts/{prompt_id}"), + json=jsonable_encoder(request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_prompt(self, prompt_id: str) -> typing.Any: + _response = httpx.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/prompts/{prompt_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncPromptsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def list_prompts(self) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/prompts"), + 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 create_a_prompt( + self, *, name: str, input_variables: typing.List[typing.Any], template: str + ) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/prompts"), + json=jsonable_encoder({"name": name, "input_variables": input_variables, "template": template}), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_prompt(self, prompt_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/prompts/{prompt_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 patch_prompt(self, prompt_id: str, *, request: typing.Dict[str, typing.Any]) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "PATCH", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/prompts/{prompt_id}"), + json=jsonable_encoder(request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_prompt(self, prompt_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/prompts/{prompt_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/resources/tools/__init__.py b/src/superagent/resources/tools/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/tools/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/tools/client.py b/src/superagent/resources/tools/client.py new file mode 100644 index 0000000..ec511df --- /dev/null +++ b/src/superagent/resources/tools/client.py @@ -0,0 +1,207 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.jsonable_encoder import jsonable_encoder +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + +# this is used as the default value for optional parameters +OMIT = typing.cast(typing.Any, ...) + + +class ToolsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def list_tools(self) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/tools"), + 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 create_a_tool( + self, + *, + name: str, + type: str, + authorization: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"name": name, "type": type} + if authorization is not OMIT: + _request["authorization"] = authorization + if metadata is not OMIT: + _request["metadata"] = metadata + _response = httpx.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/tools"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_tool(self, tool_id: str) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/tools/{tool_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_tool(self, tool_id: str) -> typing.Any: + _response = httpx.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/tools/{tool_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncToolsClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def list_tools(self) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/tools"), + 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 create_a_tool( + self, + *, + name: str, + type: str, + authorization: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT, + ) -> typing.Any: + _request: typing.Dict[str, typing.Any] = {"name": name, "type": type} + if authorization is not OMIT: + _request["authorization"] = authorization + if metadata is not OMIT: + _request["metadata"] = metadata + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "POST", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/tools"), + json=jsonable_encoder(_request), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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_tool(self, tool_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/tools/{tool_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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 delete_tool(self, tool_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "DELETE", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/tools/{tool_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/resources/traces/__init__.py b/src/superagent/resources/traces/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/traces/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/traces/client.py b/src/superagent/resources/traces/client.py new file mode 100644 index 0000000..960e97f --- /dev/null +++ b/src/superagent/resources/traces/client.py @@ -0,0 +1,58 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.remove_none_from_headers import remove_none_from_headers + + +class TracesClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def list_agent_traces(self) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/traces"), + 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) + + +class AsyncTracesClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def list_agent_traces(self) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/traces"), + 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) diff --git a/src/superagent/resources/user/__init__.py b/src/superagent/resources/user/__init__.py new file mode 100644 index 0000000..f3ea265 --- /dev/null +++ b/src/superagent/resources/user/__init__.py @@ -0,0 +1,2 @@ +# This file was auto-generated by Fern from our API Definition. + diff --git a/src/superagent/resources/user/client.py b/src/superagent/resources/user/client.py new file mode 100644 index 0000000..59ee2f7 --- /dev/null +++ b/src/superagent/resources/user/client.py @@ -0,0 +1,99 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing +import urllib.parse +from json.decoder import JSONDecodeError + +import httpx +import pydantic + +from ...core.api_error import ApiError +from ...core.remove_none_from_headers import remove_none_from_headers +from ...errors.unprocessable_entity_error import UnprocessableEntityError +from ...types.http_validation_error import HttpValidationError + + +class UserClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + def read_user_me(self) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/users/me"), + 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 read_user(self, user_id: str) -> typing.Any: + _response = httpx.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/users/{user_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) + + +class AsyncUserClient: + def __init__(self, *, environment: str, token: typing.Optional[str] = None): + self._environment = environment + self._token = token + + async def read_user_me(self) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", "api/v1/users/me"), + 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 read_user(self, user_id: str) -> typing.Any: + async with httpx.AsyncClient() as _client: + _response = await _client.request( + "GET", + urllib.parse.urljoin(f"{self._environment}/", f"api/v1/users/{user_id}"), + 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 + if _response.status_code == 422: + raise UnprocessableEntityError(pydantic.parse_obj_as(HttpValidationError, _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) diff --git a/src/superagent/types/__init__.py b/src/superagent/types/__init__.py new file mode 100644 index 0000000..47a491f --- /dev/null +++ b/src/superagent/types/__init__.py @@ -0,0 +1,7 @@ +# This file was auto-generated by Fern from our API Definition. + +from .http_validation_error import HttpValidationError +from .validation_error import ValidationError +from .validation_error_loc_item import ValidationErrorLocItem + +__all__ = ["HttpValidationError", "ValidationError", "ValidationErrorLocItem"] diff --git a/src/superagent/types/http_validation_error.py b/src/superagent/types/http_validation_error.py new file mode 100644 index 0000000..426b4a9 --- /dev/null +++ b/src/superagent/types/http_validation_error.py @@ -0,0 +1,25 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +import pydantic + +from ..core.datetime_utils import serialize_datetime +from .validation_error import ValidationError + + +class HttpValidationError(pydantic.BaseModel): + detail: typing.Optional[typing.List[ValidationError]] + + def json(self, **kwargs: typing.Any) -> str: + kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + return super().json(**kwargs_with_defaults) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + return super().dict(**kwargs_with_defaults) + + class Config: + frozen = True + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/superagent/types/validation_error.py b/src/superagent/types/validation_error.py new file mode 100644 index 0000000..3f78271 --- /dev/null +++ b/src/superagent/types/validation_error.py @@ -0,0 +1,27 @@ +# This file was auto-generated by Fern from our API Definition. + +import datetime as dt +import typing + +import pydantic + +from ..core.datetime_utils import serialize_datetime +from .validation_error_loc_item import ValidationErrorLocItem + + +class ValidationError(pydantic.BaseModel): + loc: typing.List[ValidationErrorLocItem] + msg: str + type: str + + def json(self, **kwargs: typing.Any) -> str: + kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + return super().json(**kwargs_with_defaults) + + def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]: + kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs} + return super().dict(**kwargs_with_defaults) + + class Config: + frozen = True + json_encoders = {dt.datetime: serialize_datetime} diff --git a/src/superagent/types/validation_error_loc_item.py b/src/superagent/types/validation_error_loc_item.py new file mode 100644 index 0000000..9a0a83f --- /dev/null +++ b/src/superagent/types/validation_error_loc_item.py @@ -0,0 +1,5 @@ +# This file was auto-generated by Fern from our API Definition. + +import typing + +ValidationErrorLocItem = typing.Union[str, int]