rainy-sdk 0.3.0

Official Rust SDK for Rainy API by Enosis Labs v0.3.0 - Full OpenAI compatibility with unified interface for multiple AI providers, intelligent retry, metadata tracking, and comprehensive error handling
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
# ๐Ÿค Contributing to Rainy SDK


Thank you for your interest in contributing to the Rainy SDK! We welcome contributions from everyone. This document provides guidelines and information for contributors.

## ๐Ÿ“‹ Table of Contents


- [Development Setup]#development-setup
- [Development Workflow]#development-workflow
- [Coding Standards]#coding-standards
- [Testing]#testing
- [Pull Request Process]#pull-request-process
- [Issue Reporting]#issue-reporting
- [Code of Conduct]#code-of-conduct

## ๐Ÿš€ Development Setup


### Prerequisites


- **Rust**: Install the latest stable version from [rustup.rs]https://rustup.rs/
- **Git**: Version control system
- **Optional**: IDE with Rust support (VS Code with rust-analyzer, CLion, etc.)

### 1. Fork and Clone


```bash
# Fork the repository on GitHub

# Then clone your fork

git clone https://github.com/enosislabs/rainy-sdk.git
cd rainy-sdk
```

### 2. Set Up Development Environment


```bash
# Install development dependencies

cargo install cargo-edit
cargo install cargo-watch
cargo install cargo-tarpaulin  # For coverage reports

# Verify installation

cargo --version
rustc --version
```

### 3. Run Initial Setup


```bash
# Build the project

cargo build

# Run tests to ensure everything works

cargo test

# Generate documentation

cargo doc --open
```

### 4. Environment Configuration


Create a `.env` file for testing (not committed to git):

```bash
# Copy example environment file

cp .env.example .env

# Edit with your test credentials

RAINY_API_KEY=your-test-api-key
```

## ๐Ÿ”„ Development Workflow


### 1. Choose an Issue


- Check [open issues]https://github.com/enosislabs/rainy-sdk/issues for tasks
- Look for issues labeled `good first issue` or `help wanted`
- Comment on the issue to indicate you're working on it

### 2. Create a Feature Branch


```bash
# Create and switch to a feature branch

git checkout -b feature/your-feature-name

# Or for bug fixes

git checkout -b fix/issue-number-description
```

### 3. Make Changes


```bash
# Make your changes following the coding standards

# Add tests for new functionality

# Update documentation as needed


# Run tests frequently

cargo test

# Run linting

cargo clippy

# Format code

cargo fmt
```

### 4. Commit Changes


```bash
# Stage your changes

git add .

# Commit with descriptive message

git commit -m "feat: add new chat completion streaming support

- Add streaming parameter to ChatCompletionRequest
- Implement streaming response handling
- Add example for streaming usage
- Update documentation

Closes #123"
```

### 5. Commit Sign-Off


All contributions to this repository must include a Developer Certificate of Origin (DCO) sign-off. This is a lightweight way to certify that you have the right to submit the code you're contributing.

#### Why is sign-off required?


The sign-off serves several important purposes:

- **Legal compliance**: It certifies that you have the legal right to submit the code
- **Chain of custody**: It helps track who contributed what and when
- **Intellectual property**: It ensures proper attribution and licensing
- **Open source standards**: It follows industry best practices for contribution tracking

#### How to sign off your commits


**For command line users:**
Simply add the `-s` flag when committing:

```bash
git commit -s -m "Your commit message"
```

This automatically adds a sign-off line at the end of your commit message:

```
Signed-off-by: Your Name <your.email@example.com>
```

**For GitHub web interface users:**
GitHub makes this process easy by providing a sign-off option in the commit interface. When creating or editing files through GitHub's web interface, you'll see a checkbox for "Sign off and commit changes" - simply check this box before committing.

#### Verifying your sign-off


You can verify that your commits are properly signed off by checking the commit log:

```bash
git log --show-signature
```

Or to see just the sign-off lines:

```bash
git log --pretty=format:"%H %s%n%b%n" | grep "Signed-off-by"
```

### 6. Push and Create Pull Request


```bash
# Push your branch

git push origin feature/your-feature-name

# Create a Pull Request on GitHub

```

## ๐Ÿ’ป Coding Standards


### Rust Style Guidelines


