Skip to content

Commit

Permalink
Merge pull request #41 from Bobholamovic/dev/agent
Browse files Browse the repository at this point in the history
Fix Gradio Demo Bugs
  • Loading branch information
juncaipeng committed Oct 24, 2023
2 parents c6e29f9 + 6483c82 commit 2c3c773
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 398 deletions.
11 changes: 5 additions & 6 deletions erniebot/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ def retrieve_entry(self, api_type: str,

return key, val

def add_or_update_entry(
self,
api_type: str,
key: Hashable,
value: Union[str, Callable[[], str]]) -> Optional[str]:
def upsert_entry(self,
api_type: str,
key: Hashable,
value: Union[str, Callable[[], str]]) -> Optional[str]:
with self._cond:
self._writes += 1
while self._reads > 0 or self._is_writing:
Expand Down Expand Up @@ -167,7 +166,7 @@ def _retrieve_from_cache(self) -> Optional[str]:
self._cache_key)[1]

def _update_cache(self, init: bool) -> str:
token = _GlobalAuthCache().add_or_update_entry(
token = _GlobalAuthCache().upsert_entry(
self.api_type.name,
self._cache_key,
functools.partial(
Expand Down
9 changes: 4 additions & 5 deletions erniebot/resources/abc/cancellable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import abc
from typing import (Any, Dict, Optional, Tuple)

from typing_extensions import Protocol, runtime_checkable

from erniebot.response import EBResponse
from erniebot.types import (ParamsType, HeadersType)
from .protocol import Resource


@runtime_checkable
class Cancellable(Resource, Protocol):
"""Cancellable resource protocol."""
class Cancellable(Resource):
"""Cancellable resource."""

@classmethod
def cancel(cls, **kwargs: Any) -> EBResponse:
Expand Down Expand Up @@ -68,6 +66,7 @@ async def acancel_resource(self, **cancel_kwargs: Any) -> EBResponse:
resp = self._postprocess_cancel(resp)
return resp

@abc.abstractmethod
def _prepare_cancel(self,
kwargs: Dict[str, Any]) -> Tuple[str,
Optional[ParamsType],
Expand Down
9 changes: 4 additions & 5 deletions erniebot/resources/abc/creatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import abc
from typing import (Any, AsyncIterator, Dict, Iterator, Optional, Tuple, Union)

from typing_extensions import Protocol, runtime_checkable

from erniebot.response import EBResponse
from erniebot.types import (ParamsType, HeadersType, FilesType, ResponseT)
from .protocol import Resource


@runtime_checkable
class Creatable(Resource, Protocol):
"""Creatable resource protocol."""
class Creatable(Resource):
"""Creatable resource."""

@classmethod
def create(cls, **kwargs: Any) -> Union[EBResponse, Iterator[EBResponse]]:
Expand Down Expand Up @@ -76,6 +74,7 @@ async def acreate_resource(
resp = self._postprocess_create(resp) # type: ignore
return resp

@abc.abstractmethod
def _prepare_create(self,
kwargs: Dict[str, Any]) -> Tuple[str,
Optional[ParamsType],
Expand Down
9 changes: 4 additions & 5 deletions erniebot/resources/abc/queryable.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import abc
from typing import (Any, Dict, Optional, Tuple)

from typing_extensions import Protocol, runtime_checkable

from erniebot.response import EBResponse
from erniebot.types import (ParamsType, HeadersType)
from .protocol import Resource


@runtime_checkable
class Queryable(Resource, Protocol):
"""Queryable resource protocol."""
class Queryable(Resource):
"""Queryable resource."""

@classmethod
def query(cls, **kwargs: Any) -> EBResponse:
Expand Down Expand Up @@ -68,6 +66,7 @@ async def aquery_resource(self, **query_kwargs: Any) -> EBResponse:
resp = self._postprocess_query(resp)
return resp

@abc.abstractmethod
def _prepare_query(self,
kwargs: Dict[str, Any]) -> Tuple[str,
Optional[ParamsType],
Expand Down
Loading

0 comments on commit 2c3c773

Please sign in to comment.