llama_cpp 0.25.2 → 0.25.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c2a769491201813ec3b65cc286f283342ca492cf8a893b24ba46a4536b7669d
4
- data.tar.gz: 95799ab5fa55ccdd691d65f81e5c48cd0702163c4eff2f589c2384e43d64af45
3
+ metadata.gz: 1b76e55acb48ffab518744a7afa4e60d16b716e596afd0bf73dd56859c399b2f
4
+ data.tar.gz: 26a29e928885236d6061920f5a21bd1cb9c7d33c0599554a17b363dc9276b55d
5
5
  SHA512:
6
- metadata.gz: a58b1879d867586b9b60a44b468babb69996359fb91bf8cf27f02a3c1b8a30538311f973a762f172d62e47dbeef8e2652c44d0b88cbbed345bba5532a5210d77
7
- data.tar.gz: 5ca17aa628b3c1d2a95bb1e21101c0531bbd7216efffe07fc3ac184cf7512fef54192e85762f74d363c090d1e91a2d3497e13f030beaf89d3f162f2dee15ac2b
6
+ metadata.gz: a332b1753028f192f70ab8a8144795989fd616ad4ad30d86b0cd44d6faa8aa7842b7dcb4cd8f4b2a0c1c50140b2d69593948a575fc3c3650899b4c52eb99519b
7
+ data.tar.gz: 9c4ed8bec9ebddc469f92dde6f477b85747c5b4c6a3db0f532e592bedbe4413c48ca0847a589809fc68ffed006ba05c93b7672aafd6bda3e27f83dfdd46781ff
data/CHANGELOG.md CHANGED
@@ -1,12 +1,25 @@
1
+ ## [[0.25.3](https://github.com/yoshoku/llama_cpp.rb/compare/v0.25.2...v0.25.3)] - 2026-05-24
2
+
3
+ - Add `llama_model_chat_template` module function to `LlamaCpp`.
4
+ - Add `llama_model_meta_val_str` module function to `LlamaCpp`.
5
+ - Add `llama_model_meta_key_by_index` module function to `LlamaCpp`.
6
+ - Add `llama_model_meta_val_str_by_index` module function to `LlamaCpp`.
7
+ - Change supported llama.cpp version to b9290.
8
+ - Add `LLAMA_CONTEXT_TYPE_DEFAULT` constant value.
9
+ - Add `LLAMA_CONTEXT_TYPE_MTP` constant value.
10
+ - Add `ctx_type` accessor to `LlamaContextParams`.
11
+ - Add `n_rs_seq` accessor to `LlamaContextParams`.
12
+ - Add `n_rs_seq` module function to `LlamaCpp`.
13
+
1
14
  ## [[0.25.2](https://github.com/yoshoku/llama_cpp.rb/compare/v0.25.1...v0.25.2)] - 2026-05-16
2
15
 
3
16
  - Change supported llama.cpp version to b9150.
4
- - ADD `LLAMA_STATE_SEQ_FLAGS_NONE` constant value.
17
+ - Add `LLAMA_STATE_SEQ_FLAGS_NONE` constant value.
5
18
 
6
19
  ## [[0.25.1](https://github.com/yoshoku/llama_cpp.rb/compare/v0.25.0...v0.25.1)] - 2026-05-09
7
20
 
8
21
  - Change supported llama.cpp version to b9070.
9
- - ADD `LLAMA_STATE_SEQ_FLAGS_ON_DEVICE` constant value.
22
+ - Add `LLAMA_STATE_SEQ_FLAGS_ON_DEVICE` constant value.
10
23
 
11
24
  ## [[0.25.0](https://github.com/yoshoku/llama_cpp.rb/compare/v0.24.3...v0.25.0)] - 2026-04-25
12
25
 
@@ -652,6 +652,17 @@ static VALUE llama_context_params_set_n_seq_max(VALUE self, VALUE n_seq_max) {
652
652
  return n_seq_max;
653
653
  }
654
654
 
