Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
31 changes: 31 additions & 0 deletions docs/docs/ai/llm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,34 @@ cocoindex.LlmSpec(
</Tabs>

You can find the full list of models supported by OpenRouter [here](https://openrouter.ai/models).

### vLLM

Install vLLM:

```bash
pip install vllm
```

Run vLLM Server

```bash
vllm serve deepseek-ai/deepseek-coder-1.3b-instruct
```


A spec for vLLM looks like this:

<Tabs>
<TabItem value="python" label="Python" default>

```python
cocoindex.LlmSpec(
api_type=cocoindex.LlmApiType.VLLM,
model="deepseek-ai/deepseek-coder-1.3b-instruct",
address="http://127.0.0.1:8000/v1",
)
```

</TabItem>
</Tabs>
1 change: 1 addition & 0 deletions python/cocoindex/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LlmApiType(Enum):
LITE_LLM = "LiteLlm"
OPEN_ROUTER = "OpenRouter"
VOYAGE = "Voyage"
VLLM = "Vllm"


@dataclass
Expand Down
6 changes: 6 additions & 0 deletions src/llm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub enum LlmApiType {
LiteLlm,
OpenRouter,
Voyage,
Vllm,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -81,6 +82,7 @@ mod litellm;
mod ollama;
mod openai;
mod openrouter;
mod vllm;
mod voyage;

pub async fn new_llm_generation_client(
Expand Down Expand Up @@ -108,6 +110,9 @@ pub async fn new_llm_generation_client(
LlmApiType::Voyage => {
api_bail!("Voyage is not supported for generation")
}
LlmApiType::Vllm => {
Box::new(vllm::Client::new_vllm(address).await?) as Box<dyn LlmGenerationClient>
}
};
Ok(client)
}
Expand All @@ -129,6 +134,7 @@ pub fn new_llm_embedding_client(
LlmApiType::Ollama
| LlmApiType::OpenRouter
| LlmApiType::LiteLlm
| LlmApiType::Vllm
| LlmApiType::Anthropic => {
api_bail!("Embedding is not supported for API type {:?}", api_type)
}
Expand Down
16 changes: 16 additions & 0 deletions src/llm/vllm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use async_openai::Client as OpenAIClient;
use async_openai::config::OpenAIConfig;

pub use super::openai::Client;

impl Client {
pub async fn new_vllm(address: Option<String>) -> anyhow::Result<Self> {
let address = address.unwrap_or_else(|| "http://127.0.0.1:8000/v1".to_string());
let api_key = std::env::var("VLLM_API_KEY").ok();
let mut config = OpenAIConfig::new().with_api_base(address);
if let Some(api_key) = api_key {
config = config.with_api_key(api_key);
}
Ok(Client::from_parts(OpenAIClient::with_config(config)))
}
}