liter_llm 1.0.0.pre.rc.6

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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +239 -0
  3. data/ext/liter_llm_rb/extconf.rb +65 -0
  4. data/ext/liter_llm_rb/native/.cargo/config.toml +23 -0
  5. data/ext/liter_llm_rb/native/Cargo.lock +3713 -0
  6. data/ext/liter_llm_rb/native/Cargo.toml +32 -0
  7. data/ext/liter_llm_rb/native/build.rs +15 -0
  8. data/ext/liter_llm_rb/native/src/lib.rs +1079 -0
  9. data/lib/liter_llm.rb +8 -0
  10. data/sig/liter_llm.rbs +416 -0
  11. data/vendor/Cargo.toml +54 -0
  12. data/vendor/liter-llm/Cargo.toml +92 -0
  13. data/vendor/liter-llm/README.md +252 -0
  14. data/vendor/liter-llm/schemas/pricing.json +40 -0
  15. data/vendor/liter-llm/schemas/providers.json +1662 -0
  16. data/vendor/liter-llm/src/auth/azure_ad.rs +264 -0
  17. data/vendor/liter-llm/src/auth/bedrock_sts.rs +353 -0
  18. data/vendor/liter-llm/src/auth/mod.rs +68 -0
  19. data/vendor/liter-llm/src/auth/vertex_oauth.rs +353 -0
  20. data/vendor/liter-llm/src/client/config.rs +351 -0
  21. data/vendor/liter-llm/src/client/managed.rs +622 -0
  22. data/vendor/liter-llm/src/client/mod.rs +864 -0
  23. data/vendor/liter-llm/src/cost.rs +212 -0
  24. data/vendor/liter-llm/src/error.rs +190 -0
  25. data/vendor/liter-llm/src/http/eventstream.rs +860 -0
  26. data/vendor/liter-llm/src/http/mod.rs +12 -0
  27. data/vendor/liter-llm/src/http/request.rs +438 -0
  28. data/vendor/liter-llm/src/http/retry.rs +72 -0
  29. data/vendor/liter-llm/src/http/streaming.rs +289 -0
  30. data/vendor/liter-llm/src/lib.rs +37 -0
  31. data/vendor/liter-llm/src/provider/anthropic.rs +2250 -0
  32. data/vendor/liter-llm/src/provider/azure.rs +579 -0
  33. data/vendor/liter-llm/src/provider/bedrock.rs +1543 -0
  34. data/vendor/liter-llm/src/provider/cohere.rs +654 -0
  35. data/vendor/liter-llm/src/provider/custom.rs +404 -0
  36. data/vendor/liter-llm/src/provider/google_ai.rs +281 -0
  37. data/vendor/liter-llm/src/provider/mistral.rs +188 -0
  38. data/vendor/liter-llm/src/provider/mod.rs +616 -0
  39. data/vendor/liter-llm/src/provider/vertex.rs +1504 -0
  40. data/vendor/liter-llm/src/tests.rs +1425 -0
  41. data/vendor/liter-llm/src/tokenizer.rs +281 -0
  42. data/vendor/liter-llm/src/tower/budget.rs +599 -0
  43. data/vendor/liter-llm/src/tower/cache.rs +502 -0
  44. data/vendor/liter-llm/src/tower/cache_opendal.rs +270 -0
  45. data/vendor/liter-llm/src/tower/cooldown.rs +231 -0
  46. data/vendor/liter-llm/src/tower/cost.rs +404 -0
  47. data/vendor/liter-llm/src/tower/fallback.rs +121 -0
  48. data/vendor/liter-llm/src/tower/health.rs +219 -0
  49. data/vendor/liter-llm/src/tower/hooks.rs +369 -0
  50. data/vendor/liter-llm/src/tower/mod.rs +77 -0
  51. data/vendor/liter-llm/src/tower/rate_limit.rs +300 -0
  52. data/vendor/liter-llm/src/tower/router.rs +436 -0
  53. data/vendor/liter-llm/src/tower/service.rs +181 -0
  54. data/vendor/liter-llm/src/tower/tests.rs +539 -0
  55. data/vendor/liter-llm/src/tower/tests_common.rs +252 -0
  56. data/vendor/liter-llm/src/tower/tracing.rs +209 -0
  57. data/vendor/liter-llm/src/tower/types.rs +170 -0
  58. data/vendor/liter-llm/src/types/audio.rs +52 -0
  59. data/vendor/liter-llm/src/types/batch.rs +77 -0
  60. data/vendor/liter-llm/src/types/chat.rs +214 -0
  61. data/vendor/liter-llm/src/types/common.rs +244 -0
  62. data/vendor/liter-llm/src/types/embedding.rs +84 -0
  63. data/vendor/liter-llm/src/types/files.rs +58 -0
  64. data/vendor/liter-llm/src/types/image.rs +40 -0
  65. data/vendor/liter-llm/src/types/mod.rs +27 -0
  66. data/vendor/liter-llm/src/types/models.rs +21 -0
  67. data/vendor/liter-llm/src/types/moderation.rs +80 -0
  68. data/vendor/liter-llm/src/types/ocr.rs +87 -0
  69. data/vendor/liter-llm/src/types/rerank.rs +46 -0
  70. data/vendor/liter-llm/src/types/responses.rs +55 -0
  71. data/vendor/liter-llm/src/types/search.rs +45 -0
  72. data/vendor/liter-llm/tests/contract.rs +332 -0
  73. data/vendor/liter-llm-ffi/Cargo.toml +30 -0
  74. data/vendor/liter-llm-ffi/build.rs +66 -0
  75. data/vendor/liter-llm-ffi/cbindgen.toml +60 -0
  76. data/vendor/liter-llm-ffi/liter_llm.h +850 -0
  77. data/vendor/liter-llm-ffi/src/lib.rs +2488 -0
  78. metadata +286 -0
