-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(py): Refactored Plugins API to follow generic
Plugin
interface.
- Loading branch information
Showing
5 changed files
with
125 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2025 Google LLC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from __future__ import annotations | ||
|
||
import abc | ||
import typing | ||
|
||
from genkit.core.schemas import GenerateRequest, GenerateResponse | ||
|
||
if typing.TYPE_CHECKING: | ||
from genkit.veneer import Genkit | ||
|
||
|
||
class Plugin(abc.ABC): | ||
""" | ||
Abstract class defining common interface | ||
for the Genkit Plugin implementation | ||
""" | ||
|
||
@abc.abstractmethod | ||
def attach_to_veneer(self, veneer: Genkit) -> None: | ||
""" | ||
Entrypoint for attaching the plugin to the requested Genkit Veneer | ||
:param veneer: requested `genkit.veneer.Genkit` instance | ||
""" | ||
pass | ||
|
||
def add_model_to_veneer( | ||
self, veneer: Genkit, name: str, metadata: dict | None = None | ||
) -> None: | ||
""" | ||
Generic method for defining arbitrary plugin's model | ||
in the Genkit Registry | ||
Uses self._model_callback as a generic callback wrapper, | ||
the actual implementation is up to inherited Plugin's implementation | ||
:param veneer: requested `genkit.veneer.Genkit` instance | ||
:param name: name of the model to attach | ||
:param metadata: metadata information associated | ||
with the provided model (optional) | ||
""" | ||
if not metadata: | ||
metadata = {} | ||
veneer.define_model( | ||
name=name, fn=self._model_callback, metadata=metadata | ||
) | ||
|
||
@abc.abstractmethod | ||
def _model_callback(self, request: GenerateRequest) -> GenerateResponse: | ||
""" | ||
Wrapper around any plugin's model callback. | ||
Is considered an entrypoint for any model's request | ||
:param request: incoming request as generic | ||
`genkit.core.schemas.GenerateRequest` instance | ||
:returns: model response represented as generic | ||
`genkit.core.schemas.GenerateResponse` instance | ||
""" | ||
pass |
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
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