MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / opt_repetitions

Method opt_repetitions

examples/server/server.py:190–202  ·  view source on GitHub ↗
(up_to_n: int, prefix_with_sep: bool = False)

Source from the content-addressed store, hash-verified

188 )
189
190 def opt_repetitions(up_to_n: int, prefix_with_sep: bool = False) -> str:
191 content = (
192 f"{separator_rule} {item_rule}"
193 if prefix_with_sep and separator_rule
194 else item_rule
195 )
196 if up_to_n == 0:
197 return ""
198 if up_to_n == 1:
199 return f"({content})?"
200 if separator_rule and not prefix_with_sep:
201 return f"({content} {opt_repetitions(up_to_n - 1, prefix_with_sep=True)})?"
202 return (f"({content} " * up_to_n).rstrip() + (")?" * up_to_n)
203
204 if min_items > 0 and max_items != min_items:
205 result += " "

Callers

nothing calls this directly

Calls 1

opt_repetitionsFunction · 0.85

Tested by

no test coverage detected