Source code for codegrade.models.attest_defense_ai_use_rules

"""The module that defines the ``AttestDefenseAiUseRules`` model.

SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""

from __future__ import annotations

import typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa

from ..utils import to_dict


[docs] @dataclass(kw_only=True) class AttestDefenseAiUseRules: """The rule of an assignment for each use of AI.""" #: The rule for finding sources. finding_sources: t.Literal[ "allowed", "allowed_if_disclosed", "not_allowed" ] #: The rule for brainstorming. brainstorming: t.Literal["allowed", "allowed_if_disclosed", "not_allowed"] #: The rule for drafting text. drafting_text: t.Literal["allowed", "allowed_if_disclosed", "not_allowed"] #: The rule for writing code. writing_code: t.Literal["allowed", "allowed_if_disclosed", "not_allowed"] #: The rule for editing. editing: t.Literal["allowed", "allowed_if_disclosed", "not_allowed"] #: The rule for checking work. checking_work: t.Literal["allowed", "allowed_if_disclosed", "not_allowed"] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: rqa.FixedMapping( rqa.RequiredArgument( "finding_sources", rqa.StringEnum( "allowed", "allowed_if_disclosed", "not_allowed" ), doc="The rule for finding sources.", ), rqa.RequiredArgument( "brainstorming", rqa.StringEnum( "allowed", "allowed_if_disclosed", "not_allowed" ), doc="The rule for brainstorming.", ), rqa.RequiredArgument( "drafting_text", rqa.StringEnum( "allowed", "allowed_if_disclosed", "not_allowed" ), doc="The rule for drafting text.", ), rqa.RequiredArgument( "writing_code", rqa.StringEnum( "allowed", "allowed_if_disclosed", "not_allowed" ), doc="The rule for writing code.", ), rqa.RequiredArgument( "editing", rqa.StringEnum( "allowed", "allowed_if_disclosed", "not_allowed" ), doc="The rule for editing.", ), rqa.RequiredArgument( "checking_work", rqa.StringEnum( "allowed", "allowed_if_disclosed", "not_allowed" ), doc="The rule for checking work.", ), ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "finding_sources": to_dict(self.finding_sources), "brainstorming": to_dict(self.brainstorming), "drafting_text": to_dict(self.drafting_text), "writing_code": to_dict(self.writing_code), "editing": to_dict(self.editing), "checking_work": to_dict(self.checking_work), } return res @classmethod def from_dict( cls: t.Type[AttestDefenseAiUseRules], d: t.Dict[str, t.Any] ) -> AttestDefenseAiUseRules: parsed = cls.data_parser.try_parse(d) res = cls( finding_sources=parsed.finding_sources, brainstorming=parsed.brainstorming, drafting_text=parsed.drafting_text, writing_code=parsed.writing_code, editing=parsed.editing, checking_work=parsed.checking_work, ) res.raw_data = d return res