655
+ static VALUE llama_context_params_get_n_rs_seq(VALUE self) {
656
+ struct llama_context_params* data = get_llama_context_params(self);
657
+ return UINT2NUM(data->n_rs_seq);
658
+ }
659
+
660
+ static VALUE llama_context_params_set_n_rs_seq(VALUE self, VALUE n_rs_seq) {
661
+ struct llama_context_params* data = get_llama_context_params(self);
662
+ data->n_rs_seq = NUM2UINT(n_rs_seq);
663
+ return n_rs_seq;
664
+ }
665
+
655
666
  static VALUE llama_context_params_get_n_threads(VALUE self) {
656
667
  struct llama_context_params* data = get_llama_context_params(self);
657
668
  return INT2NUM(data->n_threads);
@@ -674,6 +685,17 @@ static VALUE llama_context_params_set_n_threads_batch(VALUE self, VALUE n_thread
674
685
  return n_threads_batch;
675
686
  }
676
687
 
688
+ static VALUE llama_context_params_get_ctx_type(VALUE self) {
689
+ struct llama_context_params* data = get_llama_context_params(self);
690
+ return INT2NUM(data->ctx_type);
691
+ }
692
+
693
+ static VALUE llama_context_params_set_ctx_type(VALUE self, VALUE ctx_type) {
694
+ struct llama_context_params* data = get_llama_context_params(self);
695
+ data->ctx_type = (enum llama_context_type)NUM2INT(ctx_type);
696
+ return ctx_type;
697
+ }
698
+
677
699
  static VALUE llama_context_params_get_rope_scaling_type(VALUE self) {
678
700
  struct llama_context_params* data = get_llama_context_params(self);
679
701
  return INT2NUM(data->rope_scaling_type);
@@ -1602,6 +1624,20 @@ static VALUE rb_llama_n_seq_max(VALUE self, VALUE ctx) {
1602
1624
  return UINT2NUM(llama_n_seq_max(context_wrapper->context));
1603
1625
  }
1604
1626
 
1627
+ /**
1628
+ * @overload llama_n_rs_seq(context)
1629
+ * @param [LlamaContext] context
1630
+ * @return [Integer]
1631
+ */
1632
+ static VALUE rb_llama_n_rs_seq(VALUE self, VALUE ctx) {
1633
+ if (!rb_obj_is_kind_of(ctx, rb_cLlamaContext)) {
1634
+ rb_raise(rb_eArgError, "ctx must be a LlamaContext");
1635
+ return Qnil;
1636
+ }
1637
+ llama_context_wrapper* context_wrapper = get_llama_context_wrapper(ctx);
1638
+ return UINT2NUM(llama_n_rs_seq(context_wrapper->context));
1639
+ }
1640
+
1605
1641
  /**
1606
1642
  * @overload llama_get_model(context)
1607
1643
  * @param [LlamaContext] context
@@ -1887,6 +1923,116 @@ static VALUE rb_llama_model_meta_key_str(VALUE self, VALUE key) {
1887
1923
  return rb_utf8_str_new_cstr(key_str);
1888
1924
  }
1889
1925
 
1926
+ /**
1927
+ * @overload llama_model_meta_val_str(model, key)
1928
+ * @param [LlamaModel] model
1929
+ * @param [String] key
1930
+ * @return [String, nil] nil if the key is not found
1931
+ */
1932
+ static VALUE rb_llama_model_meta_val_str(VALUE self, VALUE model, VALUE key) {
1933
+ if (!rb_obj_is_kind_of(model, rb_cLlamaModel)) {
1934
+ rb_raise(rb_eArgError, "model must be a LlamaModel");
1935
+ return Qnil;
1936
+ }
1937
+ if (!RB_TYPE_P(key, T_STRING)) {
1938
+ rb_raise(rb_eArgError, "key must be a String");
1939
+ return Qnil;
1940
+ }
1941
+ llama_model_wrapper* model_wrapper = get_llama_model_wrapper(model);
1942
+ const char* key_ = StringValueCStr(key);
1943
+ char stack_buf[1024];
1944
+ int32_t n = llama_model_meta_val_str(model_wrapper->model, key_, stack_buf, sizeof(stack_buf));
1945
+ if (n < 0) {
1946
+ RB_GC_GUARD(model);
1947
+ RB_GC_GUARD(key);
1948
+ return Qnil;
1949
+ }
1950
+ VALUE result;
1951
+ if ((size_t)n < sizeof(stack_buf)) {
1952
+ result = rb_utf8_str_new(stack_buf, n);
1953
+ } else {
1954
+ char* heap_buf = (char*)ruby_xmalloc((size_t)n + 1);
1955
+ llama_model_meta_val_str(model_wrapper->model, key_, heap_buf, (size_t)n + 1);
1956
+ result = rb_utf8_str_new(heap_buf, n);
1957
+ ruby_xfree(heap_buf);
1958
+ }
1959
+ RB_GC_GUARD(model);
1960
+ RB_GC_GUARD(key);
1961
+ return result;
1962
+ }
1963
+
1964
+ /**
1965
+ * @overload llama_model_meta_key_by_index(model, idx)
1966
+ * @param [LlamaModel] model
1967
+ * @param [Integer] idx
1968
+ * @return [String, nil] nil if the index is out of range
1969
+ */
1970
+ static VALUE rb_llama_model_meta_key_by_index(VALUE self, VALUE model, VALUE idx) {
1971
+ if (!rb_obj_is_kind_of(model, rb_cLlamaModel)) {
1972
+ rb_raise(rb_eArgError, "model must be a LlamaModel");
1973
+ return Qnil;
1974
+ }
1975
+ if (!RB_INTEGER_TYPE_P(idx)) {
1976
+ rb_raise(rb_eArgError, "i must be an Integer");
1977
+ return Qnil;
1978
+ }
1979
+ llama_model_wrapper* model_wrapper = get_llama_model_wrapper(model);
1980
+ int32_t idx_ = NUM2INT(idx);
1981
+ char stack_buf[1024];
1982
+ int32_t n = llama_model_meta_key_by_index(model_wrapper->model, idx_, stack_buf, sizeof(stack_buf));
1983
+ if (n < 0) {
1984
+ RB_GC_GUARD(model);
1985
+ return Qnil;
1986
+ }
1987
+ VALUE result;
1988
+ if ((size_t)n < sizeof(stack_buf)) {
1989
+ result = rb_utf8_str_new(stack_buf, n);
1990
+ } else {
1991
+ char* heap_buf = (char*)ruby_xmalloc((size_t)n + 1);
1992
+ llama_model_meta_key_by_index(model_wrapper->model, idx_, heap_buf, (size_t)n + 1);
1993
+ result = rb_utf8_str_new(heap_buf, n);
1994
+ ruby_xfree(heap_buf);
1995
+ }
1996
+ RB_GC_GUARD(model);
1997
+ return result;
1998
+ }
1999
+
2000
+ /**
2001
+ * @overload llama_model_meta_val_str_by_index(model, idx)
2002
+ * @param [LlamaModel] model
2003
+ * @param [Integer] idx
2004
+ * @return [String, nil] nil if the index is out of range
2005
+ */
2006
+ static VALUE rb_llama_model_meta_val_str_by_index(VALUE self, VALUE model, VALUE idx) {
2007
+ if (!rb_obj_is_kind_of(model, rb_cLlamaModel)) {
2008
+ rb_raise(rb_eArgError, "model must be a LlamaModel");
2009
+ return Qnil;
2010
+ }
2011
+ if (!RB_INTEGER_TYPE_P(idx)) {
2012
+ rb_raise(rb_eArgError, "i must be an Integer");
2013
+ return Qnil;
2014
+ }
2015
+ llama_model_wrapper* model_wrapper = get_llama_model_wrapper(model);
2016
+ int32_t idx_ = NUM2INT(idx);
2017
+ char stack_buf[1024];
2018
+ int32_t n = llama_model_meta_val_str_by_index(model_wrapper->model, idx_, stack_buf, sizeof(stack_buf));
2019
+ if (n < 0) {
2020
+ RB_GC_GUARD(model);
2021
+ return Qnil;
2022
+ }
2023
+ VALUE result;
2024
+ if ((size_t)n < sizeof(stack_buf)) {
2025
+ result = rb_utf8_str_new(stack_buf, n);
2026
+ } else {
2027
+ char* heap_buf = (char*)ruby_xmalloc((size_t)n + 1);
2028
+ llama_model_meta_val_str_by_index(model_wrapper->model, idx_, heap_buf, (size_t)n + 1);
2029
+ result = rb_utf8_str_new(heap_buf, n);
2030
+ ruby_xfree(heap_buf);
2031
+ }
2032
+ RB_GC_GUARD(model);
2033
+ return result;
2034
+ }
2035
+
1890
2036
  /**
1891
2037
  * @overload llama_model_desc(model)
1892
2038
  * @param [LlamaModel] model
@@ -1918,19 +2064,28 @@ static VALUE rb_llama_model_size(VALUE self, VALUE model) {
1918
2064
  return ULONG2NUM(llama_model_size(model_wrapper->model));
1919
2065
  }
1920
2066
 
1921
- /* llama_model_chat_template */
1922
- /*
1923
- static VALUE rb_llama_model_chat_template(VALUE self, VALUE model) {
2067
+ /**
2068
+ * @overload llama_model_chat_template(model, name)
2069
+ * @param [LlamaModel] model
2070
+ * @param [String, nil] name pass nil to get the default chat template
2071
+ * @return [String, nil] nil if no chat template is available
2072
+ */
2073
+ static VALUE rb_llama_model_chat_template(VALUE self, VALUE model, VALUE name) {
1924
2074
  if (!rb_obj_is_kind_of(model, rb_cLlamaModel)) {
1925
2075
  rb_raise(rb_eArgError, "model must be a LlamaModel");
1926
2076
  return Qnil;
1927
2077
  }
2078
+ if (!NIL_P(name) && !RB_TYPE_P(name, T_STRING)) {
2079
+ rb_raise(rb_eArgError, "name must be a String or nil");
2080
+ return Qnil;
2081
+ }
1928
2082
  llama_model_wrapper* model_wrapper = get_llama_model_wrapper(model);
1929
- const char* templ = llama_model_chat_template(model_wrapper->model)
2083
+ const char* name_ = NIL_P(name) ? NULL : StringValueCStr(name);
2084
+ const char* templ = llama_model_chat_template(model_wrapper->model, name_);
1930
2085
  RB_GC_GUARD(model);
1931
- return rb_utf8_str_new_cstr(templ);
2086
+ RB_GC_GUARD(name);
2087
+ return templ == NULL ? Qnil : rb_utf8_str_new_cstr(templ);
1932
2088
  }
1933
- */
1934
2089
 
1935
2090
  /**
1936
2091
  * @overload llama_model_n_params(model)
@@ -4312,6 +4467,10 @@ void Init_llama_cpp(void) {
4312
4467
  rb_define_const(rb_mLlamaCpp, "LLAMA_SPLIT_MODE_LAYER", INT2NUM(LLAMA_SPLIT_MODE_LAYER));
4313
4468
  rb_define_const(rb_mLlamaCpp, "LLAMA_SPLIT_MODE_ROW", INT2NUM(LLAMA_SPLIT_MODE_ROW));
4314
4469
  rb_define_const(rb_mLlamaCpp, "LLAMA_SPLIT_MODE_TENSOR", INT2NUM(LLAMA_SPLIT_MODE_TENSOR));
4470
+ /* llama_context_type */
4471
+ /* Document-const: LlamaCpp::LLAMA_CONTEXT_TYPE_DEFAULT */
4472
+ rb_define_const(rb_mLlamaCpp, "LLAMA_CONTEXT_TYPE_DEFAULT", INT2NUM(LLAMA_CONTEXT_TYPE_DEFAULT));
4473
+ rb_define_const(rb_mLlamaCpp, "LLAMA_CONTEXT_TYPE_MTP", INT2NUM(LLAMA_CONTEXT_TYPE_MTP));
4315
4474
 
4316
4475
  rb_define_module_function(rb_mLlamaCpp, "llama_flash_attn_type_name", rb_llama_flash_attn_type_name, 1);
4317
4476
 
@@ -4644,6 +4803,17 @@ void Init_llama_cpp(void) {
4644
4803
  * @return [Integer]
4645
4804
  */
4646
4805
  rb_define_method(rb_cLlamaContextParams, "n_seq_max=", RUBY_METHOD_FUNC(llama_context_params_set_n_seq_max), 1);
4806
+ /**
4807
+ * Document-method: n_rs_seq
4808
+ * @return [Integer]
4809
+ */
4810
+ rb_define_method(rb_cLlamaContextParams, "n_rs_seq", RUBY_METHOD_FUNC(llama_context_params_get_n_rs_seq), 0);
4811
+ /**
4812
+ * Document-method: n_rs_seq=
4813
+ * @param [Integer] n_rs_seq
4814
+ * @return [Integer]
4815
+ */
4816
+ rb_define_method(rb_cLlamaContextParams, "n_rs_seq=", RUBY_METHOD_FUNC(llama_context_params_set_n_rs_seq), 1);
4647
4817
  /**
4648
4818
  * Document-method: n_threads
4649
4819
  * @return [Integer]
@@ -4666,6 +4836,17 @@ void Init_llama_cpp(void) {
4666
4836
  * @return [Integer]
4667
4837
  */
4668
4838
  rb_define_method(rb_cLlamaContextParams, "n_threads_batch=", RUBY_METHOD_FUNC(llama_context_params_set_n_threads_batch), 1);
4839
+ /**
4840
+ * Document-method: ctx_type
4841
+ * @return [Integer]
4842
+ */
4843
+ rb_define_method(rb_cLlamaContextParams, "ctx_type", RUBY_METHOD_FUNC(llama_context_params_get_ctx_type), 0);
4844
+ /**
4845
+ * Document-method: ctx_type=
4846
+ * @param [Integer] ctx_type
4847
+ * @return [Integer]
4848
+ */
4849
+ rb_define_method(rb_cLlamaContextParams, "ctx_type=", RUBY_METHOD_FUNC(llama_context_params_set_ctx_type), 1);
4669
4850
  /**
4670
4851
  * Document-method: rope_scaling_type
4671
4852
  * @return [Integer]
@@ -5186,6 +5367,9 @@ void Init_llama_cpp(void) {
5186
5367
  /* llama_n_seq_max */
5187
5368
  rb_define_module_function(rb_mLlamaCpp, "llama_n_seq_max", rb_llama_n_seq_max, 1);
5188
5369
 
5370
+ /* llama_n_rs_seq */
5371
+ rb_define_module_function(rb_mLlamaCpp, "llama_n_rs_seq", rb_llama_n_rs_seq, 1);
5372
+
5189
5373
  /* TODO: llama_get_model */
5190
5374
  rb_define_module_function(rb_mLlamaCpp, "llama_get_model", rb_llama_get_model, 1);
5191
5375
 
@@ -5244,9 +5428,12 @@ void Init_llama_cpp(void) {
5244
5428
  rb_define_module_function(rb_mLlamaCpp, "llama_model_meta_count", rb_llama_model_meta_count, 1);
5245
5429
  /* llama_model_meta_key_str */
5246
5430
  rb_define_module_function(rb_mLlamaCpp, "llama_model_meta_key_str", rb_llama_model_meta_key_str, 1);
5247
- /* TODO: llama_model_meta_val_str */
5248
- /* TODO: llama_model_meta_key_by_index */
5249
- /* TODO: llama_model_meta_val_str_by_index */
5431
+ /* llama_model_meta_val_str */
5432
+ rb_define_module_function(rb_mLlamaCpp, "llama_model_meta_val_str", rb_llama_model_meta_val_str, 2);
5433
+ /* llama_model_meta_key_by_index */
5434
+ rb_define_module_function(rb_mLlamaCpp, "llama_model_meta_key_by_index", rb_llama_model_meta_key_by_index, 2);
5435
+ /* llama_model_meta_val_str_by_index */
5436
+ rb_define_module_function(rb_mLlamaCpp, "llama_model_meta_val_str_by_index", rb_llama_model_meta_val_str_by_index, 2);
5250
5437
 
5251
5438
  /* llama_model_desc */
5252
5439
  rb_define_module_function(rb_mLlamaCpp, "llama_model_desc", rb_llama_model_desc, 1);
@@ -5254,8 +5441,8 @@ void Init_llama_cpp(void) {
5254
5441
  /* llama_model_size */
5255
5442
  rb_define_module_function(rb_mLlamaCpp, "llama_model_size", rb_llama_model_size, 1);
5256
5443
 
5257
- /* TODO: llama_model_chat_template */
5258
- /* rb_define_module_function(rb_mLlamaCpp, "llama_model_chat_template", rb_llama_model_chat_template, 1); */
5444
+ /* llama_model_chat_template */
5445
+ rb_define_module_function(rb_mLlamaCpp, "llama_model_chat_template", rb_llama_model_chat_template, 2);
5259
5446
 
5260
5447
  /* llama_model_n_params */
5261
5448
  rb_define_module_function(rb_mLlamaCpp, "llama_model_n_params", rb_llama_model_n_params, 1);
@@ -3,8 +3,8 @@
3
3
  # llama_cpp.rb provides Ruby bindings for the llama.cpp.
4
4
  module LlamaCpp
5
5
  # The version of llama_cpp.rb you install.
6
- VERSION = '0.25.2'
6
+ VERSION = '0.25.3'
7
7
 
8
8
  # The supported version of llama.cpp.
9
- LLAMA_CPP_VERSION = 'b9150'
9
+ LLAMA_CPP_VERSION = 'b9290'
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llama_cpp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.2
4
+ version: 0.25.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
@@ -33,7 +33,7 @@ metadata:
33
33
  homepage_uri: https://github.com/yoshoku/llama_cpp.rb
34
34
  source_code_uri: https://github.com/yoshoku/llama_cpp.rb
35
35
  changelog_uri: https://github.com/yoshoku/llama_cpp.rb/blob/main/CHANGELOG.md
36
- documentation_uri: https://gemdocs.org/gems/llama_cpp/0.25.2/
36
+ documentation_uri: https://gemdocs.org/gems/llama_cpp/0.25.3/
37
37
  rubygems_mfa_required: 'true'
38
38
  rdoc_options: []
39
39
  require_paths: