Streaming + logging works in Typescript SDK
Also added some high-level tests to minimize the chances that we're breaking anything. The typescript SDK is mostly functional at this point, with the exception that we don't have a build process or way to import it when deployed as an NPM package.
This commit is contained in:
@@ -13,7 +13,8 @@ from .local_testing_only_get_latest_logged_call_response_200_tags import (
|
||||
from .report_json_body import ReportJsonBody
|
||||
from .report_json_body_tags import ReportJsonBodyTags
|
||||
from .report_response_200 import ReportResponse200
|
||||
from .report_response_200_status import ReportResponse200Status
|
||||
from .report_response_200_status_type_0 import ReportResponse200StatusType0
|
||||
from .report_response_200_status_type_1 import ReportResponse200StatusType1
|
||||
|
||||
__all__ = (
|
||||
"CheckCacheJsonBody",
|
||||
@@ -25,5 +26,6 @@ __all__ = (
|
||||
"ReportJsonBody",
|
||||
"ReportJsonBodyTags",
|
||||
"ReportResponse200",
|
||||
"ReportResponse200Status",
|
||||
"ReportResponse200StatusType0",
|
||||
"ReportResponse200StatusType1",
|
||||
)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from typing import Any, Dict, Type, TypeVar
|
||||
from typing import Any, Dict, Type, TypeVar, Union
|
||||
|
||||
from attrs import define
|
||||
|
||||
from ..models.report_response_200_status import ReportResponse200Status
|
||||
from ..models.report_response_200_status_type_0 import ReportResponse200StatusType0
|
||||
from ..models.report_response_200_status_type_1 import ReportResponse200StatusType1
|
||||
|
||||
T = TypeVar("T", bound="ReportResponse200")
|
||||
|
||||
@@ -11,13 +12,19 @@ T = TypeVar("T", bound="ReportResponse200")
|
||||
class ReportResponse200:
|
||||
"""
|
||||
Attributes:
|
||||
status (ReportResponse200Status):
|
||||
status (Union[ReportResponse200StatusType0, ReportResponse200StatusType1]):
|
||||
"""
|
||||
|
||||
status: ReportResponse200Status
|
||||
status: Union[ReportResponse200StatusType0, ReportResponse200StatusType1]
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
status = self.status.value
|
||||
status: str
|
||||
|
||||
if isinstance(self.status, ReportResponse200StatusType0):
|
||||
status = self.status.value
|
||||
|
||||
else:
|
||||
status = self.status.value
|
||||
|
||||
field_dict: Dict[str, Any] = {}
|
||||
field_dict.update(
|
||||
@@ -31,7 +38,23 @@ class ReportResponse200:
|
||||
@classmethod
|
||||
def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T:
|
||||
d = src_dict.copy()
|
||||
status = ReportResponse200Status(d.pop("status"))
|
||||
|
||||
def _parse_status(data: object) -> Union[ReportResponse200StatusType0, ReportResponse200StatusType1]:
|
||||
try:
|
||||
if not isinstance(data, str):
|
||||
raise TypeError()
|
||||
status_type_0 = ReportResponse200StatusType0(data)
|
||||
|
||||
return status_type_0
|
||||
except: # noqa: E722
|
||||
pass
|
||||
if not isinstance(data, str):
|
||||
raise TypeError()
|
||||
status_type_1 = ReportResponse200StatusType1(data)
|
||||
|
||||
return status_type_1
|
||||
|
||||
status = _parse_status(d.pop("status"))
|
||||
|
||||
report_response_200 = cls(
|
||||
status=status,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ReportResponse200Status(str, Enum):
|
||||
class ReportResponse200StatusType0(str, Enum):
|
||||
OK = "ok"
|
||||
|
||||
def __str__(self) -> str:
|
||||
@@ -0,0 +1,8 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ReportResponse200StatusType1(str, Enum):
|
||||
ERROR = "error"
|
||||
|
||||
def __str__(self) -> str:
|
||||
return str(self.value)
|
||||
@@ -24,10 +24,18 @@ def _get_tags(openpipe_options):
|
||||
return ReportJsonBodyTags.from_dict(tags)
|
||||
|
||||
|
||||
def _should_check_cache(openpipe_options):
|
||||
def _should_check_cache(openpipe_options, req_payload):
|
||||
if configured_client.token == "":
|
||||
return False
|
||||
return openpipe_options.get("cache", False)
|
||||
|
||||
cache_requested = openpipe_options.get("cache", False)
|
||||
streaming = req_payload.get("stream", False)
|
||||
if cache_requested and streaming:
|
||||
print(
|
||||
"Caching is not yet supported for streaming requests. Ignoring cache flag. Vote for this feature at https://github.com/OpenPipe/OpenPipe/issues/159"
|
||||
)
|
||||
return False
|
||||
return cache_requested
|
||||
|
||||
|
||||
def _process_cache_payload(
|
||||
@@ -44,7 +52,7 @@ def maybe_check_cache(
|
||||
openpipe_options={},
|
||||
req_payload={},
|
||||
):
|
||||
if not _should_check_cache(openpipe_options):
|
||||
if not _should_check_cache(openpipe_options, req_payload):
|
||||
return None
|
||||
try:
|
||||
payload = check_cache.sync(
|
||||
@@ -68,7 +76,7 @@ async def maybe_check_cache_async(
|
||||
openpipe_options={},
|
||||
req_payload={},
|
||||
):
|
||||
if not _should_check_cache(openpipe_options):
|
||||
if not _should_check_cache(openpipe_options, req_payload):
|
||||
return None
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user