liter_llm 1.5.0 → 1.6.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.
@@ -1,5 +1,5 @@
1
1
  // This file is auto-generated by alef. DO NOT EDIT.
2
- // alef:hash:93a82f0d43d1c6af3f54574908a88a952d597f9e2cca238de810ede5a8948e48
2
+ // alef:hash:0c694843abf5c6a9fc8b410dfa73aea7c94ee538a40dc746dd72c50e7c986f97
3
3
  // Re-generate with: alef generate
4
4
  #![allow(dead_code, unused_imports, unused_variables)]
5
5
  #![allow(
@@ -21,6 +21,7 @@
21
21
 
22
22
  use futures::StreamExt as _;
23
23
  use liter_llm::client::BatchClient;
24
+ use liter_llm::client::BatchRetriever;
24
25
  use liter_llm::client::FileClient;
25
26
  use liter_llm::client::LlmClient;
26
27
  use liter_llm::client::ResponseClient;
@@ -6256,6 +6257,92 @@ impl ResponseUsage {
6256
6257
  }
6257
6258
  }
6258
6259
 
6260
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
6261
+ #[serde(default)]
6262
+ #[magnus::wrap(class = "LiterLlm::WaitForBatchConfig")]
6263
+ pub struct WaitForBatchConfig {
6264
+ initial_interval_secs: f64,
6265
+ max_interval_secs: f64,
6266
+ backoff_multiplier: f32,
6267
+ timeout_secs: Option<f64>,
6268
+ }
6269
+
6270
+ unsafe impl IntoValueFromNative for WaitForBatchConfig {}
6271
+
6272
+ impl magnus::TryConvert for WaitForBatchConfig {
6273
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
6274
+ if let Ok(r) = <&WaitForBatchConfig as magnus::TryConvert>::try_convert(val) {
6275
+ return Ok(r.clone());
6276
+ }
6277
+ let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
6278
+ s
6279
+ } else {
6280
+ val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
6281
+ magnus::Error::new(
6282
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
6283
+ format!("no implicit conversion into WaitForBatchConfig: {}", e),
6284
+ )
6285
+ })?
6286
+ };
6287
+ serde_json::from_str::<WaitForBatchConfig>(&json_str).map_err(|e| {
6288
+ magnus::Error::new(
6289
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
6290
+ format!("failed to deserialize WaitForBatchConfig: {}", e),
6291
+ )
6292
+ })
6293
+ }
6294
+ }
6295
+
6296
+ unsafe impl TryConvertOwned for WaitForBatchConfig {}
6297
+
6298
+ impl Default for WaitForBatchConfig {
6299
+ fn default() -> Self {
6300
+ liter_llm::client::WaitForBatchConfig::default().into()
6301
+ }
6302
+ }
6303
+
6304
+ impl WaitForBatchConfig {
6305
+ fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
6306
+ let ruby = unsafe { magnus::Ruby::get_unchecked() };
6307
+ let args = magnus::scan_args::scan_args::<(), (Option<magnus::RHash>,), (), (), (), ()>(args)?;
6308
+ let (kwargs_opt,) = args.optional;
6309
+ let kwargs = kwargs_opt.unwrap_or_else(|| ruby.hash_new());
6310
+ Ok(Self {
6311
+ initial_interval_secs: kwargs
6312
+ .get(ruby.to_symbol("initial_interval_secs"))
6313
+ .and_then(|v| f64::try_convert(v).ok())
6314
+ .unwrap_or(5.0),
6315
+ max_interval_secs: kwargs
6316
+ .get(ruby.to_symbol("max_interval_secs"))
6317
+ .and_then(|v| f64::try_convert(v).ok())
6318
+ .unwrap_or(60.0),
6319
+ backoff_multiplier: kwargs
6320
+ .get(ruby.to_symbol("backoff_multiplier"))
6321
+ .and_then(|v| f32::try_convert(v).ok())
6322
+ .unwrap_or(1.5),
6323
+ timeout_secs: kwargs
6324
+ .get(ruby.to_symbol("timeout_secs"))
6325
+ .and_then(|v| f64::try_convert(v).ok()),
6326
+ })
6327
+ }
6328
+
6329
+ fn initial_interval_secs(&self) -> f64 {
6330
+ self.initial_interval_secs
6331
+ }
6332
+
6333
+ fn max_interval_secs(&self) -> f64 {
6334
+ self.max_interval_secs
6335
+ }
6336
+
6337
+ fn backoff_multiplier(&self) -> f32 {
6338
+ self.backoff_multiplier
6339
+ }
6340
+
6341
+ fn timeout_secs(&self) -> Option<f64> {
6342
+ self.timeout_secs
6343
+ }
6344
+ }
6345
+
6259
6346
  #[derive(Clone)]
