diff --git a/lib/action/base.py b/lib/action/base.py index b3794d6..d9ccfbd 100644 --- a/lib/action/base.py +++ b/lib/action/base.py @@ -39,9 +39,23 @@ class Action(ABC): @property @abstractmethod - def name(self) -> str: + def display_name(self) -> str: pass + @property + @abstractmethod + def action_name(self) -> str: + pass + + @property + @abstractmethod + def description(self) -> str: + pass + + @property + def usage_examples(self) -> List[str]: + return [] + @property @abstractmethod def grammar(self) -> str: @@ -116,7 +130,7 @@ class SingleArgAction(Action, ABC): self.arg = arg def __repr__(self) -> str: - return f"{self.name}({self.arg})" + return f"{self.display_name}({self.arg})" class MultiArgAction(Action, ABC): arity = ActionArity.MULTI diff --git a/lib/actions/avg.py b/lib/actions/avg.py index e937247..026678e 100644 --- a/lib/actions/avg.py +++ b/lib/actions/avg.py @@ -12,9 +12,17 @@ from custom_nodes.KepPromptLang.lib.parser.prompt_segment import PromptSegment class AverageAction(MultiArgAction): grammar = 'avg(" arg "|" arg "|" arg ")"' - name = "avg" chars = ["+", "+"] + display_name = "Average" + action_name = "avg" + description = "Performs a weighted average between two segments or actions. The recommended weight is 0 - 1." + usage_examples = [ + "avg(The cat is|The dog is|0.5)", + "avg(Cat|Dog|0.5)", + ] + + def __init__(self, args: List[List[Union[PromptSegment, Action]]]) -> None: super().__init__(args) diff --git a/lib/actions/diff.py b/lib/actions/diff.py index e8dd995..a5a4305 100644 --- a/lib/actions/diff.py +++ b/lib/actions/diff.py @@ -11,9 +11,17 @@ from custom_nodes.KepPromptLang.lib.parser.registration import register_action class DiffAction(MultiArgAction): grammar = 'diff(" arg ("|" arg)* ")"' - name = "diff" chars = ["-", "-"] + display_name = "Difference" + action_name = "diff" + description = "Subtracts the segments in the order they are given. The first segment is subtracted from the second, then the third from the result, and so on." + usage_examples = [ + "diff(The cat is|The dog is)", + "diff(Cat|Dog)", + "sum(diff(king|man)|woman)", + ] + def __init__(self, args: List[List[Union[PromptSegment, Action]]]): super().__init__(args) self.base_arg = args[0] diff --git a/lib/actions/mult.py b/lib/actions/mult.py index f457b85..84b3aaa 100644 --- a/lib/actions/mult.py +++ b/lib/actions/mult.py @@ -13,9 +13,16 @@ from custom_nodes.KepPromptLang.lib.parser.registration import register_action class MultiplyAction(MultiArgAction): grammar = 'mult(" arg+ ")"' - name = "mult" chars = ["[", "]"] + display_name = "Multiply" + action_name = "mult" + description = "Multiplies the provided segments or actions by the multiplier." + usage_examples = [ + "mult(The cat is|2.5)", + "mult(Cat|-1)", + ] + def __init__(self, args: List[List[SegOrAction]]) -> None: super().__init__(args) if len(args) != 2: diff --git a/lib/actions/neg.py b/lib/actions/neg.py index 31bd9cb..a28b645 100644 --- a/lib/actions/neg.py +++ b/lib/actions/neg.py @@ -7,9 +7,16 @@ from custom_nodes.KepPromptLang.lib.parser.registration import register_action class NegAction(SingleArgAction): grammar = 'neg(" arg+ ")"' - name = "neg" chars = ["[", "]"] + display_name = "Negate" + action_name = "neg" + description = "Negates the provided segments or actions." + usage_examples = [ + "neg(cat)", + "sum(king|neg(man)|women)", + ] + def token_length(self) -> int: """ Neg negates the embeddings of the base segment, so the length is the length of the base segment diff --git a/lib/actions/norm.py b/lib/actions/norm.py index 2a1c5d8..71cc02d 100644 --- a/lib/actions/norm.py +++ b/lib/actions/norm.py @@ -10,9 +10,16 @@ from custom_nodes.KepPromptLang.lib.parser.registration import register_action class NormAction(SingleArgAction): grammar = 'norm(" arg+ ")"' - name = "norm" chars = None + display_name = "Normalize" + action_name = "norm" + description = "Normalizes the provided segments or actions." + usage_examples = [ + "norm(cat)", + "sum(cat|norm(sum(tiger|fish)))", + ] + def token_length(self) -> int: """ Norm normalizes the embeddings of the base segment, so the length is the length of the base segment diff --git a/lib/actions/pooled_avg.py b/lib/actions/pooled_avg.py index d68af44..af4fcb7 100644 --- a/lib/actions/pooled_avg.py +++ b/lib/actions/pooled_avg.py @@ -14,9 +14,16 @@ from custom_nodes.KepPromptLang.lib.parser.prompt_segment import PromptSegment class PooledAvgAction(SingleArgAction): grammar = 'pooledAvg(" arg+ ")"' - name = "_exp-pooledAvg" chars = ["[", "]"] + display_name = "Pooled Average(Experimental)" + action_name = "_exp-pooledAvg" + description = "Processes the provided segments or actions fully through CLIP and creates a pooled average of the last hidden state by averaging the last hidden state of each token." + usage_examples = [ + "A cat on a _exp-pooledAvg(beautiful sunny day)", + "A _exp-pooledAvg(broken glass) bottle", + ] + def __init__(self, args): super().__init__(args) self.result = None diff --git a/lib/actions/pooler.py b/lib/actions/pooler.py index 91ae99a..f0bfd4b 100644 --- a/lib/actions/pooler.py +++ b/lib/actions/pooler.py @@ -14,9 +14,17 @@ from custom_nodes.KepPromptLang.lib.parser.prompt_segment import PromptSegment class PoolerAction(SingleArgAction): grammar = 'pooler(" arg+ ")"' - name = "_exp-pooler" chars = ["[", "]"] + display_name = "Pooler Output(Experimental)" + action_name = "_exp-pooler" + description = "Processes the provided segments or actions fully through CLIP and returns the pooler_output from the transformer" + usage_examples = [ + "A cat on a _exp-pooler(beautiful sunny day)", + "A _exp-pooler(broken glass) bottle", + ] + + def __init__(self, args): super().__init__(args) self.result = None diff --git a/lib/actions/pos_scale.py b/lib/actions/pos_scale.py index 803d2fa..fc0eb48 100644 --- a/lib/actions/pos_scale.py +++ b/lib/actions/pos_scale.py @@ -13,9 +13,15 @@ from custom_nodes.KepPromptLang.lib.actions.types import SegOrAction class PosScaleAction(MultiArgAction): grammar = 'posScale(" arg+ ")"' - name = "posScale" chars = ["[", "]"] + display_name = "Positional Embedding Scale" + action_name = "posScale" + description = "Scales(Multiplies) the positional embeddings of the provided segments or actions by the multiplier." + usage_examples = [ + "A posScale(cat|1.5) on a rainy day", + ] + def __init__(self, args: List[List[SegOrAction]]) -> None: super().__init__(args) if len(args) != 2: diff --git a/lib/actions/post_pos.py b/lib/actions/post_pos.py index e847067..e5065a5 100644 --- a/lib/actions/post_pos.py +++ b/lib/actions/post_pos.py @@ -13,9 +13,15 @@ from custom_nodes.KepPromptLang.lib.action.base import ( class PostPosAction(SingleArgAction): grammar = 'postPos(" arg+ ")"' - name = "postPos" chars = ["[", "]"] + display_name = "Ignore Positional Embeddings" + action_name = "postPos" + description = "Prevents positional embeddings from being applied to the provided segments or actions." + usage_examples = [ + "A postPos(cat) on a rainy day", + ] + def __init__(self, args): super().__init__(args) self.result = None diff --git a/lib/actions/rand.py b/lib/actions/rand.py index eb5d7cd..f2aaa93 100644 --- a/lib/actions/rand.py +++ b/lib/actions/rand.py @@ -17,6 +17,14 @@ class RandAction(MultiArgAction): name = "rand" chars = None + display_name = "Random Embedding" + action_name = "rand" + description = "Returns a random embedding of the specified token length, with the values optionally bounded by the second and third arguments." + usage_examples = [ + "A rand(1) cat", + "A rand(1|-1|1) cat", + ] + parsed_token_length = 0 range_min = 0 range_max = 1 diff --git a/lib/actions/scale_dims.py b/lib/actions/scale_dims.py index dc50dcf..f1a7942 100644 --- a/lib/actions/scale_dims.py +++ b/lib/actions/scale_dims.py @@ -10,11 +10,15 @@ from custom_nodes.KepPromptLang.lib.parser.prompt_segment import PromptSegment class ScaleDims(MultiArgAction): grammar = 'scaleDims(" arg ("|" arg)* ")"' - name = "scaleDims" - description = "Scales the specified dimensions of the input embeddings by the specified amount" - example = "'The scaleDims(cat|4,1.5|76,1.2) is happy' scales the 4th dimension by 1.5 and the 76th dimension by 1.2 for the word 'cat'" chars = ["-", "-"] + display_name = "Scale Dimensions" + action_name = "scaleDims" + description = "Scales the specified dimensions of the input embeddings by the specified amount" + usage_examples = [ + "The scaleDims(cat|4,1.5|76,1.2) is happy", + ] + def __init__(self, args: List[List[Union[PromptSegment, Action]]]): super().__init__(args) diff --git a/lib/actions/set_dims.py b/lib/actions/set_dims.py index dcb87f3..b5226cd 100644 --- a/lib/actions/set_dims.py +++ b/lib/actions/set_dims.py @@ -10,11 +10,15 @@ from custom_nodes.KepPromptLang.lib.parser.prompt_segment import PromptSegment class SetDims(MultiArgAction): grammar = 'setDims(" arg ("|" arg)* ")"' - name = "setDims" - description = "Sets the specified dimensions of the input embeddings to the specified value" - example = "'The scaleDims(cat|4,1.5|76,1.2) is happy' scales the 4th dimension by 1.5 and the 76th dimension by 1.2 for the word 'cat'" chars = ["-", "-"] + display_name = "Set Dimensions" + action_name = "setDims" + description = "Sets the specified dimensions of the input embeddings to the specified value" + usage_examples = [ + "The setDims(cat|4, -0.01253|76, 1.2) is happy" + ] + def __init__(self, args: List[List[Union[PromptSegment, Action]]]): super().__init__(args) diff --git a/lib/actions/slerp.py b/lib/actions/slerp.py index 15acc43..87bb4fd 100644 --- a/lib/actions/slerp.py +++ b/lib/actions/slerp.py @@ -12,9 +12,15 @@ from custom_nodes.KepPromptLang.lib.parser.prompt_segment import PromptSegment class SlerpAction(MultiArgAction): grammar = 'slerp(" arg "|" arg "|" arg ")"' - name = "slerp" chars = ["+", "+"] + display_name = "Slerp" + action_name = "slerp" + description = "Performs a slerp(Interpolation) between two segments or actions, with the given weight. The recommended weight is 0 - 1" + usage_examples = [ + "The slerp(cat|dog|0.5) is happy", + ] + def __init__(self, args: List[List[Union[PromptSegment, Action]]]) -> None: super().__init__(args) diff --git a/lib/actions/sum.py b/lib/actions/sum.py index 5865db7..baa68fa 100644 --- a/lib/actions/sum.py +++ b/lib/actions/sum.py @@ -11,9 +11,15 @@ from custom_nodes.KepPromptLang.lib.parser.registration import register_action class SumAction(MultiArgAction): grammar = 'sum(" arg ("|" arg)+ ")"' - name = "sum" chars = ["+", "+"] + display_name = "Sum" + action_name = "sum" + description = "Adds the embeddings of the provided segments or actions." + usage_examples = [ + "A happy sum(cat|dog|shark)", + ] + def __init__(self, args: List[List[Union[PromptSegment, Action]]]) -> None: super().__init__(args) diff --git a/lib/parser/registration.py b/lib/parser/registration.py index b72296b..96ff357 100644 --- a/lib/parser/registration.py +++ b/lib/parser/registration.py @@ -9,9 +9,9 @@ def register_action(action: Type[Action]) -> None: :rtype: object """ - if action.name in action_registry: - raise ValueError(f"Action {action.name} already registered") - action_registry[str(action.name)] = action + if action.action_name in action_registry: + raise ValueError(f"Action {action.action_name} already registered") + action_registry[str(action.action_name)] = action def get_action_by_name(name: str) -> Type[Action]: if name not in action_registry: