Skip to content

Commit 7aca30f

Browse files
committed
feat: add better file support and helper macros
1 parent 3b55fb8 commit 7aca30f

19 files changed

Lines changed: 1239 additions & 398 deletions

CONTRIBUTING.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,25 @@ We focus on being a **precision thin layer**—prioritizing raw API fidelity, re
3939

4040
This library is part of the `rain` ecosystem. To maintain consistency across clients (e.g., `ollama-client-rs`), we adhere to a shared set of interface patterns:
4141

42-
1. **Builder Pattern**: Clients should always implement `new`, `with_client`, and `with_api_url`.
43-
2. **Pinned Streams**: All streaming methods must return `Pin<Box<dyn Stream>>` to simplify caller integration.
44-
3. **Standardized Telemetry**: Use the internal `telemetry_*!` macros. Never use raw `tracing` calls directly in the client logic.
45-
4. **Error Mapping**: Maintain a flat, descriptive `GeminiError` enum using `thiserror`.
42+
1. **Macro-First DX**: Prioritize declarative request building via procedural macros (`gemini_chat!`, `gemini_parts!`).
43+
2. **Standardized Schema Generation**: All structured outputs should use the `GeminiSchema` derive macro.
44+
3. **Builder Pattern**: Clients should always implement `new`, `with_client`, and `with_api_url`.
45+
4. **Pinned Streams**: All streaming methods must return `Pin<Box<dyn Stream>>` to simplify caller integration.
46+
5. **Standardized Telemetry**: Use the internal `telemetry_*!` macros.
47+
6. **Error Mapping**: Maintain a flat, descriptive `GeminiError` enum using `thiserror`.
4648

4749
---
4850

4951
## 🛠️ Architectural Philosophy
5052

5153
When contributing to the core client, adhere to these principles:
5254

53-
1. **Thin Layer Philosophy**: The client is a transport and mapping layer. Avoid adding complex state machines, orchestration logic, or "agentic" capabilities. These belong in higher-level crates (like `rain`).
54-
2. **Transparent Proxy**: Preserving byte-for-byte fidelity and API structure is a priority. Avoid abstractions that hide underlying API features.
55-
3. **Rust Type Safety**: Leverage Rust's type system to make API constraints (like `TaskType` or `FinishReason`) explicit and compile-time safe.
56-
4. **Zero-Overhead Abstractions**: Ensure the mapping from request structs to JSON is efficient and follows the public API documentation precisely.
55+
1. **Thin Layer Foundation**: The core client is a transport and mapping layer. Avoid adding complex state machines or orchestration logic.
56+
2. **Ergonomic Macro Overlay**: Provide a best-in-class developer experience via macros that simplify common tasks (e.g., chat construction, tool declaration).
57+
3. **Transparent Proxy**: Preserving byte-for-byte fidelity and API structure in the core types is a priority.
58+
4. **Rust Type Safety**: Leverage Rust's type system to make API constraints explicit and compile-time safe.
59+
5. **Zero-Overhead Abstractions**: Ensure the mapping from macros to request structs is efficient.
60+
5761

5862
---
5963

Cargo.lock

Lines changed: 78 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,12 @@
1-
[package]
2-
name = "gemini_client_rs"
3-
version = "0.9.0"
4-
edition = "2021"
5-
description = "A Rust SDK for the Google Gemini API"
6-
license = "MIT"
7-
repository = "https://github.com/Adriftdev/gemini-client"
1+
[workspace]
2+
members = [
3+
"crates/gemini-client",
4+
"crates/gemini-client-macros",
5+
]
6+
resolver = "2"
87

9-
[features]
10-
default = []
11-
tracing = ["dep:tracing"]
12-
13-
[dependencies]
14-
async-stream = { version = "0.3", default-features = false }
15-
async-trait = { version = "0.1", default-features = false }
16-
futures-util = { version = "0.3", default-features = false }
17-
reqwest = { version = "0.12", default-features = false, features = [
18-
"json",
19-
"stream",
20-
"rustls-tls"
21-
] }
22-
reqwest-eventsource = { version = "0.6", default-features = false }
23-
serde = { version = "1", default-features = false, features = ["derive"] }
24-
serde_json = { version = "1", default-features = false }
25-
thiserror = { version = "2", default-features = false }
26-
tokio = { version = "1", default-features = false, features = [
27-
"macros",
28-
"rt-multi-thread",
29-
] }
30-
tracing = { version = "0.1", default-features = false, optional = true }
31-
32-
[dev-dependencies]
33-
dotenvy = "0.15"
34-
tracing-subscriber = { version = "0.3", default-features = false, features = [
35-
"fmt",
36-
"registry",
37-
] }
8+
[profile.release]
9+
opt-level = 3
10+
lto = true
11+
codegen-units = 1
12+
strip = true

README.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,27 @@ This crate does not own orchestration, planning, retrieval, or tool-loop executi
1515
## Basic usage
1616

1717
```rust
18-
use gemini_client_rs::{
19-
types::{Content, ContentPart, GenerateContentRequest},
20-
GeminiClient,
21-
};
18+
use gemini_client_rs::{gemini_chat, GeminiClient};
2219

2320
#[tokio::main]
2421
async fn main() -> Result<(), Box<dyn std::error::Error>> {
2522
let client = GeminiClient::default();
23+
24+
// Use the declarative gemini_chat! macro for elegant request building
25+
let req = gemini_chat!(
26+
user("Summarize this project in two sentences.")
27+
);
28+
2629
let response = client
27-
.generate_content(
28-
"gemini-2.5-flash",
29-
&GenerateContentRequest {
30-
contents: vec![Content {
31-
role: None,
32-
parts: vec![ContentPart::new_text("Summarize this project in two sentences.", false)],
33-
}],
34-
..Default::default()
35-
},
36-
)
30+
.generate_content("gemini-2.0-flash", &req)
3731
.await?;
3832

3933
println!("{response:#?}");
4034
Ok(())
4135
}
4236
```
4337

38+
4439
## Position in the stack
4540

4641
- Use `gemini_client_rs` when you want a low-level SDK for Gemini.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "gemini_client_macros"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Procedural macros for the gemini-client-rs crate"
6+
license = "MIT"
7+
8+
[lib]
9+
proc-macro = true
10+
11+
[dependencies]
12+
proc-macro2 = "1.0"
13+
quote = "1.0"
14+
syn = { version = "2.0", features = ["full", "extra-traits"] }
15+
darling = "0.20" # Helper for parsing proc-macro attributes

0 commit comments

Comments
 (0)