Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Pydantic models in server endpoint args and return type #92

Open
ddayan opened this issue Nov 17, 2024 · 0 comments
Open

Support Pydantic models in server endpoint args and return type #92

ddayan opened this issue Nov 17, 2024 · 0 comments
Assignees

Comments

@ddayan
Copy link
Contributor

ddayan commented Nov 17, 2024

Support any pydentic based models in endpoint arguments and return type:

class Message(BaseModel):
....

class Response(BaseModel):
....

Expected behaviour fails:

  @endpoint
    def generate(self, request: Message) -> Response:
        embedding = self.tokenizer.embedding_function.encode(request.content)
        return Response(embedding) 

Workaround:

   @endpoint
    def generate(self, request: Message) -> dict:
        request = Message.model_validate(request)
        embedding = self.tokenizer.embedding_function.encode(request.content)
        return {"response": embedding}
@ddayan ddayan changed the title Support Pydantic models in server endpoint args Support Pydantic models in server endpoint args and return type Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants