Skip to content

Commit

Permalink
chore(client): optimize model build when no model serving api
Browse files Browse the repository at this point in the history
  • Loading branch information
jialeicui committed Jan 3, 2023
1 parent 95a713f commit 0970343
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions client/starwhale/api/_impl/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def add_api_instance(self, api_: Api) -> None:
self.apis[api_.uri] = api_

def get_spec(self) -> t.Any:
# fast path
if not self.apis:
return {}
server = self._gen_gradio_server()
return server.get_config_file()

Expand Down
11 changes: 11 additions & 0 deletions client/tests/data/sdk/service/no_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import typing as t

from starwhale import PipelineHandler, PPLResultIterator


class NoApi(PipelineHandler):
def ppl(self, data: t.Any, **kw: t.Any) -> t.Any:
pass

def cmp(self, ppl_result: PPLResultIterator) -> t.Any:
pass
4 changes: 4 additions & 0 deletions client/tests/sdk/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def test_default_class(self):
svc = StandaloneModel._get_service("default_class:MyDefaultClass", self.root)
assert list(svc.apis.keys()) == ["ppl", "handler_foo", "cmp"]

def test_class_without_api(self):
svc = StandaloneModel._get_service("no_api:NoApi", self.root)
assert svc.get_spec() == {}

def test_custom_service(self):
svc = StandaloneModel._get_service("custom_service", self.root)
assert list(svc.apis.keys()) == ["baz"]
Expand Down

0 comments on commit 0970343

Please sign in to comment.