-
Notifications
You must be signed in to change notification settings - Fork 579
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
8c50fea
commit f594145
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
test-integration/test_integration/fixtures/partial-predict-project/cog.yaml
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 @@ | ||
build: | ||
python_version: "3.8" | ||
predict: "predict.py:Predictor" | ||
train: "predict.py:train" |
38 changes: 38 additions & 0 deletions
38
test-integration/test_integration/fixtures/partial-predict-project/predict.py
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,38 @@ | ||
from typing import Callable | ||
import functools | ||
|
||
from cog import BasePredictor, Input | ||
|
||
|
||
class Predictor(BasePredictor): | ||
def general( | ||
self, prompt: str = Input(description="hi"), system_prompt: str = None | ||
) -> int: | ||
return 1 | ||
|
||
def _remove(f: Callable, defaults: dict[str, Any]) -> Callable: | ||
# pylint: disable=no-self-argument | ||
def wrapper(self, *args, **kwargs): | ||
kwargs.update(defaults) | ||
return f(self, *args, **kwargs) | ||
|
||
# Update wrapper attributes for documentation, etc. | ||
functools.update_wrapper(wrapper, f) | ||
|
||
# for the purposes of inspect.signature as used by predictor.get_input_type, | ||
# remove the argument (system_prompt) | ||
sig = inspect.signature(f) | ||
params = [p for name, p in sig.parameters.items() if name not in defaults] | ||
wrapper.__signature__ = sig.replace(parameters=params) | ||
|
||
# Return partialmethod, wrapper behaves correctly when part of a class | ||
return functools.partialmethod(wrapper) | ||
|
||
predict = _remove(general, {"system_prompt": ""}) | ||
|
||
|
||
def _train(self, prompt: str = Input(description="hi"), system_prompt: str = None): | ||
return 1 | ||
|
||
|
||
train = functools.partial(_train, system_prompt="") |
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