MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / __init__

Method __init__

src/optimizer/textgrad/loss.py:148–184  ·  view source on GitHub ↗

The test-time loss to use when working on a response to a multiple choice question. :param evaluation_instruction: Instruction to guide the test time evaluation. This will be a prefix to the prompt. :type evaluation_instruction: str :param engine: LLM engine to use

(self,
                 evaluation_instruction: str,
                 engine: Union[EngineLM, str] = None,
                 system_prompt: Variable = None)

Source from the content-addressed store, hash-verified

146
147class MultiChoiceTestTime(Module):
148 def __init__(self,
149 evaluation_instruction: str,
150 engine: Union[EngineLM, str] = None,
151 system_prompt: Variable = None):
152 """
153 The test-time loss to use when working on a response to a multiple choice question.
154
155 :param evaluation_instruction: Instruction to guide the test time evaluation. This will be a prefix to the prompt.
156 :type evaluation_instruction: str
157 :param engine: LLM engine to use for the test-time loss computation.
158 :type engine: EngineLM
159 :param system_prompt: System prompt for the test-time loss computation, defaults to None
160 :type system_prompt: Variable, optional
161 """
162 super().__init__()
163 if system_prompt:
164 self.tt_system_prompt = system_prompt
165 else:
166 tt_system_prompt = DEFAULT_TEST_TIME
167 self.tt_system_prompt = Variable(tt_system_prompt,
168 requires_grad=False,
169 role_description="system prompt for the test-time evaluation")
170
171 if ((engine is None) and (SingletonBackwardEngine().get_engine() is None)):
172 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.")
173 elif engine is None:
174 engine = SingletonBackwardEngine().get_engine()
175 if isinstance(engine, str):
176 engine = get_engine(engine)
177 self.engine = engine
178 format_string = "{instruction}\nQuestion: {{question}}\nAnswer by the language model: {{prediction}}"
179 self.format_string = format_string.format(instruction=evaluation_instruction)
180 self.fields = {"prediction": None, "question": None}
181 self.formatted_llm_call = FormattedLLMCall(engine=self.engine,
182 format_string=self.format_string,
183 fields=self.fields,
184 system_prompt=self.tt_system_prompt)
185
186 def forward(self, question: str, prediction: Variable) -> Variable:
187 question_variable = Variable(question,

Callers

nothing calls this directly

Calls 7

get_engineFunction · 0.85
FormattedLLMCallClass · 0.85
get_engineMethod · 0.80
VariableClass · 0.70
__init__Method · 0.45
formatMethod · 0.45

Tested by

no test coverage detected