MCPcopy Create free account
hub / github.com/algorithmicsuperintelligence/optillm / loop_until_match

Function loop_until_match

optillm/plugins/longcepo/utils.py:144–171  ·  view source on GitHub ↗

Repeatedly calls a function until its output matches one of the given patterns or max attempts is reached. Args: function (Callable): Function returning (answer: str, cb_log). pattern_list (Tuple[str]): Patterns to match in the answer. num_attempts (int): Max number

(
    function: Callable, pattern_list: Tuple[str], num_attempts: int = 10
)

Source from the content-addressed store, hash-verified

142
143
144def loop_until_match(
145 function: Callable, pattern_list: Tuple[str], num_attempts: int = 10
146):
147 """
148 Repeatedly calls a function until its output matches one of the given patterns or max attempts is reached.
149
150 Args:
151 function (Callable): Function returning (answer: str, cb_log).
152 pattern_list (Tuple[str]): Patterns to match in the answer.
153 num_attempts (int): Max number of attempts (default: 10).
154
155 Returns:
156 Tuple[str, Any]: The matching answer and its corresponding log object.
157 """
158 correct_format = False
159 for _ in range(num_attempts):
160 answer, cb_log = function()
161
162 for pattern in pattern_list:
163 if pattern in answer:
164 correct_format = True
165
166 if correct_format:
167 break
168
169 logger.info("Wrong output formatting, retrying...")
170
171 return answer, cb_log
172
173
174def longcepo_init(

Callers 2

mapreduceFunction · 0.85
run_longcepoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected