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

Function opt_repetitions

llama_cpp/llama_grammar.py:273–292  ·  view source on GitHub ↗

- n=4, no sep: '(a (a (a (a)?)?)?)?' - n=4, sep=',', prefix: '("," a ("," a ("," a ("," a)?)?)?)?' - n=4, sep=',', no prefix: '(a ("," a ("," a ("," a)?)?)?)?'

(up_to_n, prefix_with_sep=False)

Source from the content-addressed store, hash-verified

271 )
272
273 def opt_repetitions(up_to_n, prefix_with_sep=False):
274 """
275 - n=4, no sep: '(a (a (a (a)?)?)?)?'
276 - n=4, sep=',', prefix: '("," a ("," a ("," a ("," a)?)?)?)?'
277 - n=4, sep=',', no prefix: '(a ("," a ("," a ("," a)?)?)?)?'
278 """
279
280 content = (
281 f"{separator_rule} {item_rule}"
282 if prefix_with_sep and separator_rule
283 else item_rule
284 )
285 if up_to_n == 0:
286 return ""
287 elif up_to_n == 1:
288 return f"({content})?"
289 elif separator_rule and not prefix_with_sep:
290 return f"({content} {opt_repetitions(up_to_n - 1, prefix_with_sep=True)})?"
291 else:
292 return (f"({content} " * up_to_n).rstrip() + (")?" * up_to_n)
293
294 if min_items > 0 and max_items != min_items:
295 result += " "

Callers 3

_build_repetitionFunction · 0.85
opt_repetitionsMethod · 0.85
_build_repetitionMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…