Skip to content

Commit 2410892

Browse files
committed
add vllm
1 parent 14da9da commit 2410892

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

docs/docs/ai/llm.mdx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,34 @@ cocoindex.LlmSpec(
307307
</Tabs>
308308

309309
You can find the full list of models supported by OpenRouter [here](https://openrouter.ai/models).
310+
311+
### vLLM
312+
313+
Install vLLM:
314+
315+
```bash
316+
pip install vllm
317+
```
318+
319+
Run vLLM Server
320+
321+
```bash
322+
vllm serve deepseek-ai/deepseek-coder-1.3b-instruct
323+
```
324+
325+
326+
A spec for vLLM looks like this:
327+
328+
<Tabs>
329+
<TabItem value="python" label="Python" default>
330+
331+
```python
332+
cocoindex.LlmSpec(
333+
api_type=cocoindex.LlmApiType.VLLM,
334+
model="deepseek-ai/deepseek-coder-1.3b-instruct",
335+
address="http://127.0.0.1:8000/v1",
336+
)
337+
```
338+
339+
</TabItem>
340+
</Tabs>

python/cocoindex/llm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class LlmApiType(Enum):
1212
LITE_LLM = "LiteLlm"
1313
OPEN_ROUTER = "OpenRouter"
1414
VOYAGE = "Voyage"
15+
VLLM = "Vllm"
1516

1617

1718
@dataclass

src/llm/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub enum LlmApiType {
1313
LiteLlm,
1414
OpenRouter,
1515
Voyage,
16+
Vllm,
1617
}
1718

1819
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -82,6 +83,7 @@ mod ollama;
8283
mod openai;
8384
mod openrouter;
8485
mod voyage;
86+
mod vllm;
8587

8688
pub async fn new_llm_generation_client(
8789
api_type: LlmApiType,
@@ -108,6 +110,9 @@ pub async fn new_llm_generation_client(
108110
LlmApiType::Voyage => {
109111
api_bail!("Voyage is not supported for generation")
110112
}
113+
LlmApiType::Vllm => {
114+
Box::new(vllm::Client::new_vllm(address).await?) as Box<dyn LlmGenerationClient>
115+
}
111116
};
112117
Ok(client)
113118
}

src/llm/vllm.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use async_openai::Client as OpenAIClient;
2+
use async_openai::config::OpenAIConfig;
3+
4+
pub use super::openai::Client;
5+
6+
impl Client {
7+
pub async fn new_vllm(address: Option<String>) -> anyhow::Result<Self> {
8+
let address = address.unwrap_or_else(|| "http://127.0.0.1:8000/v1".to_string());
9+
let api_key = std::env::var("VLLM_API_KEY").ok();
10+
let mut config = OpenAIConfig::new().with_api_base(address);
11+
if let Some(api_key) = api_key {
12+
config = config.with_api_key(api_key);
13+
}
14+
Ok(Client::from_parts(OpenAIClient::with_config(config)))
15+
}
16+
}

0 commit comments

Comments
 (0)