We follow the official [Rust Style Guide](https://doc.rust-lang.org/style-guide/) and use `rustfmt` for formatting.

#### Code Formatting


```bash
# Format all code

cargo fmt

# Check formatting without changing files

cargo fmt --check
```

#### Linting


```bash
# Run clippy for additional linting

cargo clippy

# Fix auto-fixable issues

cargo clippy --fix
```

### Naming Conventions


- **Functions**: `snake_case`
- **Types/Structs**: `PascalCase`
- **Constants**: `SCREAMING_SNAKE_CASE`
- **Modules**: `snake_case`

### Documentation


- **Public APIs**: Must have documentation comments (`///`)
- **Complex logic**: Include inline comments explaining the "why"
- **Examples**: Provide code examples in documentation

```rust
/// Creates a new chat completion request.
///
/// # Examples
///
/// ```rust
/// use rainy_sdk::{ChatCompletionRequest, ChatMessage, ChatRole};
///
/// let request = ChatCompletionRequest::new(
///     "gpt-4",
///     vec![ChatMessage {
///         role: ChatRole::User,
///         content: "Hello!".to_string(),
///     }]
/// );
/// ```
```

### Error Handling


- Use the `RainyError` type for all public APIs
- Provide meaningful error messages
- Use `Result<T, RainyError>` for fallible operations
- Handle all `Result` values appropriately

### Async Code


- Use `async fn` for asynchronous functions
- Prefer `tokio::spawn` for concurrent tasks
- Use `async_trait` for trait methods when needed
- Handle cancellation properly with `CancellationToken`

## ๐Ÿงช Testing


### Test Structure


- **Unit tests**: Test individual functions and methods
- **Integration tests**: Test API interactions (in `tests/` directory)
- **Documentation tests**: Examples in documentation comments

### Running Tests


```bash
# Run all tests

cargo test

# Run specific test

cargo test test_name

# Run tests with output

cargo test -- --nocapture

# Run integration tests only

cargo test --test integration_test

# Generate coverage report (requires tarpaulin)

cargo tarpaulin --out Html
```

### Writing Tests


#### Unit Tests


```rust
#[cfg(test)]

mod tests {
    use super::*;

    #[test]
    fn test_chat_message_creation() {
        let message = ChatMessage {
            role: ChatRole::User,
            content: "Hello".to_string(),
        };

        assert_eq!(message.role, ChatRole::User);
        assert_eq!(message.content, "Hello");
    }

    #[tokio::test]
    async fn test_async_function() {
        let result = some_async_function().await;
        assert!(result.is_ok());
    }
}
```

#### Integration Tests


```rust
// tests/integration_test.rs
use rainy_sdk::{AuthConfig, RainyClient};

#[tokio::test]

async fn test_health_check() {
    let client = RainyClient::new(
        AuthConfig::new()
            .with_api_key(std::env::var("RAINY_API_KEY").unwrap())
    ).unwrap();

    let health = client.health_check().await.unwrap();
    assert!(matches!(health.status, HealthStatus::Healthy));
}
```

### Test Coverage


We aim for high test coverage:

- **Core functionality**: >90% coverage
- **Error handling**: Test all error paths
- **Edge cases**: Test boundary conditions
- **API compatibility**: Test against real API when possible

## ๐Ÿ“ Pull Request Process


### Before Submitting


1. **Update documentation**: Ensure README and docs reflect your changes
2. **Add tests**: Include tests for new functionality
3. **Update CHANGELOG**: Add entry for user-facing changes
4. **Run full test suite**: `cargo test && cargo clippy && cargo fmt --check`

### PR Template


Use this template when creating a Pull Request:

```markdown
## Description

Brief description of the changes made.

## Type of Change

- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
- [ ] Refactoring
- [ ] Performance improvement

## Testing

- [ ] Unit tests added/updated
- [ ] Integration tests added/updated
- [ ] Manual testing performed
- [ ] All tests pass

## Checklist

- [ ] Code follows project style guidelines
- [ ] Documentation updated
- [ ] Tests added for new functionality
- [ ] CHANGELOG updated (if applicable)
- [ ] Commit messages follow conventional commits
```

### Review Process

1. **Automated Checks**: CI will run tests, linting, and formatting checks
2. **Code Review**: At least one maintainer will review your code
3. **Approval**: PR must be approved before merging
4. **Merge**: Use "Squash and merge" for clean commit history

## ๐Ÿ› Issue Reporting

### Bug Reports

When reporting bugs, please include:

- **Clear title**: Summarize the issue
- **Description**: Detailed explanation of the problem
- **Steps to reproduce**: Step-by-step instructions
- **Expected behavior**: What should happen
- **Actual behavior**: What actually happens
- **Environment**: OS, Rust version, SDK version
- **Code sample**: Minimal code to reproduce the issue

### Feature Requests

For new features, please include:

- **Use case**: Why do you need this feature?
- **Proposed solution**: How should it work?
- **Alternatives**: Other approaches considered
- **Additional context**: Screenshots, examples, etc.

### Security Issues

- **DO NOT** report security vulnerabilities in public issues
- Email <security@enosislabs.com> instead
- Include detailed reproduction steps and potential impact

## ๐Ÿ“œ Code of Conduct

### Our Standards

We are committed to providing a welcoming and inclusive environment for all contributors. We expect all participants to:

- **Be respectful**: Treat everyone with respect and kindness
- **Be collaborative**: Work together constructively
- **Be inclusive**: Welcome people from all backgrounds
- **Be patient**: Understand that everyone has different experience levels
- **Be constructive**: Focus on solutions, not blame

### Unacceptable Behavior

- Harassment or discrimination
- Offensive comments or language
- Personal attacks
- Trolling or disruptive behavior
- Publishing private information

### Enforcement

Violations of the code of conduct may result in:

- Warning from maintainers
- Temporary ban from contributing
- Permanent ban in severe cases

## ๐Ÿ™ Recognition

Contributors will be recognized in:

- **CHANGELOG.md**: For all releases
- **README.md**: Notable contributors section
- **GitHub releases**: Contributor mentions

## ๐Ÿ“ž Getting Help

- **Documentation**: [docs.rs/rainy-sdk](https://docs.rs/rainy-sdk)
- **Discussions**: [GitHub Discussions](https://github.com/enosislabs/rainy-sdk/discussions)
- **Issues**: [GitHub Issues](https://github.com/enosislabs/rainy-sdk/issues)

Thank you for contributing to the Rainy SDK! ๐Ÿš€