File tree Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Expand file tree Collapse file tree 4 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -307,3 +307,34 @@ cocoindex.LlmSpec(
307307</Tabs>
308308
309309You 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>
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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;
8283mod openai;
8384mod openrouter;
8485mod voyage;
86+ mod vllm;
8587
8688pub 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}
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments