rig-bailian
Rig adapter for Alibaba BaiLian (DashScope). This crate integrates BaiLian’s OpenAI‑compatible APIs into the Rig ecosystem with a consistent, strongly‑typed interface for:
- Chat completions (agents)
- Text embeddings
- Streaming responses
- Reranking
Use this adapter to swap BaiLian in and out with other providers supported by Rig with minimal code changes.
Documentation: https://docs.rs/rig-bailian
Features
- Consistent Rig API surface:
Client::from_env()andClient::builder(...).agent(model),.embeddings(model), and rerank model helpers
- Chat completion with context stacking (agents)
- Text embedding builders with
derive(Embed) - Streaming support aligned with Rig semantics
- Rerank API with top‑k selection
- Sensible defaults and environment‑based configuration
Key constants:
QWEN3_MAX: a convenience model id for chat completionsTEXT_EMBEDDING_V4: a convenience model id for embeddingsGTE_RERANK_V2: a convenience rerank model idBAILIAN_API_BASE_URL: default base URL (https://dashscope.aliyuncs.com/compatible-mode/v1)
Installation
From crates.io (recommended):
[]
= "0.1"
= "0.28.0" # Rig core
= "0.1.10" # Optional: for derive macros like Embed
From a workspace/path (if you’re developing locally):
[]
= { = "../rig-bailian" }
= "0.28.0"
= "0.1.10"
Configuration (Environment Variables)
BAILIAN_API_KEY(required): Your DashScope API key.BAILIAN_BASE_URL(optional): Override API base. Defaults to:https://dashscope.aliyuncs.com/compatible-mode/v1.
Example:
# export BAILIAN_BASE_URL="https://dashscope.aliyuncs.com/compatible-mode/v1"
Quick Start
Below are minimal snippets for chat, embeddings, and reranking.
Chat (Agent)
use Prompt;
use *;
async
Embeddings
use Embed;
use *;
use Embed;
async
Rerank
use *;
async
Examples
More end‑to‑end samples are available in the examples directory of this crate:
agent_wirh_bailian.rsbailian_embeddings.rsbailian_rereank.rs
Run from this crate directory:
# Make sure BAILIAN_API_KEY is set
Versioning and Compatibility
- Rust edition: 2024
- This crate aligns its public surface with the Rig core abstractions. Check your
rig-corecrate version for compatibility (examples userig-core = "0.28.0").
License
MIT. See the LICENSE file (or package metadata) for details.