LLM Kit Together AI
Together AI provider for LLM Kit - Complete integration with Together AI's extensive collection of open-source models.
Note: This provider uses the standardized builder pattern. See the Quick Start section for the recommended usage.
Features
- Text Generation: Generate text using Llama, Mistral, Qwen, DeepSeek, and more
- Streaming: Stream responses in real-time with support for tool calls
- Tool Calling: Support for function calling with chat models
- Text Embedding: Generate embeddings for semantic search and similarity
- Image Generation: Create images with FLUX and Stable Diffusion models
- Reranking: Improve search results with document reranking models
- Multiple Model Families: Access to Llama, Mistral, Qwen, DeepSeek, Gemma, and more
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= "0.1"
= "0.1"
= { = "1", = ["full"] }
Quick Start
Using the Client Builder (Recommended)
use TogetherAIClient;
use LanguageModel;
async
Using Settings Directly (Alternative)
use ;
use LanguageModel;
async
Configuration
Environment Variables
Set your Together AI API key as an environment variable:
Using the Client Builder
use TogetherAIClient;
let provider = new
.api_key
.base_url
.header
.name
.build;
Builder Methods
The TogetherAIClient builder supports:
.api_key(key)- Set the API key (overridesTOGETHER_AI_API_KEYenvironment variable).base_url(url)- Set custom base URL (default:https://api.together.xyz/v1).name(name)- Set provider name (optional).header(key, value)- Add a single custom header.headers(map)- Add multiple custom headers.load_api_key_from_env()- Explicitly load API key from environment variable.build()- Build the provider
Supported Models
Chat Models
All Together AI chat models are supported, including:
- Llama:
meta-llama/Llama-3.3-70B-Instruct-Turbo,meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo,meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo,meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo - Qwen:
Qwen/Qwen2.5-Coder-32B-Instruct,Qwen/Qwen2.5-7B-Instruct-Turbo,Qwen/Qwen2.5-72B-Instruct-Turbo - DeepSeek:
deepseek-ai/DeepSeek-V3 - Mistral:
mistralai/Mistral-7B-Instruct-v0.3,mistralai/Mixtral-8x7B-Instruct-v0.1,mistralai/Mixtral-8x22B-Instruct-v0.1 - Gemma:
google/gemma-2-9b-it,google/gemma-2-27b-it
Embedding Models
- WhereIsAI:
WhereIsAI/UAE-Large-V1 - BAAI:
BAAI/bge-large-en-v1.5,BAAI/bge-base-en-v1.5 - Sentence Transformers:
sentence-transformers/msmarco-bert-base-dot-v5
Image Models
- FLUX:
black-forest-labs/FLUX.1-schnell,black-forest-labs/FLUX.1-dev,black-forest-labs/FLUX.1.1-pro - Stable Diffusion:
stabilityai/stable-diffusion-xl-base-1.0,stabilityai/stable-diffusion-2-1
Reranking Models
- Salesforce:
Salesforce/Llama-Rank-v1 - Mixedbread:
mixedbread-ai/Mxbai-Rerank-Large-V2
For a complete list of available models, see the Together AI Models documentation.
Provider-Specific Options
Chained Model Creation
Together AI provider supports convenient chained model creation:
use TogetherAIClient;
// Create model directly from builder
let model = new
.api_key
.build
.chat_model;
Multiple Model Types
Together AI supports multiple model types in a single provider:
use TogetherAIClient;
let provider = new
.api_key
.build;
// Chat models
let chat_model = provider.chat_model;
// Embedding models
let embedding_model = provider.text_embedding_model;
// Image models
let image_model = provider.image_model;
// Reranking models
let reranking_model = provider.reranking_model;
Examples
See the examples/ directory for complete examples:
chat.rs- Basic chat completionstream.rs- Streaming responseschat_tool_calling.rs- Tool calling with function definitionsstream_tool_calling.rs- Streaming with tool callstext_embedding.rs- Text embeddings for semantic searchimage_generation.rs- Image generation with FLUX and Stable Diffusionreranking.rs- Document reranking for improved search
Run examples with:
Documentation
License
Apache-2.0
Contributing
Contributions are welcome! Please see the Contributing Guide for more details.