|
| 1 | +import Tabs from '@theme/Tabs'; |
| 2 | +import TabItem from '@theme/TabItem'; |
| 3 | + |
| 4 | +# CompactifAI |
| 5 | +https://docs.compactif.ai/ |
| 6 | + |
| 7 | +CompactifAI offers highly compressed versions of leading language models, delivering up to **70% lower inference costs**, **4x throughput gains**, and **low-latency inference** with minimal quality loss (<5%). CompactifAI's OpenAI-compatible API makes integration straightforward, enabling developers to build ultra-efficient, scalable AI applications with superior concurrency and resource efficiency. |
| 8 | + |
| 9 | +| Property | Details | |
| 10 | +|-------|-------| |
| 11 | +| Description | CompactifAI offers compressed versions of leading language models with up to 70% cost reduction and 4x throughput gains | |
| 12 | +| Provider Route on LiteLLM | `compactifai/` (add this prefix to the model name - e.g. `compactifai/cai-llama-3-1-8b-slim`) | |
| 13 | +| Provider Doc | [CompactifAI ↗](https://docs.compactif.ai/) | |
| 14 | +| API Endpoint for Provider | https://api.compactif.ai/v1 | |
| 15 | +| Supported Endpoints | `/chat/completions`, `/completions` | |
| 16 | + |
| 17 | +## Supported OpenAI Parameters |
| 18 | + |
| 19 | +CompactifAI is fully OpenAI-compatible and supports the following parameters: |
| 20 | + |
| 21 | +``` |
| 22 | +"stream", |
| 23 | +"stop", |
| 24 | +"temperature", |
| 25 | +"top_p", |
| 26 | +"max_tokens", |
| 27 | +"presence_penalty", |
| 28 | +"frequency_penalty", |
| 29 | +"logit_bias", |
| 30 | +"user", |
| 31 | +"response_format", |
| 32 | +"seed", |
| 33 | +"tools", |
| 34 | +"tool_choice", |
| 35 | +"parallel_tool_calls", |
| 36 | +"extra_headers" |
| 37 | +``` |
| 38 | + |
| 39 | +## API Key Setup |
| 40 | + |
| 41 | +CompactifAI API keys are available through AWS Marketplace subscription: |
| 42 | + |
| 43 | +1. Subscribe via [AWS Marketplace](https://aws.amazon.com/marketplace) |
| 44 | +2. Complete subscription verification (24-hour review process) |
| 45 | +3. Access MultiverseIAM dashboard with provided credentials |
| 46 | +4. Retrieve your API key from the dashboard |
| 47 | + |
| 48 | +```python |
| 49 | +import os |
| 50 | + |
| 51 | +os.environ["COMPACTIFAI_API_KEY"] = "your-api-key" |
| 52 | +``` |
| 53 | + |
| 54 | +## Usage |
| 55 | + |
| 56 | +<Tabs> |
| 57 | +<TabItem value="sdk" label="SDK"> |
| 58 | + |
| 59 | +```python |
| 60 | +from litellm import completion |
| 61 | +import os |
| 62 | + |
| 63 | +os.environ['COMPACTIFAI_API_KEY'] = "your-api-key" |
| 64 | + |
| 65 | +response = completion( |
| 66 | + model="compactifai/cai-llama-3-1-8b-slim", |
| 67 | + messages=[ |
| 68 | + {"role": "user", "content": "Hello from LiteLLM!"} |
| 69 | + ], |
| 70 | +) |
| 71 | +print(response) |
| 72 | +``` |
| 73 | + |
| 74 | +</TabItem> |
| 75 | +<TabItem value="proxy" label="Proxy"> |
| 76 | + |
| 77 | +```yaml |
| 78 | +model_list: |
| 79 | + - model_name: llama-2-compressed |
| 80 | + litellm_params: |
| 81 | + model: compactifai/cai-llama-3-1-8b-slim |
| 82 | + api_key: os.environ/COMPACTIFAI_API_KEY |
| 83 | +``` |
| 84 | +
|
| 85 | +</TabItem> |
| 86 | +</Tabs> |
| 87 | +
|
| 88 | +## Streaming |
| 89 | +
|
| 90 | +```python |
| 91 | +from litellm import completion |
| 92 | +import os |
| 93 | + |
| 94 | +os.environ['COMPACTIFAI_API_KEY'] = "your-api-key" |
| 95 | + |
| 96 | +response = completion( |
| 97 | + model="compactifai/cai-llama-3-1-8b-slim", |
| 98 | + messages=[ |
| 99 | + {"role": "user", "content": "Write a short story"} |
| 100 | + ], |
| 101 | + stream=True |
| 102 | +) |
| 103 | + |
| 104 | +for chunk in response: |
| 105 | + print(chunk) |
| 106 | +``` |
| 107 | +
|
| 108 | +## Advanced Usage |
| 109 | +
|
| 110 | +### Custom Parameters |
| 111 | +
|
| 112 | +```python |
| 113 | +from litellm import completion |
| 114 | + |
| 115 | +response = completion( |
| 116 | + model="compactifai/cai-llama-3-1-8b-slim", |
| 117 | + messages=[{"role": "user", "content": "Explain quantum computing"}], |
| 118 | + temperature=0.7, |
| 119 | + max_tokens=500, |
| 120 | + top_p=0.9, |
| 121 | + stop=["Human:", "AI:"] |
| 122 | +) |
| 123 | +``` |
| 124 | + |
| 125 | +### Function Calling |
| 126 | + |
| 127 | +CompactifAI supports OpenAI-compatible function calling: |
| 128 | + |
| 129 | +```python |
| 130 | +from litellm import completion |
| 131 | + |
| 132 | +functions = [ |
| 133 | + { |
| 134 | + "name": "get_weather", |
| 135 | + "description": "Get current weather information", |
| 136 | + "parameters": { |
| 137 | + "type": "object", |
| 138 | + "properties": { |
| 139 | + "location": { |
| 140 | + "type": "string", |
| 141 | + "description": "The city and state" |
| 142 | + } |
| 143 | + }, |
| 144 | + "required": ["location"] |
| 145 | + } |
| 146 | + } |
| 147 | +] |
| 148 | + |
| 149 | +response = completion( |
| 150 | + model="compactifai/cai-llama-3-1-8b-slim", |
| 151 | + messages=[{"role": "user", "content": "What's the weather in San Francisco?"}], |
| 152 | + tools=[{"type": "function", "function": f} for f in functions], |
| 153 | + tool_choice="auto" |
| 154 | +) |
| 155 | +``` |
| 156 | + |
| 157 | +### Async Usage |
| 158 | + |
| 159 | +```python |
| 160 | +import asyncio |
| 161 | +from litellm import acompletion |
| 162 | + |
| 163 | +async def async_call(): |
| 164 | + response = await acompletion( |
| 165 | + model="compactifai/cai-llama-3-1-8b-slim", |
| 166 | + messages=[{"role": "user", "content": "Hello async world!"}] |
| 167 | + ) |
| 168 | + return response |
| 169 | + |
| 170 | +# Run async function |
| 171 | +response = asyncio.run(async_call()) |
| 172 | +print(response) |
| 173 | +``` |
| 174 | + |
| 175 | +## Available Models |
| 176 | + |
| 177 | +CompactifAI offers compressed versions of popular models. Use the `/models` endpoint to get the latest list: |
| 178 | + |
| 179 | +```python |
| 180 | +import httpx |
| 181 | + |
| 182 | +headers = {"Authorization": f"Bearer {your_api_key}"} |
| 183 | +response = httpx.get("https://api.compactif.ai/v1/models", headers=headers) |
| 184 | +models = response.json() |
| 185 | +``` |
| 186 | + |
| 187 | +Common model formats: |
| 188 | +- `compactifai/cai-llama-3-1-8b-slim` |
| 189 | +- `compactifai/mistral-7b-compressed` |
| 190 | +- `compactifai/codellama-7b-compressed` |
| 191 | + |
| 192 | +## Benefits |
| 193 | + |
| 194 | +- **Cost Efficient**: Up to 70% lower inference costs compared to standard models |
| 195 | +- **High Performance**: 4x throughput gains with minimal quality loss (<5%) |
| 196 | +- **Low Latency**: Optimized for fast response times |
| 197 | +- **Drop-in Replacement**: Full OpenAI API compatibility |
| 198 | +- **Scalable**: Superior concurrency and resource efficiency |
| 199 | + |
| 200 | +## Error Handling |
| 201 | + |
| 202 | +CompactifAI returns standard OpenAI-compatible error responses: |
| 203 | + |
| 204 | +```python |
| 205 | +from litellm import completion |
| 206 | +from litellm.exceptions import AuthenticationError, RateLimitError |
| 207 | + |
| 208 | +try: |
| 209 | + response = completion( |
| 210 | + model="compactifai/cai-llama-3-1-8b-slim", |
| 211 | + messages=[{"role": "user", "content": "Hello"}] |
| 212 | + ) |
| 213 | +except AuthenticationError: |
| 214 | + print("Invalid API key") |
| 215 | +except RateLimitError: |
| 216 | + print("Rate limit exceeded") |
| 217 | +``` |
| 218 | + |
| 219 | +## Support |
| 220 | + |
| 221 | +- Documentation: https://docs.compactif.ai/ |
| 222 | +- LinkedIn: [MultiverseComputing](https://www.linkedin.com/company/multiversecomputing) |
| 223 | +- Analysis: [Artificial Analysis Provider Comparison](https://artificialanalysis.ai/providers/compactifai) |
0 commit comments