-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b929756
commit f7e3d23
Showing
38 changed files
with
2,214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dist/ | ||
.mypy_cache/ | ||
__pycache__/ | ||
poetry.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
||
from .unprocessable_entity_error import UnprocessableEntityError | ||
|
||
__all__ = ["UnprocessableEntityError"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
Oops, something went wrong.