This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce singular model component and singular pipeline
- Loading branch information
1 parent
91ddb8e
commit 20adf41
Showing
3 changed files
with
106 additions
and
2 deletions.
There are no files selected for viewing
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
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,78 @@ | ||
# -*- coding: utf-8 -*- | ||
from typing import Any, Generic, List, Optional | ||
|
||
from pydantic.generics import GenericModel | ||
|
||
from wyvern.components.business_logic.business_logic import BusinessLogicPipeline | ||
from wyvern.components.component import Component | ||
from wyvern.components.events.events import LoggedEvent | ||
from wyvern.components.models.model_component import SingularModelComponent | ||
from wyvern.components.pipeline_component import PipelineComponent | ||
from wyvern.entities.model_entities import SingularModelInput | ||
from wyvern.entities.request import BaseWyvernRequest | ||
from wyvern.event_logging import event_logger | ||
from wyvern.wyvern_typing import ( | ||
GENERALIZED_WYVERN_ENTITY, | ||
REQUEST_ENTITY, | ||
RESPONSE_SCHEMA, | ||
) | ||
|
||
|
||
class SingularPipelineRequest( | ||
BaseWyvernRequest, | ||
Generic[GENERALIZED_WYVERN_ENTITY, REQUEST_ENTITY], | ||
): | ||
entity: GENERALIZED_WYVERN_ENTITY | ||
request: REQUEST_ENTITY | ||
|
||
|
||
class SingularPipelineResponse(GenericModel, Generic[RESPONSE_SCHEMA]): | ||
data: RESPONSE_SCHEMA | ||
events: Optional[List[LoggedEvent[Any]]] | ||
|
||
|
||
class SingularPipelineComponent( | ||
PipelineComponent[ | ||
SingularPipelineRequest[GENERALIZED_WYVERN_ENTITY, REQUEST_ENTITY], | ||
SingularPipelineResponse[RESPONSE_SCHEMA], | ||
], | ||
Generic[GENERALIZED_WYVERN_ENTITY, REQUEST_ENTITY, RESPONSE_SCHEMA], | ||
): | ||
def __init__( | ||
self, | ||
*upstreams: Component, | ||
model: SingularModelComponent, | ||
business_logic: Optional[BusinessLogicPipeline] = None, | ||
name: Optional[str] = None, | ||
handle_feature_store_exceptions: bool = False, | ||
) -> None: | ||
self.model = model | ||
self.business_logic = business_logic | ||
upstream_components = list(upstreams) | ||
upstream_components.append(self.model) | ||
if self.business_logic: | ||
upstream_components.append(self.business_logic) | ||
super().__init__( | ||
*upstream_components, | ||
name=name, | ||
handle_feature_store_exceptions=handle_feature_store_exceptions, | ||
) | ||
|
||
async def execute( | ||
self, | ||
input: SingularPipelineRequest[GENERALIZED_WYVERN_ENTITY, REQUEST_ENTITY], | ||
**kwargs, | ||
) -> SingularPipelineResponse[RESPONSE_SCHEMA]: | ||
model_input = SingularModelInput[ | ||
GENERALIZED_WYVERN_ENTITY, | ||
SingularPipelineRequest[GENERALIZED_WYVERN_ENTITY, REQUEST_ENTITY], | ||
]( | ||
request=input, | ||
entity=input.entity, | ||
) | ||
output = await self.model.execute(model_input, **kwargs) | ||
entity_data = output.data.get(input.entity.identifier) | ||
return SingularPipelineResponse( | ||
data=entity_data, | ||
events=event_logger.get_logged_events() if input.include_events else None, | ||
) |
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