Apps can define multiple entry points to support different modes of operation within the same container context. This reduces cold starts and resource duplication.
Use Cases
- LLMs: Separate
chat(history-aware) andcompletion(raw text) functions. - Image Models:
generate,upscale, andinpaintfunctions using the same loaded model. - Data Pipelines:
process,validate, andexportsteps exposed individually.
Defining Functions
Define functions as async methods on your App class. Each function (except setup) is an exposable entry point.
inference.py:
python
1from inferencesh import BaseApp, BaseAppInput, BaseAppOutput2from pydantic import Field3 4# 1. Define Schemas5class GenerateInput(BaseAppInput):6 prompt: str7 8class UpscaleInput(BaseAppInput):9 image_id: str10 scale: float = 2.011 12class ImageOutput(BaseAppOutput):13 uri: str14 15# 2. Define App16class App(BaseApp):17 async def setup(self, config):18 self.model = load_diffusion_pipeline()19 20 # Default function (optional, conventionally named 'run')21 async def run(self, input: GenerateInput) -> ImageOutput:22 return await self.generate(input)23 24 # Named function: generate25 async def generate(self, input: GenerateInput) -> ImageOutput:26 image = self.model(input.prompt)27 return ImageOutput(uri=save(image))28 29 # Named function: upscale30 async def upscale(self, input: UpscaleInput) -> ImageOutput:31 image = load(input.image_id)32 result = self.model.upscale(image, input.scale)33 return ImageOutput(uri=save(result))Running Specific Functions
Specify the function parameter when calling the app.
CLI
bash
1# Run 'upscale' function2infsh run input.json --function upscalePython SDK
python
1client.run({2 "app": "my-app",3 "function": "upscale",4 "input": {5 "image_id": "img_123",6 "scale": 4.07 }8})API
json
1POST /v1/run2{3 "app": "my-app",4 "function": "upscale",5 "input": { ... }6}