fix: return removed sampler

This commit is contained in:
Gilad S. 2024-09-12 03:57:46 +03:00 committed by GitHub
parent 4a2e5e0dc5
commit 4410aa09fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View File

@ -1057,7 +1057,7 @@ extern "C" {
LLAMA_API int llama_sampler_chain_n (const struct llama_sampler * chain); LLAMA_API int llama_sampler_chain_n (const struct llama_sampler * chain);
// after removing a sampler, the chain will no longer own it, and it will not be freed when the chain is freed // after removing a sampler, the chain will no longer own it, and it will not be freed when the chain is freed
LLAMA_API void llama_sampler_chain_remove( struct llama_sampler * chain, int32_t i); LLAMA_API struct llama_sampler * llama_sampler_chain_remove( struct llama_sampler * chain, int32_t i);
// available samplers: // available samplers:

View File

@ -356,15 +356,17 @@ struct llama_sampler * llama_sampler_chain_get(const struct llama_sampler * chai
return p->samplers[i]; return p->samplers[i];
} }
void llama_sampler_chain_remove(struct llama_sampler * chain, int32_t i) { struct llama_sampler * llama_sampler_chain_remove(struct llama_sampler * chain, int32_t i) {
auto * p = (llama_sampler_chain *) chain->ctx; auto * p = (llama_sampler_chain *) chain->ctx;
if (i < 0 || i >= (int32_t) p->samplers.size()) { if (i < 0 || i >= (int32_t) p->samplers.size()) {
return; return nullptr;
} }
auto * result = p->samplers[i]; auto * result = p->samplers[i];
p->samplers.erase(p->samplers.begin() + i); p->samplers.erase(p->samplers.begin() + i);
return result;
} }
int llama_sampler_chain_n(const struct llama_sampler * chain) { int llama_sampler_chain_n(const struct llama_sampler * chain) {