-
Notifications
You must be signed in to change notification settings - Fork 1
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
0 parents
commit 065122e
Showing
24 changed files
with
787 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 @@ | ||
# Specify files that shouldn't be modified by Fern |
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,36 @@ | ||
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 . | ||
test: | ||
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: Test | ||
run: poetry run pytest . |
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 |
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,22 @@ | ||
[tool.poetry] | ||
name = "open-copilot" | ||
version = "0.0.0" | ||
description = "" | ||
readme = "README.md" | ||
authors = [] | ||
packages = [ | ||
{ include = "open-copilot", from = "src"} | ||
] | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.7" | ||
httpx = ">=0.21.2" | ||
pydantic = "^1.9.2" | ||
|
||
[tool.poetry.dev-dependencies] | ||
mypy = "0.971" | ||
pytest = "^7.4.0" | ||
|
||
[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,5 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
||
from .resources import Chatbot, ChatbotStatus, chat, copilot | ||
|
||
__all__ = ["Chatbot", "ChatbotStatus", "chat", "copilot"] |
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,23 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
||
import typing | ||
|
||
import httpx | ||
|
||
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper | ||
from .resources.chat.client import AsyncChatClient, ChatClient | ||
from .resources.copilot.client import AsyncCopilotClient, CopilotClient | ||
|
||
|
||
class OpenCopilotApi: | ||
def __init__(self, *, base_url: str, timeout: typing.Optional[float] = 60): | ||
self._client_wrapper = SyncClientWrapper(base_url=base_url, httpx_client=httpx.Client(timeout=timeout)) | ||
self.chat = ChatClient(client_wrapper=self._client_wrapper) | ||
self.copilot = CopilotClient(client_wrapper=self._client_wrapper) | ||
|
||
|
||
class AsyncOpenCopilotApi: | ||
def __init__(self, *, base_url: str, timeout: typing.Optional[float] = 60): | ||
self._client_wrapper = AsyncClientWrapper(base_url=base_url, httpx_client=httpx.AsyncClient(timeout=timeout)) | ||
self.chat = AsyncChatClient(client_wrapper=self._client_wrapper) | ||
self.copilot = AsyncCopilotClient(client_wrapper=self._client_wrapper) |
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,17 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
||
from .api_error import ApiError | ||
from .client_wrapper import AsyncClientWrapper, BaseClientWrapper, SyncClientWrapper | ||
from .datetime_utils import serialize_datetime | ||
from .jsonable_encoder import jsonable_encoder | ||
from .remove_none_from_dict import remove_none_from_dict | ||
|
||
__all__ = [ | ||
"ApiError", | ||
"AsyncClientWrapper", | ||
"BaseClientWrapper", | ||
"SyncClientWrapper", | ||
"jsonable_encoder", | ||
"remove_none_from_dict", | ||
"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,33 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
||
import typing | ||
|
||
import httpx | ||
|
||
|
||
class BaseClientWrapper: | ||
def __init__(self, *, base_url: str): | ||
self._base_url = base_url | ||
|
||
def get_headers(self) -> typing.Dict[str, str]: | ||
headers: typing.Dict[str, str] = { | ||
"X-Fern-Language": "Python", | ||
"X-Fern-SDK-Name": "open-copilot", | ||
"X-Fern-SDK-Version": "0.0.0", | ||
} | ||
return headers | ||
|
||
def get_base_url(self) -> str: | ||
return self._base_url | ||
|
||
|
||
class SyncClientWrapper(BaseClientWrapper): | ||
def __init__(self, *, base_url: str, httpx_client: httpx.Client): | ||
super().__init__(base_url=base_url) | ||
self.httpx_client = httpx_client | ||
|
||
|
||
class AsyncClientWrapper(BaseClientWrapper): | ||
def __init__(self, *, base_url: str, httpx_client: httpx.AsyncClient): | ||
super().__init__(base_url=base_url) | ||
self.httpx_client = httpx_client |
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 Any, Dict, Optional | ||
|
||
|
||
def remove_none_from_dict(original: Dict[str, Optional[Any]]) -> Dict[str, Any]: | ||
new: Dict[str, Any] = {} | ||
for key, value in original.items(): | ||
if value is not None: | ||
new[key] = value | ||
return new |
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,6 @@ | ||
# This file was auto-generated by Fern from our API Definition. | ||
|
||
from . import chat, copilot | ||
from .copilot import Chatbot, ChatbotStatus | ||
|
||
__all__ = ["Chatbot", "ChatbotStatus", "chat", "copilot"] |
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.