6260
6347
  #[magnus::wrap(class = "LiterLlm::DefaultClient")]
6261
6348
  pub struct DefaultClient {
@@ -6613,6 +6700,44 @@ impl DefaultClient {
6613
6700
  Ok(result.into())
6614
6701
  }
6615
6702
 
6703
+ fn fetch_batch_for_polling_async(&self, batch_id: String) -> Result<BatchObject, Error> {
6704
+ let inner = self.inner.clone();
6705
+ let rt = tokio::runtime::Runtime::new().map_err(|e| {
6706
+ magnus::Error::new(
6707
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
6708
+ e.to_string(),
6709
+ )
6710
+ })?;
6711
+ let result = rt
6712
+ .block_on(async { inner.fetch_batch_for_polling(&batch_id).await })
6713
+ .map_err(|e| {
6714
+ magnus::Error::new(
6715
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
6716
+ e.to_string(),
6717
+ )
6718
+ })?;
6719
+ Ok(result.into())
6720
+ }
6721
+
6722
+ fn wait_for_batch_async(&self, batch_id: String, config: WaitForBatchConfig) -> Result<BatchObject, Error> {
6723
+ let inner = self.inner.clone();
6724
+ let rt = tokio::runtime::Runtime::new().map_err(|e| {
6725
+ magnus::Error::new(
6726
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
6727
+ e.to_string(),
6728
+ )
6729
+ })?;
6730
+ let result = rt
6731
+ .block_on(async { inner.wait_for_batch(&batch_id, config.into()).await })
6732
+ .map_err(|e| {
6733
+ magnus::Error::new(
6734
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
6735
+ e.to_string(),
6736
+ )
6737
+ })?;
6738
+ Ok(result.into())
6739
+ }
6740
+
6616
6741
  fn create_response_async(&self, req: CreateResponseRequest) -> Result<ResponseObject, Error> {
6617
6742
  let inner = self.inner.clone();
6618
6743
  let rt = tokio::runtime::Runtime::new().map_err(|e| {
@@ -6794,6 +6919,120 @@ impl CustomProviderConfig {
6794
6919
  }
6795
6920
  }
6796
6921
 
6922
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
6923
+ #[serde(default)]
6924
+ #[magnus::wrap(class = "LiterLlm::ProviderCapabilities")]
6925
+ pub struct ProviderCapabilities {
6926
+ vision: bool,
6927
+ reasoning: bool,
6928
+ structured_output: bool,
6929
+ function_calling: bool,
6930
+ audio_in: bool,
6931
+ audio_out: bool,
6932
+ video_in: bool,
6933
+ }
6934
+
6935
+ unsafe impl IntoValueFromNative for ProviderCapabilities {}
6936
+
6937
+ impl magnus::TryConvert for ProviderCapabilities {
6938
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
6939
+ if let Ok(r) = <&ProviderCapabilities as magnus::TryConvert>::try_convert(val) {
6940
+ return Ok(r.clone());
6941
+ }
6942
+ let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
6943
+ s
6944
+ } else {
6945
+ val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
6946
+ magnus::Error::new(
6947
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
6948
+ format!("no implicit conversion into ProviderCapabilities: {}", e),
6949
+ )
6950
+ })?
6951
+ };
6952
+ serde_json::from_str::<ProviderCapabilities>(&json_str).map_err(|e| {
6953
+ magnus::Error::new(
6954
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
6955
+ format!("failed to deserialize ProviderCapabilities: {}", e),
6956
+ )
6957
+ })
6958
+ }
6959
+ }
6960
+
6961
+ unsafe impl TryConvertOwned for ProviderCapabilities {}
6962
+
6963
+ impl Default for ProviderCapabilities {
6964
+ fn default() -> Self {
6965
+ liter_llm::provider::ProviderCapabilities::default().into()
6966
+ }
6967
+ }
6968
+
6969
+ impl ProviderCapabilities {
6970
+ fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
6971
+ let ruby = unsafe { magnus::Ruby::get_unchecked() };
6972
+ let args = magnus::scan_args::scan_args::<(), (Option<magnus::RHash>,), (), (), (), ()>(args)?;
6973
+ let (kwargs_opt,) = args.optional;
6974
+ let kwargs = kwargs_opt.unwrap_or_else(|| ruby.hash_new());
6975
+ Ok(Self {
6976
+ vision: kwargs
6977
+ .get(ruby.to_symbol("vision"))
6978
+ .and_then(|v| bool::try_convert(v).ok())
6979
+ .unwrap_or_default(),
6980
+ reasoning: kwargs
6981
+ .get(ruby.to_symbol("reasoning"))
6982
+ .and_then(|v| bool::try_convert(v).ok())
6983
+ .unwrap_or_default(),
6984
+ structured_output: kwargs
6985
+ .get(ruby.to_symbol("structured_output"))
6986
+ .and_then(|v| bool::try_convert(v).ok())
6987
+ .unwrap_or_default(),
6988
+ function_calling: kwargs
6989
+ .get(ruby.to_symbol("function_calling"))
6990
+ .and_then(|v| bool::try_convert(v).ok())
6991
+ .unwrap_or_default(),
6992
+ audio_in: kwargs
6993
+ .get(ruby.to_symbol("audio_in"))
6994
+ .and_then(|v| bool::try_convert(v).ok())
6995
+ .unwrap_or_default(),
6996
+ audio_out: kwargs
6997
+ .get(ruby.to_symbol("audio_out"))
6998
+ .and_then(|v| bool::try_convert(v).ok())
6999
+ .unwrap_or_default(),
7000
+ video_in: kwargs
7001
+ .get(ruby.to_symbol("video_in"))
7002
+ .and_then(|v| bool::try_convert(v).ok())
7003
+ .unwrap_or_default(),
7004
+ })
7005
+ }
7006
+
7007
+ fn vision(&self) -> bool {
7008
+ self.vision
7009
+ }
7010
+
7011
+ fn reasoning(&self) -> bool {
7012
+ self.reasoning
7013
+ }
7014
+
7015
+ fn structured_output(&self) -> bool {
7016
+ self.structured_output
7017
+ }
7018
+
7019
+ fn function_calling(&self) -> bool {
7020
+ self.function_calling
7021
+ }
7022
+
7023
+ fn audio_in(&self) -> bool {
7024
+ self.audio_in
7025
+ }
7026
+
7027
+ fn audio_out(&self) -> bool {
7028
+ self.audio_out
7029
+ }
7030
+
7031
+ fn video_in(&self) -> bool {
7032
+ self.video_in
7033
+ }
7034
+ }
7035
+
6797
7036
  #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
6798
7037
  #[magnus::wrap(class = "LiterLlm::ProviderConfig")]
6799
7038
  pub struct ProviderConfig {
@@ -7042,6 +7281,25 @@ impl BudgetConfig {
7042
7281
  }
7043
7282
  }
7044
7283
 
7284
+ #[derive(Clone)]
7285
+ #[magnus::wrap(class = "LiterLlm::SingleflightResult")]
7286
+ pub struct SingleflightResult {
7287
+ inner: Arc<liter_llm::tower::SingleflightResult>,
7288
+ }
7289
+
7290
+ unsafe impl IntoValueFromNative for SingleflightResult {}
7291
+
7292
+ impl magnus::TryConvert for SingleflightResult {
7293
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
7294
+ let r: &SingleflightResult = magnus::TryConvert::try_convert(val)?;
7295
+ Ok(r.clone())
7296
+ }
7297
+ }
7298
+
7299
+ unsafe impl TryConvertOwned for SingleflightResult {}
7300
+
7301
+ impl SingleflightResult {}
7302
+
7045
7303
  #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
7046
7304
  #[serde(default)]
7047
7305
  #[magnus::wrap(class = "LiterLlm::RateLimitConfig")]
@@ -7114,6 +7372,77 @@ impl RateLimitConfig {
7114
7372
  }
7115
7373
  }
7116
7374
 
7375
+ #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
7376
+ #[magnus::wrap(class = "LiterLlm::IntentPrototype")]
7377
+ pub struct IntentPrototype {
7378
+ name: String,
7379
+ embedding: Vec<f64>,
7380
+ model: String,
7381
+ }
7382
+
7383
+ unsafe impl IntoValueFromNative for IntentPrototype {}
7384
+
7385
+ impl magnus::TryConvert for IntentPrototype {
7386
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
7387
+ if let Ok(r) = <&IntentPrototype as magnus::TryConvert>::try_convert(val) {
7388
+ return Ok(r.clone());
7389
+ }
7390
+ let json_str: String = if let Ok(s) = <String as magnus::TryConvert>::try_convert(val) {
7391
+ s
7392
+ } else {
7393
+ val.funcall::<_, _, String>("to_json", ()).map_err(|e| {
7394
+ magnus::Error::new(
7395
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
7396
+ format!("no implicit conversion into IntentPrototype: {}", e),
7397
+ )
7398
+ })?
7399
+ };
7400
+ serde_json::from_str::<IntentPrototype>(&json_str).map_err(|e| {
7401
+ magnus::Error::new(
7402
+ unsafe { magnus::Ruby::get_unchecked() }.exception_type_error(),
7403
+ format!("failed to deserialize IntentPrototype: {}", e),
7404
+ )
7405
+ })
7406
+ }
7407
+ }
7408
+
7409
+ unsafe impl TryConvertOwned for IntentPrototype {}
7410
+
7411
+ impl IntentPrototype {
7412
+ fn new(args: &[magnus::Value]) -> Result<Self, magnus::Error> {
7413
+ let ruby = unsafe { magnus::Ruby::get_unchecked() };
7414
+ let args = magnus::scan_args::scan_args::<(), (Option<magnus::RHash>,), (), (), (), ()>(args)?;
7415
+ let (kwargs_opt,) = args.optional;
7416
+ let kwargs = kwargs_opt.unwrap_or_else(|| ruby.hash_new());
7417
+ Ok(Self {
7418
+ name: kwargs
7419
+ .get(ruby.to_symbol("name"))
7420
+ .and_then(|v| String::try_convert(v).ok())
7421
+ .unwrap_or_default(),
7422
+ embedding: kwargs
7423
+ .get(ruby.to_symbol("embedding"))
7424
+ .and_then(|v| <Vec<f64>>::try_convert(v).ok())
7425
+ .unwrap_or_default(),
7426
+ model: kwargs
7427
+ .get(ruby.to_symbol("model"))
7428
+ .and_then(|v| String::try_convert(v).ok())
7429
+ .unwrap_or_default(),
7430
+ })
7431
+ }
7432
+
7433
+ fn name(&self) -> String {
7434
+ self.name.clone()
7435
+ }
7436
+
7437
+ fn embedding(&self) -> Vec<f64> {
7438
+ self.embedding.clone()
7439
+ }
7440
+
7441
+ fn model(&self) -> String {
7442
+ self.model.clone()
7443
+ }
7444
+ }
7445
+
7117
7446
  #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
7118
7447
  #[serde(tag = "role")]
7119
7448
  pub enum Message {
@@ -8165,6 +8494,48 @@ impl magnus::TryConvert for AuthHeaderFormat {
8165
8494
  unsafe impl IntoValueFromNative for AuthHeaderFormat {}
8166
8495
  unsafe impl TryConvertOwned for AuthHeaderFormat {}
8167
8496
 
8497
+ #[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
8498
+ #[serde(rename_all = "snake_case")]
8499
+ pub enum StreamFormat {
8500
+ Sse,
8501
+ AwsEventStream,
8502
+ }
8503
+
8504
+ impl Default for StreamFormat {
8505
+ fn default() -> Self {
8506
+ Self::Sse
8507
+ }
8508
+ }
8509
+
8510
+ impl magnus::IntoValue for StreamFormat {
8511
+ fn into_value_with(self, handle: &Ruby) -> magnus::Value {
8512
+ let sym = match self {
8513
+ StreamFormat::Sse => "sse",
8514
+ StreamFormat::AwsEventStream => "aws_event_stream",
8515
+ };
8516
+ handle.to_symbol(sym).into_value_with(handle)
8517
+ }
8518
+ }
8519
+
8520
+ impl magnus::TryConvert for StreamFormat {
8521
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
8522
+ let s: String = magnus::TryConvert::try_convert(val)?;
8523
+ // Accept the serde wire name (snake_case), the PascalCase Rust variant name,
8524
+ // and a lowercase fallback so fixtures written in any of those styles work.
8525
+ match s.as_str() {
8526
+ "sse" | "Sse" => Ok(StreamFormat::Sse),
8527
+ "aws_event_stream" | "AwsEventStream" => Ok(StreamFormat::AwsEventStream),
8528
+ other => Err(magnus::Error::new(
8529
+ unsafe { Ruby::get_unchecked() }.exception_arg_error(),
8530
+ format!("invalid StreamFormat value: {other}"),
8531
+ )),
8532
+ }
8533
+ }
8534
+ }
8535
+
8536
+ unsafe impl IntoValueFromNative for StreamFormat {}
8537
+ unsafe impl TryConvertOwned for StreamFormat {}
8538
+
8168
8539
  #[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
8169
8540
  #[serde(rename_all = "kebab-case")]
8170
8541
  pub enum AuthType {
@@ -8254,6 +8625,91 @@ impl magnus::TryConvert for Enforcement {
8254
8625
  unsafe impl IntoValueFromNative for Enforcement {}
8255
8626
  unsafe impl TryConvertOwned for Enforcement {}
8256
8627
 
8628
+ #[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
8629
+ pub enum CircuitState {
8630
+ Closed,
8631
+ Open,
8632
+ HalfOpen,
8633
+ }
8634
+
8635
+ impl Default for CircuitState {
8636
+ fn default() -> Self {
8637
+ Self::Closed
8638
+ }
8639
+ }
8640
+
8641
+ impl magnus::IntoValue for CircuitState {
8642
+ fn into_value_with(self, handle: &Ruby) -> magnus::Value {
8643
+ let sym = match self {
8644
+ CircuitState::Closed => "closed",
8645
+ CircuitState::Open => "open",
8646
+ CircuitState::HalfOpen => "half_open",
8647
+ };
8648
+ handle.to_symbol(sym).into_value_with(handle)
8649
+ }
8650
+ }
8651
+
8652
+ impl magnus::TryConvert for CircuitState {
8653
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
8654
+ let s: String = magnus::TryConvert::try_convert(val)?;
8655
+ // Accept the serde wire name (snake_case), the PascalCase Rust variant name,
8656
+ // and a lowercase fallback so fixtures written in any of those styles work.
8657
+ match s.as_str() {
8658
+ "closed" | "Closed" => Ok(CircuitState::Closed),
8659
+ "open" | "Open" => Ok(CircuitState::Open),
8660
+ "half_open" | "HalfOpen" => Ok(CircuitState::HalfOpen),
8661
+ other => Err(magnus::Error::new(
8662
+ unsafe { Ruby::get_unchecked() }.exception_arg_error(),
8663
+ format!("invalid CircuitState value: {other}"),
8664
+ )),
8665
+ }
8666
+ }
8667
+ }
8668
+
8669
+ unsafe impl IntoValueFromNative for CircuitState {}
8670
+ unsafe impl TryConvertOwned for CircuitState {}
8671
+
8672
+ #[derive(Clone, Copy, PartialEq, Eq, Debug, serde::Serialize, serde::Deserialize)]
8673
+ pub enum HealthStatus {
8674
+ Healthy,
8675
+ Unhealthy,
8676
+ }
8677
+
8678
+ impl Default for HealthStatus {
8679
+ fn default() -> Self {
8680
+ Self::Healthy
8681
+ }
8682
+ }
8683
+
8684
+ impl magnus::IntoValue for HealthStatus {
8685
+ fn into_value_with(self, handle: &Ruby) -> magnus::Value {
8686
+ let sym = match self {
8687
+ HealthStatus::Healthy => "healthy",
8688
+ HealthStatus::Unhealthy => "unhealthy",
8689
+ };
8690
+ handle.to_symbol(sym).into_value_with(handle)
8691
+ }
8692
+ }
8693
+
8694
+ impl magnus::TryConvert for HealthStatus {
8695
+ fn try_convert(val: magnus::Value) -> Result<Self, magnus::Error> {
8696
+ let s: String = magnus::TryConvert::try_convert(val)?;
8697
+ // Accept the serde wire name (snake_case), the PascalCase Rust variant name,
8698
+ // and a lowercase fallback so fixtures written in any of those styles work.
8699
+ match s.as_str() {
8700
+ "healthy" | "Healthy" => Ok(HealthStatus::Healthy),
8701
+ "unhealthy" | "Unhealthy" => Ok(HealthStatus::Unhealthy),
8702
+ other => Err(magnus::Error::new(
8703
+ unsafe { Ruby::get_unchecked() }.exception_arg_error(),
8704
+ format!("invalid HealthStatus value: {other}"),
8705
+ )),
8706
+ }
8707
+ }
8708
+ }
8709
+
8710
+ unsafe impl IntoValueFromNative for HealthStatus {}
8711
+ unsafe impl TryConvertOwned for HealthStatus {}
8712
+
8257
8713
  fn create_client(args: &[magnus::Value]) -> Result<DefaultClient, Error> {
8258
8714
  let args = magnus::scan_args::scan_args::<
8259
8715
  (String,),
@@ -8331,6 +8787,10 @@ fn unregister_custom_provider(name: String) -> Result<bool, Error> {
8331
8787
  Ok(result)
8332
8788
  }
8333
8789
 
8790
+ fn capabilities(provider_name: String) -> ProviderCapabilities {
8791
+ liter_llm::provider::capabilities(&provider_name).into()
8792
+ }
8793
+
8334
8794
  fn all_providers() -> Result<Vec<ProviderConfig>, Error> {
8335
8795
  let result = liter_llm::provider::all_providers().map_err(|e| {
8336
8796
  magnus::Error::new(
@@ -8364,6 +8824,10 @@ fn completion_cost_with_cache(
8364
8824
  liter_llm::completion_cost_with_cache(&model, prompt_tokens, cached_tokens, completion_tokens)
8365
8825
  }
8366
8826
 
8827
+ fn clear() -> () {
8828
+ liter_llm::guardrail::registry::clear()
8829
+ }
8830
+
8367
8831
  fn count_tokens(model: String, text: String) -> Result<usize, Error> {
8368
8832
  let result = liter_llm::count_tokens(&model, &text).map_err(|e| {
8369
8833
  magnus::Error::new(
@@ -8401,6 +8865,17 @@ fn count_request_tokens(args: &[magnus::Value]) -> Result<usize, Error> {
8401
8865
  Ok(result)
8402
8866
  }
8403
8867
 
8868
+ fn check_bound(context: String, current_len: usize, incoming: usize, limit: usize) -> Result<(), Error> {
8869
+ let result = liter_llm::util::bounds::check_bound(&context, current_len, incoming, limit).map_err(|e| {
8870
+ magnus::Error::new(
8871
+ unsafe { Ruby::get_unchecked() }.exception_runtime_error(),
8872
+ e.to_string(),
8873
+ )
8874
+ })?;
8875
+ Ok(result)
8876
+ }
8877
+
8878
+ #[cfg(all(feature = "native-http", not(target_os = "windows")))]
8404
8879
  fn ensure_crypto_provider() -> () {
8405
8880
  liter_llm::ensure_crypto_provider()
8406
8881
  }
@@ -10053,6 +10528,30 @@ impl From<liter_llm::types::ResponseUsage> for ResponseUsage {
10053
10528
  }
10054
10529
  }
10055
10530
 
10531
+ #[allow(clippy::redundant_closure, clippy::useless_conversion)]
10532
+ impl From<WaitForBatchConfig> for liter_llm::client::WaitForBatchConfig {
10533
+ fn from(val: WaitForBatchConfig) -> Self {
10534
+ Self {
10535
+ initial_interval_secs: val.initial_interval_secs,
10536
+ max_interval_secs: val.max_interval_secs,
10537
+ backoff_multiplier: val.backoff_multiplier,
10538
+ timeout_secs: val.timeout_secs,
10539
+ }
10540
+ }
10541
+ }
10542
+
10543
+ #[allow(clippy::redundant_closure, clippy::useless_conversion)]
10544
+ impl From<liter_llm::client::WaitForBatchConfig> for WaitForBatchConfig {
10545
+ fn from(val: liter_llm::client::WaitForBatchConfig) -> Self {
10546
+ Self {
10547
+ initial_interval_secs: val.initial_interval_secs,
10548
+ max_interval_secs: val.max_interval_secs,
10549
+ backoff_multiplier: val.backoff_multiplier,
10550
+ timeout_secs: val.timeout_secs,
10551
+ }
10552
+ }
10553
+ }
10554
+
10056
10555
  #[allow(clippy::redundant_closure, clippy::useless_conversion)]
10057
10556
  impl From<CustomProviderConfig> for liter_llm::provider::custom::CustomProviderConfig {
10058
10557
  fn from(val: CustomProviderConfig) -> Self {
@@ -10077,6 +10576,36 @@ impl From<liter_llm::provider::custom::CustomProviderConfig> for CustomProviderC
10077
10576
  }
10078
10577
  }
10079
10578
 
10579
+ #[allow(clippy::redundant_closure, clippy::useless_conversion)]
10580
+ impl From<ProviderCapabilities> for liter_llm::provider::ProviderCapabilities {
10581
+ fn from(val: ProviderCapabilities) -> Self {
10582
+ Self {
10583
+ vision: val.vision,
10584
+ reasoning: val.reasoning,
10585
+ structured_output: val.structured_output,
10586
+ function_calling: val.function_calling,
10587
+ audio_in: val.audio_in,
10588
+ audio_out: val.audio_out,
10589
+ video_in: val.video_in,
10590
+ }
10591
+ }
10592
+ }
10593
+
10594
+ #[allow(clippy::redundant_closure, clippy::useless_conversion)]
10595
+ impl From<liter_llm::provider::ProviderCapabilities> for ProviderCapabilities {
10596
+ fn from(val: liter_llm::provider::ProviderCapabilities) -> Self {
10597
+ Self {
10598
+ vision: val.vision,
10599
+ reasoning: val.reasoning,
10600
+ structured_output: val.structured_output,
10601
+ function_calling: val.function_calling,
10602
+ audio_in: val.audio_in,
10603
+ audio_out: val.audio_out,
10604
+ video_in: val.video_in,
10605
+ }
10606
+ }
10607
+ }
10608
+
10080
10609
  #[allow(clippy::redundant_closure, clippy::useless_conversion)]
10081
10610
  impl From<ProviderConfig> for liter_llm::provider::ProviderConfig {
10082
10611
  fn from(val: ProviderConfig) -> Self {
@@ -10175,6 +10704,17 @@ impl From<liter_llm::RateLimitConfig> for RateLimitConfig {
10175
10704
  }
10176
10705
  }
10177
10706
 
10707
+ #[allow(clippy::redundant_closure, clippy::useless_conversion)]
10708
+ impl From<liter_llm::tower::IntentPrototype> for IntentPrototype {
10709
+ fn from(val: liter_llm::tower::IntentPrototype) -> Self {
10710
+ Self {
10711
+ name: val.name.to_string(),
10712
+ embedding: val.embedding.into_iter().collect(),
10713
+ model: val.model.to_string(),
10714
+ }
10715
+ }
10716
+ }
10717
+
10178
10718
  impl From<Message> for liter_llm::types::Message {
10179
10719
  fn from(val: Message) -> Self {
10180
10720
  match val {
@@ -10580,6 +11120,15 @@ impl From<liter_llm::provider::custom::AuthHeaderFormat> for AuthHeaderFormat {
10580
11120
  }
10581
11121
  }
10582
11122
 
11123
+ impl From<liter_llm::provider::StreamFormat> for StreamFormat {
11124
+ fn from(val: liter_llm::provider::StreamFormat) -> Self {
11125
+ match val {
11126
+ liter_llm::provider::StreamFormat::Sse => Self::Sse,
11127
+ liter_llm::provider::StreamFormat::AwsEventStream => Self::AwsEventStream,
11128
+ }
11129
+ }
11130
+ }
11131
+
10583
11132
  impl From<AuthType> for liter_llm::provider::AuthType {
10584
11133
  fn from(val: AuthType) -> Self {
10585
11134
  match val {
@@ -10620,6 +11169,25 @@ impl From<liter_llm::Enforcement> for Enforcement {
10620
11169
  }
10621
11170
  }
10622
11171
 
11172
+ impl From<liter_llm::tower::CircuitState> for CircuitState {
11173
+ fn from(val: liter_llm::tower::CircuitState) -> Self {
11174
+ match val {
11175
+ liter_llm::tower::CircuitState::Closed => Self::Closed,
11176
+ liter_llm::tower::CircuitState::Open => Self::Open,
11177
+ liter_llm::tower::CircuitState::HalfOpen => Self::HalfOpen,
11178
+ }
11179
+ }
11180
+ }
11181
+
11182
+ impl From<liter_llm::tower::HealthStatus> for HealthStatus {
11183
+ fn from(val: liter_llm::tower::HealthStatus) -> Self {
11184
+ match val {
11185
+ liter_llm::tower::HealthStatus::Healthy => Self::Healthy,
11186
+ liter_llm::tower::HealthStatus::Unhealthy => Self::Unhealthy,
11187
+ }
11188
+ }
11189
+ }
11190
+
10623
11191
  /// Convert a `liter_llm::error::LiterLlmError` error to a Magnus runtime error.
10624
11192
  #[allow(dead_code)]
10625
11193
  fn liter_llm_error_to_magnus_err(e: liter_llm::error::LiterLlmError) -> magnus::Error {
@@ -11661,6 +12229,21 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
11661
12229
 
11662
12230
  class.define_method("total_tokens", method!(ResponseUsage::total_tokens, 0))?;
11663
12231
 
12232
+ let class = module.define_class("WaitForBatchConfig", ruby.class_object())?;
12233
+
12234
+ class.define_singleton_method("new", function!(WaitForBatchConfig::new, -1))?;
12235
+
12236
+ class.define_method(
12237
+ "initial_interval_secs",
12238
+ method!(WaitForBatchConfig::initial_interval_secs, 0),
12239
+ )?;
12240
+
12241
+ class.define_method("max_interval_secs", method!(WaitForBatchConfig::max_interval_secs, 0))?;
12242
+
12243
+ class.define_method("backoff_multiplier", method!(WaitForBatchConfig::backoff_multiplier, 0))?;
12244
+
12245
+ class.define_method("timeout_secs", method!(WaitForBatchConfig::timeout_secs, 0))?;
12246
+
11664
12247
  let class = module.define_class("DefaultClient", ruby.class_object())?;
11665
12248
 
11666
12249
  class.define_method("chat_async", method!(DefaultClient::chat_async, 1))?;
@@ -11701,6 +12284,13 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
11701
12284
 
11702
12285
  class.define_method("cancel_batch_async", method!(DefaultClient::cancel_batch_async, 1))?;
11703
12286
 
12287
+ class.define_method(
12288
+ "fetch_batch_for_polling_async",
12289
+ method!(DefaultClient::fetch_batch_for_polling_async, 1),
12290
+ )?;
12291
+
12292
+ class.define_method("wait_for_batch_async", method!(DefaultClient::wait_for_batch_async, 2))?;
12293
+
11704
12294
  class.define_method(
11705
12295
  "create_response_async",
11706
12296
  method!(DefaultClient::create_response_async, 1),
@@ -11730,6 +12320,24 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
11730
12320
 
11731
12321
  class.define_method("model_prefixes", method!(CustomProviderConfig::model_prefixes, 0))?;
11732
12322
 
12323
+ let class = module.define_class("ProviderCapabilities", ruby.class_object())?;
12324
+
12325
+ class.define_singleton_method("new", function!(ProviderCapabilities::new, -1))?;
12326
+
12327
+ class.define_method("vision", method!(ProviderCapabilities::vision, 0))?;
12328
+
12329
+ class.define_method("reasoning", method!(ProviderCapabilities::reasoning, 0))?;
12330
+
12331
+ class.define_method("structured_output", method!(ProviderCapabilities::structured_output, 0))?;
12332
+
12333
+ class.define_method("function_calling", method!(ProviderCapabilities::function_calling, 0))?;
12334
+
12335
+ class.define_method("audio_in", method!(ProviderCapabilities::audio_in, 0))?;
12336
+
12337
+ class.define_method("audio_out", method!(ProviderCapabilities::audio_out, 0))?;
12338
+
12339
+ class.define_method("video_in", method!(ProviderCapabilities::video_in, 0))?;
12340
+
11733
12341
  let class = module.define_class("ProviderConfig", ruby.class_object())?;
11734
12342
 
11735
12343
  class.define_singleton_method("new", function!(ProviderConfig::new, -1))?;
@@ -11766,6 +12374,8 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
11766
12374
 
11767
12375
  class.define_method("enforcement", method!(BudgetConfig::enforcement, 0))?;
11768
12376
 
12377
+ let class = module.define_class("SingleflightResult", ruby.class_object())?;
12378
+
11769
12379
  let class = module.define_class("RateLimitConfig", ruby.class_object())?;
11770
12380
 
11771
12381
  class.define_singleton_method("new", function!(RateLimitConfig::new, -1))?;
@@ -11776,6 +12386,16 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
11776
12386
 
11777
12387
  class.define_method("window", method!(RateLimitConfig::window, 0))?;
11778
12388
 
12389
+ let class = module.define_class("IntentPrototype", ruby.class_object())?;
12390
+
12391
+ class.define_singleton_method("new", function!(IntentPrototype::new, -1))?;
12392
+
12393
+ class.define_method("name", method!(IntentPrototype::name, 0))?;
12394
+
12395
+ class.define_method("embedding", method!(IntentPrototype::embedding, 0))?;
12396
+
12397
+ class.define_method("model", method!(IntentPrototype::model, 0))?;
12398
+
11779
12399
  let class = module.define_class("ChatStreamIterator", ruby.class_object())?;
11780
12400
  class.define_method("next_chunk", method!(ChatStreamIterator::next_chunk, 0))?;
11781
12401
  class.define_method("each", method!(ChatStreamIterator::each, 0))?;
@@ -11789,6 +12409,8 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
11789
12409
 
11790
12410
  module.define_module_function("unregister_custom_provider", function!(unregister_custom_provider, 1))?;
11791
12411
 
12412
+ module.define_module_function("capabilities", function!(capabilities, 1))?;
12413
+
11792
12414
  module.define_module_function("all_providers", function!(all_providers, 0))?;
11793
12415
 
11794
12416
  module.define_module_function("complex_provider_names", function!(complex_provider_names, 0))?;
@@ -11797,10 +12419,14 @@ fn ruby_init(ruby: &Ruby) -> Result<(), Error> {
11797
12419
 
11798
12420
  module.define_module_function("completion_cost_with_cache", function!(completion_cost_with_cache, 4))?;
11799
12421
 
12422
+ module.define_module_function("clear", function!(clear, 0))?;
12423
+
11800
12424
  module.define_module_function("count_tokens", function!(count_tokens, 2))?;
11801
12425
 
11802
12426
  module.define_module_function("count_request_tokens", function!(count_request_tokens, -1))?;
11803
12427
 
12428
+ module.define_module_function("check_bound", function!(check_bound, 4))?;
12429
+
11804
12430
  module.define_module_function("ensure_crypto_provider", function!(ensure_crypto_provider, 0))?;
11805
12431
 
11806
12432
  module.define_module_function("chat_stream", function!(chat_stream, 2))?;