cog icon indicating copy to clipboard operation
cog copied to clipboard

Output type List[Output] causes cog to generate invalid output schema

Open yorickvP opened this issue 2 years ago • 3 comments

This code:

class Output(BaseModel):
  text: str

class Predictor(BasePredictor):
  def predict(self) -> list[Output]:
    pass

confuses cog's get_output_type into generating a schema with no Output, thereby confusing the replicate.com UI

image

yorickvP avatar Nov 03 '23 14:11 yorickvP

Not sure if it's related but there was a change in Python 3.9 that made capital-L List the thing you use for type hinting, rather than list which is now just the built-in python list function.

If you do this, does it work?

from typing import List 

class Output(BaseModel):
  text: str

class Predictor(BasePredictor):
  def predict(self) -> List[Output]:
    pass

zeke avatar Nov 06 '23 22:11 zeke

No change. Test with cog run python3 -m cog.command.openapi_schema

yorickvP avatar Nov 07 '23 10:11 yorickvP

Here's another one: https://github.com/replicate/cog/pull/1267#issuecomment-1885038556

cc @aron

yorickvP avatar Jan 22 '24 15:01 yorickvP