-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4240f0a
commit 56608d2
Showing
6 changed files
with
64 additions
and
27 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
Empty file.
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,17 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any, Generic, TypeVar | ||
|
||
from attrs import define | ||
|
||
from griptape.mixins.serializable_mixin import SerializableMixin | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
@define | ||
class BaseSchemaDriver(ABC, SerializableMixin, Generic[T]): | ||
@abstractmethod | ||
def validate(self, model: T, data: Any) -> Any: ... | ||
|
||
@abstractmethod | ||
def to_json_schema(self, model: T) -> dict: ... |
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,15 @@ | ||
from typing import Any | ||
|
||
from attrs import define | ||
from pydantic import BaseModel | ||
|
||
from griptape.drivers import BaseSchemaDriver | ||
|
||
|
||
@define | ||
class PydanticSchemaDriver(BaseSchemaDriver[BaseModel]): | ||
def validate(self, model: BaseModel, data: Any) -> Any: | ||
return model.model_validate(data) | ||
|
||
def to_json_schema(self, model: BaseModel) -> dict: | ||
return model.model_dump() |
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,15 @@ | ||
from typing import Any | ||
|
||
from attrs import define | ||
from schema import Schema | ||
|
||
from griptape.drivers import BaseSchemaDriver | ||
|
||
|
||
@define | ||
class SchemaSchemaDriver(BaseSchemaDriver[Schema]): | ||
def validate(self, model: Schema, data: Any) -> Any: | ||
return model.validate(data) | ||
|
||
def to_json_schema(self, model: Schema) -> dict: | ||
return model.json_schema("Schema") |
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