| 642 | |
| 643 | |
| 644 | class CustomSampler: |
| 645 | def __init__(self, apply_func: Callable[[llama_cpp.llama_token_data_array], None]): |
| 646 | self.apply_func = apply_func |
| 647 | |
| 648 | def apply_wrapper( |
| 649 | sampler: llama_cpp.llama_sampler_p, |
| 650 | cur_p: llama_cpp.llama_token_data_array_p, |
| 651 | ): |
| 652 | self.apply_func(cur_p) |
| 653 | |
| 654 | def free_wrapper(sampler: llama_cpp.llama_sampler_p): |
| 655 | pass |
| 656 | |
| 657 | sampler_i = llama_cpp.llama_sampler_i() |
| 658 | sampler_i.apply = llama_cpp.llama_sampler_i_apply(apply_wrapper) |
| 659 | self._apply_wrapper_ref = apply_wrapper |
| 660 | |
| 661 | sampler_i.name = llama_cpp.llama_sampler_i_name(0) |
| 662 | sampler_i.accept = llama_cpp.llama_sampler_i_accept(0) |
| 663 | sampler_i.reset = llama_cpp.llama_sampler_i_reset(0) |
| 664 | sampler_i.clone = llama_cpp.llama_sampler_i_clone(0) |
| 665 | sampler_i.free = llama_cpp.llama_sampler_i_free(0) |
| 666 | |
| 667 | self.sampler = llama_cpp.llama_sampler() |
| 668 | self.sampler.iface = ctypes.pointer(sampler_i) |
| 669 | self.sampler.ctx = None |
| 670 | |
| 671 | def get_sampler(self) -> llama_cpp.llama_sampler_p: |
| 672 | return ctypes.pointer(self.sampler) |
| 673 | |
| 674 | |
| 675 | class LlamaSampler: |
no outgoing calls
no test coverage detected
searching dependent graphs…