From 7f1cb71bac92d254c57122ae1d149c59842cd12f Mon Sep 17 00:00:00 2001 From: mertyg Date: Tue, 11 Jun 2024 16:12:42 -0700 Subject: [PATCH] let args be strings --- textgrad/loss.py | 4 +++- textgrad/model.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/textgrad/loss.py b/textgrad/loss.py index 0457ec2..d422db1 100644 --- a/textgrad/loss.py +++ b/textgrad/loss.py @@ -8,7 +8,7 @@ class TextLoss(Module): def __init__(self, - eval_system_prompt: Variable, + eval_system_prompt: Union[Variable, str], engine: Union[EngineLM, str] = None): """ A vanilla loss function to evaluate a response. @@ -29,6 +29,8 @@ def __init__(self, >>> response_evaluator(response) """ super().__init__() + if isinstance(eval_system_prompt, str): + eval_system_prompt = Variable(eval_system_prompt, requires_grad=False, role_description="system prompt for the evaluation") self.eval_system_prompt = eval_system_prompt if ((engine is None) and (SingletonBackwardEngine().get_engine() is None)): raise Exception("No engine provided. Either provide an engine as the argument to this call, or use `textgrad.set_backward_engine(engine)` to set the backward engine.") diff --git a/textgrad/model.py b/textgrad/model.py index c0042e9..882cf19 100644 --- a/textgrad/model.py +++ b/textgrad/model.py @@ -8,7 +8,7 @@ from .config import SingletonBackwardEngine class BlackboxLLM(Module): - def __init__(self, engine: Union[EngineLM, str] = None, system_prompt: Variable = None): + def __init__(self, engine: Union[EngineLM, str] = None, system_prompt: Union[Variable, str] = None): """ Initialize the LLM module. @@ -24,6 +24,8 @@ def __init__(self, engine: Union[EngineLM, str] = None, system_prompt: Variable if isinstance(engine, str): engine = get_engine(engine) self.engine = engine + if isinstance(system_prompt, str): + system_prompt = Variable(system_prompt, requires_grad=False, role_description="system prompt for the language model") self.system_prompt = system_prompt self.llm_call = LLMCall(self.engine, self.system_prompt)