Skip to content

Commit 759a525

Browse files
committed
feat: add llama_kv_self_seq_pos_min module function
1 parent 4356c65 commit 759a525

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

ext/llama_cpp/llama_cpp.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,27 @@ static VALUE rb_llama_kv_self_seq_div(VALUE self, VALUE ctx, VALUE seq_id, VALUE
20752075
return Qnil;
20762076
}
20772077

2078+
/**
2079+
* @overload llama_kv_self_seq_pos_min(context, seq_id)
2080+
* @param [LlamaContext] context
2081+
* @param [Integer] seq_id
2082+
* @return [Integer]
2083+
*/
2084+
static VALUE rb_llama_kv_self_seq_pos_min(VALUE self, VALUE ctx, VALUE seq_id) {
2085+
if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
2086+
rb_raise(rb_eArgError, "ctx must be a LlamaContext");
2087+
return Qnil;
2088+
}
2089+
if (!RB_INTEGER_TYPE_P(seq_id)) {
2090+
rb_raise(rb_eArgError, "seq_id must be an Integer");
2091+
return Qnil;
2092+
}
2093+
llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
2094+
const int32_t pos_max = llama_kv_self_seq_pos_min(context_wrapper->context, NUM2INT(seq_id));
2095+
RB_GC_GUARD(ctx);
2096+
return INT2NUM(pos_max);
2097+
}
2098+
20782099
/**
20792100
* @overload llama_kv_self_seq_pos_max(context, seq_id)
20802101
* @param [LlamaContext] context
@@ -4800,6 +4821,9 @@ void Init_llama_cpp(void) {
48004821
/* llama_kv_self_seq_div */
48014822
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_div", rb_llama_kv_self_seq_div, 5);
48024823

4824+
/* llama_kv_self_seq_pos_min */
4825+
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_pos_min", rb_llama_kv_self_seq_pos_min, 2);
4826+
48034827
/* llama_kv_self_seq_pos_max */
48044828
rb_define_module_function(rb_mLlamaCpp, "llama_kv_self_seq_pos_max", rb_llama_kv_self_seq_pos_max, 2);
48054829

0 commit comments

Comments
 (0)