@@ -0,0 +1,40 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ /// Request to create images from a text prompt.
4
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5
+ #[serde(deny_unknown_fields)]
6
+ pub struct CreateImageRequest {
7
+ pub prompt: String,
8
+ #[serde(default, skip_serializing_if = "Option::is_none")]
9
+ pub model: Option<String>,
10
+ #[serde(default, skip_serializing_if = "Option::is_none")]
11
+ pub n: Option<u32>,
12
+ #[serde(default, skip_serializing_if = "Option::is_none")]
13
+ pub size: Option<String>,
14
+ #[serde(default, skip_serializing_if = "Option::is_none")]
15
+ pub quality: Option<String>,
16
+ #[serde(default, skip_serializing_if = "Option::is_none")]
17
+ pub style: Option<String>,
18
+ #[serde(default, skip_serializing_if = "Option::is_none")]
19
+ pub response_format: Option<String>,
20
+ #[serde(default, skip_serializing_if = "Option::is_none")]
21
+ pub user: Option<String>,
22
+ }
23
+
24
+ /// Response containing generated images.
25
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
26
+ pub struct ImagesResponse {
27
+ pub created: u64,
28
+ pub data: Vec<Image>,
29
+ }
30
+
31
+ /// A single generated image, returned as either a URL or base64 data.
32
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
33
+ pub struct Image {
34
+ #[serde(default, skip_serializing_if = "Option::is_none")]
35
+ pub url: Option<String>,
36
+ #[serde(default, skip_serializing_if = "Option::is_none")]
37
+ pub b64_json: Option<String>,
38
+ #[serde(default, skip_serializing_if = "Option::is_none")]
39
+ pub revised_prompt: Option<String>,
40
+ }
@@ -0,0 +1,27 @@
1
+ pub mod audio;
2
+ pub mod batch;
3
+ pub mod chat;
4
+ pub mod common;
5
+ pub mod embedding;
6
+ pub mod files;
7
+ pub mod image;
8
+ pub mod models;
9
+ pub mod moderation;
10
+ pub mod ocr;
11
+ pub mod rerank;
12
+ pub mod responses;
13
+ pub mod search;
14
+
15
+ pub use audio::*;
16
+ pub use batch::*;
17
+ pub use chat::*;
18
+ pub use common::*;
19
+ pub use embedding::*;
20
+ pub use files::*;
21
+ pub use image::*;
22
+ pub use models::*;
23
+ pub use moderation::*;
24
+ pub use ocr::*;
25
+ pub use rerank::*;
26
+ pub use responses::*;
27
+ pub use search::*;
@@ -0,0 +1,21 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ // ─── Responses ────────────────────────────────────────────────────────────────
4
+
5
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
6
+ pub struct ModelsListResponse {
7
+ /// Always `"list"` from OpenAI-compatible APIs. Stored as a plain
8
+ /// `String` so non-standard provider values do not break deserialization.
9
+ pub object: String,
10
+ pub data: Vec<ModelObject>,
11
+ }
12
+
13
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14
+ pub struct ModelObject {
15
+ pub id: String,
16
+ /// Always `"model"` from OpenAI-compatible APIs. Stored as a plain
17
+ /// `String` so non-standard provider values do not break deserialization.
18
+ pub object: String,
19
+ pub created: u64,
20
+ pub owned_by: String,
21
+ }
@@ -0,0 +1,80 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ /// Request to classify content for policy violations.
4
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5
+ #[serde(deny_unknown_fields)]
6
+ pub struct ModerationRequest {
7
+ pub input: ModerationInput,
8
+ #[serde(default, skip_serializing_if = "Option::is_none")]
9
+ pub model: Option<String>,
10
+ }
11
+
12
+ /// Input to the moderation endpoint — a single string or multiple strings.
13
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
14
+ #[serde(untagged)]
15
+ pub enum ModerationInput {
16
+ Single(String),
17
+ Multiple(Vec<String>),
18
+ }
19
+
20
+ /// Response from the moderation endpoint.
21
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
22
+ pub struct ModerationResponse {
23
+ pub id: String,
24
+ pub model: String,
25
+ pub results: Vec<ModerationResult>,
26
+ }
27
+
28
+ /// A single moderation classification result.
29
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
30
+ pub struct ModerationResult {
31
+ pub flagged: bool,
32
+ pub categories: ModerationCategories,
33
+ pub category_scores: ModerationCategoryScores,
34
+ }
35
+
36
+ /// Boolean flags for each moderation category.
37
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38
+ pub struct ModerationCategories {
39
+ pub sexual: bool,
40
+ pub hate: bool,
41
+ pub harassment: bool,
42
+ #[serde(rename = "self-harm")]
43
+ pub self_harm: bool,
44
+ #[serde(rename = "sexual/minors")]
45
+ pub sexual_minors: bool,
46
+ #[serde(rename = "hate/threatening")]
47
+ pub hate_threatening: bool,
48
+ #[serde(rename = "violence/graphic")]
49
+ pub violence_graphic: bool,
50
+ #[serde(rename = "self-harm/intent")]
51
+ pub self_harm_intent: bool,
52
+ #[serde(rename = "self-harm/instructions")]
53
+ pub self_harm_instructions: bool,
54
+ #[serde(rename = "harassment/threatening")]
55
+ pub harassment_threatening: bool,
56
+ pub violence: bool,
57
+ }
58
+
59
+ /// Confidence scores for each moderation category.
60
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
61
+ pub struct ModerationCategoryScores {
62
+ pub sexual: f64,
63
+ pub hate: f64,
64
+ pub harassment: f64,
65
+ #[serde(rename = "self-harm")]
66
+ pub self_harm: f64,
67
+ #[serde(rename = "sexual/minors")]
68
+ pub sexual_minors: f64,
69
+ #[serde(rename = "hate/threatening")]
70
+ pub hate_threatening: f64,
71
+ #[serde(rename = "violence/graphic")]
72
+ pub violence_graphic: f64,
73
+ #[serde(rename = "self-harm/intent")]
74
+ pub self_harm_intent: f64,
75
+ #[serde(rename = "self-harm/instructions")]
76
+ pub self_harm_instructions: f64,
77
+ #[serde(rename = "harassment/threatening")]
78
+ pub harassment_threatening: f64,
79
+ pub violence: f64,
80
+ }
@@ -0,0 +1,87 @@
1
+ //! Types for document OCR (optical character recognition) requests and responses.
2
+
3
+ use serde::{Deserialize, Serialize};
4
+
5
+ use super::common::Usage;
6
+
7
+ /// An OCR request.
8
+ #[derive(Debug, Clone, Serialize, Deserialize)]
9
+ #[serde(deny_unknown_fields)]
10
+ pub struct OcrRequest {
11
+ /// The model/provider to use (e.g. `"mistral/mistral-ocr-latest"`).
12
+ pub model: String,
13
+ /// The document to process.
14
+ pub document: OcrDocument,
15
+ /// Specific pages to process (1-indexed). `None` means all pages.
16
+ #[serde(default, skip_serializing_if = "Option::is_none")]
17
+ pub pages: Option<Vec<u32>>,
18
+ /// Whether to include base64-encoded images of each page.
19
+ #[serde(default, skip_serializing_if = "Option::is_none")]
20
+ pub include_image_base64: Option<bool>,
21
+ }
22
+
23
+ /// Document input for OCR — either a URL or inline base64 data.
24
+ #[derive(Debug, Clone, Serialize, Deserialize)]
25
+ #[serde(tag = "type")]
26
+ pub enum OcrDocument {
27
+ /// A publicly accessible document URL.
28
+ #[serde(rename = "document_url")]
29
+ Url {
30
+ /// The document URL.
31
+ url: String,
32
+ },
33
+ /// Inline base64-encoded document data.
34
+ #[serde(rename = "base64")]
35
+ Base64 {
36
+ /// Base64-encoded document content.
37
+ data: String,
38
+ /// MIME type (e.g. `"application/pdf"`, `"image/png"`).
39
+ media_type: String,
40
+ },
41
+ }
42
+
43
+ /// An OCR response.
44
+ #[derive(Debug, Clone, Serialize, Deserialize)]
45
+ pub struct OcrResponse {
46
+ /// Extracted pages.
47
+ pub pages: Vec<OcrPage>,
48
+ /// The model used.
49
+ pub model: String,
50
+ /// Token usage, if reported by the provider.
51
+ #[serde(default, skip_serializing_if = "Option::is_none")]
52
+ pub usage: Option<Usage>,
53
+ }
54
+
55
+ /// A single page of OCR output.
56
+ #[derive(Debug, Clone, Serialize, Deserialize)]
57
+ pub struct OcrPage {
58
+ /// Page index (0-based).
59
+ pub index: u32,
60
+ /// Extracted content as Markdown.
61
+ pub markdown: String,
62
+ /// Extracted images, if `include_image_base64` was set.
63
+ #[serde(default, skip_serializing_if = "Option::is_none")]
64
+ pub images: Option<Vec<OcrImage>>,
65
+ /// Page dimensions in pixels, if available.
66
+ #[serde(default, skip_serializing_if = "Option::is_none")]
67
+ pub dimensions: Option<PageDimensions>,
68
+ }
69
+
70
+ /// An image extracted from an OCR page.
71
+ #[derive(Debug, Clone, Serialize, Deserialize)]
72
+ pub struct OcrImage {
73
+ /// Unique image identifier.
74
+ pub id: String,
75
+ /// Base64-encoded image data.
76
+ #[serde(default, skip_serializing_if = "Option::is_none")]
77
+ pub image_base64: Option<String>,
78
+ }
79
+
80
+ /// Page dimensions in pixels.
81
+ #[derive(Debug, Clone, Serialize, Deserialize)]
82
+ pub struct PageDimensions {
83
+ /// Width in pixels.
84
+ pub width: u32,
85
+ /// Height in pixels.
86
+ pub height: u32,
87
+ }
@@ -0,0 +1,46 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ /// Request to rerank documents by relevance to a query.
4
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5
+ #[serde(deny_unknown_fields)]
6
+ pub struct RerankRequest {
7
+ pub model: String,
8
+ pub query: String,
9
+ pub documents: Vec<RerankDocument>,
10
+ #[serde(default, skip_serializing_if = "Option::is_none")]
11
+ pub top_n: Option<u32>,
12
+ #[serde(default, skip_serializing_if = "Option::is_none")]
13
+ pub return_documents: Option<bool>,
14
+ }
15
+
16
+ /// A document to be reranked — either a plain string or an object with a text field.
17
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
18
+ #[serde(untagged)]
19
+ pub enum RerankDocument {
20
+ Text(String),
21
+ Object { text: String },
22
+ }
23
+
24
+ /// Response from the rerank endpoint.
25
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
26
+ pub struct RerankResponse {
27
+ pub id: Option<String>,
28
+ pub results: Vec<RerankResult>,
29
+ #[serde(default, skip_serializing_if = "Option::is_none")]
30
+ pub meta: Option<serde_json::Value>,
31
+ }
32
+
33
+ /// A single reranked document with its relevance score.
34
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
35
+ pub struct RerankResult {
36
+ pub index: u32,
37
+ pub relevance_score: f64,
38
+ #[serde(default, skip_serializing_if = "Option::is_none")]
39
+ pub document: Option<RerankResultDocument>,
40
+ }
41
+
42
+ /// The text content of a reranked document, returned when `return_documents` is true.
43
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
44
+ pub struct RerankResultDocument {
45
+ pub text: String,
46
+ }
@@ -0,0 +1,55 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
4
+ #[serde(deny_unknown_fields)]
5
+ pub struct CreateResponseRequest {
6
+ pub model: String,
7
+ pub input: serde_json::Value,
8
+ #[serde(default, skip_serializing_if = "Option::is_none")]
9
+ pub instructions: Option<String>,
10
+ #[serde(default, skip_serializing_if = "Option::is_none")]
11
+ pub tools: Option<Vec<ResponseTool>>,
12
+ #[serde(default, skip_serializing_if = "Option::is_none")]
13
+ pub temperature: Option<f64>,
14
+ #[serde(default, skip_serializing_if = "Option::is_none")]
15
+ pub max_output_tokens: Option<u64>,
16
+ #[serde(default, skip_serializing_if = "Option::is_none")]
17
+ pub metadata: Option<serde_json::Value>,
18
+ }
19
+
20
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21
+ pub struct ResponseTool {
22
+ #[serde(rename = "type")]
23
+ pub tool_type: String,
24
+ #[serde(flatten)]
25
+ pub config: serde_json::Value,
26
+ }
27
+
28
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
29
+ pub struct ResponseObject {
30
+ pub id: String,
31
+ pub object: String,
32
+ pub created_at: u64,
33
+ pub model: String,
34
+ pub status: String,
35
+ pub output: Vec<ResponseOutputItem>,
36
+ #[serde(default, skip_serializing_if = "Option::is_none")]
37
+ pub usage: Option<ResponseUsage>,
38
+ #[serde(default, skip_serializing_if = "Option::is_none")]
39
+ pub error: Option<serde_json::Value>,
40
+ }
41
+
42
+ #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
43
+ pub struct ResponseOutputItem {
44
+ #[serde(rename = "type")]
45
+ pub item_type: String,
46
+ #[serde(flatten)]
47
+ pub content: serde_json::Value,
48
+ }
49
+
50
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
51
+ pub struct ResponseUsage {
52
+ pub input_tokens: u64,
53
+ pub output_tokens: u64,
54
+ pub total_tokens: u64,
55
+ }
@@ -0,0 +1,45 @@
1
+ //! Types for web/document search requests and responses.
2
+
3
+ use serde::{Deserialize, Serialize};
4
+
5
+ /// A search request.
6
+ #[derive(Debug, Clone, Serialize, Deserialize, Default)]
7
+ #[serde(deny_unknown_fields)]
8
+ pub struct SearchRequest {
9
+ /// The model/provider to use (e.g. `"brave/web-search"`, `"tavily/search"`).
10
+ pub model: String,
11
+ /// The search query.
12
+ pub query: String,
13
+ /// Maximum number of results to return.
14
+ #[serde(default, skip_serializing_if = "Option::is_none")]
15
+ pub max_results: Option<u32>,
16
+ /// Domain filter — restrict results to specific domains.
17
+ #[serde(default, skip_serializing_if = "Option::is_none")]
18
+ pub search_domain_filter: Option<Vec<String>>,
19
+ /// Country code for localized results (ISO 3166-1 alpha-2).
20
+ #[serde(default, skip_serializing_if = "Option::is_none")]
21
+ pub country: Option<String>,
22
+ }
23
+
24
+ /// A search response.
25
+ #[derive(Debug, Clone, Serialize, Deserialize)]
26
+ pub struct SearchResponse {
27
+ /// The search results.
28
+ pub results: Vec<SearchResult>,
29
+ /// The model used.
30
+ pub model: String,
31
+ }
32
+
33
+ /// An individual search result.
34
+ #[derive(Debug, Clone, Serialize, Deserialize)]
35
+ pub struct SearchResult {
36
+ /// Title of the result.
37
+ pub title: String,
38
+ /// URL of the result.
39
+ pub url: String,
40
+ /// Text snippet / excerpt.
41
+ pub snippet: String,
42
+ /// Publication or last-updated date, if available.
43
+ #[serde(default, skip_serializing_if = "Option::is_none")]
44
+ pub date: Option<String>,
45
+ }