Skip to content

a3mc/sol-summary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SolSummary

A Rust library for generating AI-powered summaries using Claude API.

Overview

SolSummary provides a simple interface to Claude AI for generating summaries and analyses.

Requirements

  • Rust 1.90 or higher
  • Claude API key from Anthropic

Installation

Add this to your Cargo.toml:

[dependencies]
solsummary = "0.0.1"

Setup

  1. Get a Claude API Key

  2. Configure the Application

    • Copy example.config.toml to config.toml:
      cp example.config.toml config.toml
    • Edit config.toml and add your API key:
      api_key = "your-actual-api-key-here"
    • You can customize the model versions and max_tokens in the config file
    • max_tokens controls the maximum length of the response (default: 4096)
  3. Build the Project

    cargo build

Usage

Basic Example

use solsummary::{ClaudeModel, SolSummary};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let summary = SolSummary::new()?;

    let result = summary.summarize(
        ClaudeModel::Sonnet,
        "Summarize the following data".to_string(),
        r#"{"key": "value"}"#.to_string(),
        None
    ).await?;

    println!("Summary: {}", result);
    Ok(())
}

Using Custom max_tokens

You can override the default max_tokens setting by passing Some(value) as the last parameter:

use solsummary::{ClaudeModel, SolSummary};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let summary = SolSummary::new()?;

    let result = summary.summarize(
        ClaudeModel::Sonnet,
        "Provide a detailed analysis".to_string(),
        r#"{"complex": "data", "requires": "longer response"}"#.to_string(),
        Some(8192)
    ).await?;

    println!("Summary: {}", result);
    Ok(())
}

Using Custom Model Strings

In addition to the predefined models (Sonnet, Opus, Haiku), you can pass raw model strings:

use solsummary::{ClaudeModel, SolSummary};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let summary = SolSummary::new()?;

    // Using the custom() helper method
    let result = summary.summarize(
        ClaudeModel::custom("claude-sonnet-4-5-20250929"),
        "Summarize the following data".to_string(),
        r#"{"key": "value"}"#.to_string(),
        None
    ).await?;

    println!("Summary: {}", result);
    Ok(())
}

Or using the Custom variant directly:

use solsummary::{ClaudeModel, SolSummary};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let summary = SolSummary::new()?;

    let result = summary.summarize(
        ClaudeModel::Custom("claude-opus-4-1-20250805".to_string()),
        "Summarize the following data".to_string(),
        r#"{"key": "value"}"#.to_string(),
        None
    ).await?;

    println!("Summary: {}", result);
    Ok(())
}

Error Handling

The library provides detailed error types based on Claude API responses:

Error Types

  • InvalidRequest - HTTP 400: Issue with request format or content
  • AuthenticationError - HTTP 401: Invalid or missing API key
  • PermissionError - HTTP 403: API key lacks required permissions
  • NotFound - HTTP 404: Requested resource not found
  • RequestTooLarge - HTTP 413 or validation: Request exceeds 30 MB limit
  • RateLimitError - HTTP 429: Rate limit exceeded
  • ApiError - HTTP 500: Internal API error
  • Overloaded - HTTP 529: API temporarily overloaded
  • InvalidApiKey - Empty API key provided
  • InvalidParameters - Empty prompt or data
  • NetworkError - Network connectivity issues
  • EnvError - Environment variable issues

Error Handling Example

use solsummary::{ClaudeModel, SolSummary, SolSummaryError};

#[tokio::main]
async fn main() {
    let summary = SolSummary::new().expect("Failed to initialize");

    match summary.summarize(
        ClaudeModel::Sonnet,
        "Summarize".to_string(),
        data.to_string(),
        None
    ).await {
        Ok(result) => println!("{}", result),
        Err(SolSummaryError::RateLimitError(msg)) => {
            eprintln!("Rate limit hit: {}", msg);
        }
        Err(SolSummaryError::AuthenticationError(msg)) => {
            eprintln!("Auth failed: {}", msg);
        }
        Err(e) => eprintln!("Error: {}", e),
    }
}

Running the Example

Default (uses config.toml)

cargo run

With Custom Config File

cargo run -- --config my_config.toml

CLI Options

# Show version
cargo run -- --version

# Show help
cargo run -- --help

After building, you can use the binary directly:

# Default config
./target/debug/solsummary

# Custom config
./target/debug/solsummary --config my_config.toml

# Show version
./target/debug/solsummary --version

Running Tests

cargo test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages