diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index 366f6bd60..cea8ec524 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -104,13 +104,13 @@ class OpenAI extends BaseLLM { this.maxStopWords !== undefined ? options.stop?.slice(0, this.maxStopWords) : url.host === "api.deepseek.com" - ? options.stop?.slice(0, 16) - : url.port === "1337" || - url.host === "api.openai.com" || - url.host === "api.groq.com" || - this.apiType === "azure" - ? options.stop?.slice(0, 4) - : options.stop, + ? options.stop?.slice(0, 16) + : url.port === "1337" || + url.host === "api.openai.com" || + url.host === "api.groq.com" || + this.apiType === "azure" + ? options.stop?.slice(0, 4) + : options.stop, }; return finalOptions; @@ -139,7 +139,7 @@ class OpenAI extends BaseLLM { return completion; } - private _getEndpoint( + protected _getEndpoint( endpoint: "chat/completions" | "completions" | "models", ) { if (this.apiType === "azure") { diff --git a/core/llm/llms/Vllm.ts b/core/llm/llms/Vllm.ts new file mode 100644 index 000000000..d0ad32816 --- /dev/null +++ b/core/llm/llms/Vllm.ts @@ -0,0 +1,30 @@ +import { LLMOptions, ModelProvider } from "../../index.js"; +import OpenAI from "./OpenAI.js"; + +class Vllm extends OpenAI { + constructor(options: LLMOptions) { + super(options); + this._setupCompletionOptions(); + } + + private _setupCompletionOptions() { + this.fetch(this._getEndpoint("models"), { + method: "GET", + headers: this._getHeaders(), + }).then(async (response) => { + if (response.status !== 200) { + console.warn( + "Error calling vLLM /models endpoint: ", + await response.text(), + ); + return; + } + const json = await response.json(); + const data = json.data; + this.model = data.id; + this.contextLength = Number.parseInt(data.max_model_len); + }); + } +} + +export default Vllm; diff --git a/docs/docs/reference/Model Providers/openai.md b/docs/docs/reference/Model Providers/openai.md index 10c86206d..628ec8c42 100644 --- a/docs/docs/reference/Model Providers/openai.md +++ b/docs/docs/reference/Model Providers/openai.md @@ -12,6 +12,7 @@ OpenAI compatible servers - [LocalAI](https://localai.io/basics/getting_started/) - [llama-cpp-python](https://github.com/abetlen/llama-cpp-python#web-server) - [TensorRT-LLM](https://github.com/NVIDIA/trt-llm-as-openai-windows?tab=readme-ov-file#examples) +- [vLLM](https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html) [^1] OpenAI compatible APIs @@ -40,4 +41,7 @@ To force usage of `chat/completions` instead of `completions` endpoint you can s "useLegacyCompletionsEndpoint": false ``` +[^1]: Use the [Vllm Model Provider](./vllm.md) instead. + + [View the source](https://github.com/continuedev/continue/blob/main/core/llm/llms/OpenAI.ts) diff --git a/docs/docs/reference/Model Providers/vllm.md b/docs/docs/reference/Model Providers/vllm.md new file mode 100644 index 000000000..71a5f3cba --- /dev/null +++ b/docs/docs/reference/Model Providers/vllm.md @@ -0,0 +1,22 @@ +# vLLM + +Run the OpenAI-compatible server by vLLM using `vllm serve`. See their [server documentation](https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html) and the [engine arguments documentation](https://docs.vllm.ai/en/latest/models/engine_args.html). + +```shell +vllm serve NousResearch/Meta-Llama-3-8B-Instruct --max-model-len 1024 +``` + +The continue implementation uses [OpenAI](./openai.md) under the hood and automatically selects the available model. You only need to set the `apiBase` like this: + +```json title="~/.continue/config.json" +{ + "models": [ + { + "title": "My vLLM OpenAI-compatible server", + "apiBase": "http://localhost:8000/v1" + } + ] +} +``` + +[View the source](https://github.com/continuedev/continue/blob/main/core/llm/llms/Vllm.ts)