Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions crates/llm-chain-minimax/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "llm-chain-minimax"
version = "0.13.0"
edition = "2021"
description = "Use `llm-chain` with MiniMax's LLM models (M2.7, M2.5). MiniMax provides an OpenAI-compatible API for chat completions."
license = "MIT"
keywords = ["llm", "langchain", "minimax", "chain"]
categories = ["science"]
authors = ["MiniMax Community"]
readme = "../../docs/README.md"
repository = "https://github.com/sobelio/llm-chain/"

[dependencies]
futures = "0.3.28"
async-openai = "0.16.2"
async-trait.workspace = true
llm-chain = { path = "../llm-chain", version = "0.13.0", default-features = false }
serde.workspace = true
strum = "0.24"
strum_macros = "0.24"
thiserror.workspace = true
tokio.workspace = true

[dev-dependencies]
tokio = { version = "1.28.2", features = ["macros", "rt"] }
llm-chain = { path = "../llm-chain" }
56 changes: 56 additions & 0 deletions crates/llm-chain-minimax/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# llm-chain-minimax

Use [MiniMax](https://www.minimax.io/) LLM models with `llm-chain`! This crate provides seamless integration with MiniMax's OpenAI-compatible API, giving you access to powerful models like MiniMax-M2.7 and MiniMax-M2.5.

## Supported Models

| Model | Context Window | Description |
|---|---|---|
| `MiniMax-M2.7` | 1M tokens | Latest and most capable model |
| `MiniMax-M2.7-highspeed` | 1M tokens | Faster variant of M2.7 |
| `MiniMax-M2.5` | 1M tokens | Previous generation, strong capabilities |
| `MiniMax-M2.5-highspeed` | 204K tokens | Optimized for speed |

## Quick Start

1. Get your MiniMax API key from [MiniMax Platform](https://www.minimax.io/)
2. Set the environment variable:

```bash
export MINIMAX_API_KEY="your-api-key-here"
```

3. Add dependencies to your `Cargo.toml`:

```toml
[dependencies]
llm-chain = "0.13.0"
llm-chain-minimax = "0.13.0"
```

4. Use the MiniMax executor:

```rust
use llm_chain::executor;

let exec = executor!(minimax)?;
```

Or with a specific model:

```rust
use llm_chain::{executor, options};

let exec = executor!(minimax, options!(Model: "MiniMax-M2.5-highspeed"))?;
```

## Environment Variables

| Variable | Description |
|---|---|
| `MINIMAX_API_KEY` | Your MiniMax API key (required) |
| `MINIMAX_API_BASE_URL` | Custom API base URL (default: `https://api.minimax.io/v1`) |

## Examples

See the [examples](./examples) directory for usage examples.
34 changes: 34 additions & 0 deletions crates/llm-chain-minimax/examples/simple_invocation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// This example demonstrates how to use the MiniMax executor for a simple
/// chat completion. Make sure to set the `MINIMAX_API_KEY` environment variable.
///
/// ```bash
/// export MINIMAX_API_KEY="your-api-key-here"
/// cargo run --example simple_invocation
/// ```
use llm_chain::{executor, parameters};
use llm_chain::prompt::{ConversationTemplate, StringTemplate};
use llm_chain::step::Step;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a MiniMax executor with the default model (MiniMax-M2.7)
let exec = executor!(minimax)?;

let prompt = ConversationTemplate::new()
.with_system_template("You are a helpful assistant.")
.with_user(StringTemplate::tera("{{question}}"));

let result = Step::for_prompt_template(prompt.into())
.run(&parameters!("question" => "What is the capital of France?"), &exec)
.await?;

println!(
"Response: {}",
result
.to_immediate()
.await?
.primary_textual_output()
.unwrap_or_default()
);
Ok(())
}
12 changes: 12 additions & 0 deletions crates/llm-chain-minimax/src/chatgpt/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use async_openai::error::OpenAIError;
use llm_chain::prompt::StringTemplateError;
use thiserror::Error;

#[derive(Debug, Error)]
#[error(transparent)]
pub enum MiniMaxInnerError {
#[error(transparent)]
OpenAIError(#[from] OpenAIError),
#[error(transparent)]
StringTemplateError(#[from] StringTemplateError),
}
Loading