Changesets · Branches · Tags · Compare
| Changeset | 0ecb63d17b3f0c4f95ee1794b4b92633462a58f5bdeaa1f19f703c4fdf73f02c |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-02 19:20 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-02 19:20 -07:00 |
| Parents | 6a7a94404ac9, e1f06c4b50bf |
6 files changed
added core/llm/llms/LlamaStack.ts +57 −0
| @@ -0,0 +1,57 @@ | ||
| 1 | +import { streamSse } from "@continuedev/fetch"; | |
| 2 | +import { CompletionOptions, LLMOptions } from "../../index.js"; | |
| 3 | +import { osModelsEditPrompt } from "../templates/edit.js"; | |
| 4 | + | |
| 5 | +import OpenAI from "./OpenAI.js"; | |
| 6 | + | |
| 7 | +class LlamaStack extends OpenAI { | |
| 8 | + static providerName = "llamastack"; | |
| 9 | + static defaultOptions: Partial<LLMOptions> = { | |
| 10 | + apiBase: "http://localhost:8321/v1/openai/v1/", | |
| 11 | + model: "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8", | |
| 12 | + promptTemplates: { | |
| 13 | + edit: osModelsEditPrompt, | |
| 14 | + }, | |
| 15 | + useLegacyCompletionsEndpoint: false, | |
| 16 | + }; | |
| 17 | + maxStopWords: number | undefined = 16; | |
| 18 | + | |
| 19 | + supportsFim(): boolean { | |
| 20 | + return true; | |
| 21 | + } | |
| 22 | + | |
| 23 | + async *_streamFim( | |
| 24 | + prefix: string, | |
| 25 | + suffix: string, | |
| 26 | + signal: AbortSignal, | |
| 27 | + options: CompletionOptions, | |
| 28 | + ): AsyncGenerator<string> { | |
| 29 | + const endpoint = new URL("completions", this.apiBase); | |
| 30 | + const resp = await this.fetch(endpoint, { | |
| 31 | + method: "POST", | |
| 32 | + body: JSON.stringify({ | |
| 33 | + model: options.model, | |
| 34 | + prompt: prefix, | |
| 35 | + suffix, | |
| 36 | + max_tokens: options.maxTokens, | |
| 37 | + temperature: options.temperature, | |
| 38 | + top_p: options.topP, | |
| 39 | + frequency_penalty: options.frequencyPenalty, | |
| 40 | + presence_penalty: options.presencePenalty, | |
| 41 | + stop: options.stop, | |
| 42 | + stream: true, | |
| 43 | + }), | |
| 44 | + headers: { | |
| 45 | + "Content-Type": "application/json", | |
| 46 | + Accept: "application/json", | |
| 47 | + Authorization: `Bearer ${this.apiKey}`, | |
| 48 | + }, | |
| 49 | + signal, | |
| 50 | + }); | |
| 51 | + for await (const chunk of streamSse(resp)) { | |
| 52 | + yield chunk.choices[0].text; | |
| 53 | + } | |
| 54 | + } | |
| 55 | +} | |
| 56 | + | |
| 57 | +export default LlamaStack; |
modified core/llm/llms/index.ts +2 −1
| @@ -33,6 +33,7 @@ | ||
| 33 | 33 | import Kindo from "./Kindo"; |
| 34 | 34 | import LlamaCpp from "./LlamaCpp"; |
| 35 | 35 | import Llamafile from "./Llamafile"; |
| 36 | +import LlamaStack from "./LlamaStack"; | |
| 36 | 37 | import LMStudio from "./LMStudio"; |
| 37 | 38 | import Mistral from "./Mistral"; |
| 38 | 39 | import MockLLM from "./Mock"; |
| @@ -62,7 +63,6 @@ | ||
| 62 | 63 | import Voyage from "./Voyage"; |
| 63 | 64 | import WatsonX from "./WatsonX"; |
| 64 | 65 | import xAI from "./xAI"; |
| 65 | - | |
| 66 | 66 | export const LLMClasses = [ |
| 67 | 67 | Anthropic, |
| 68 | 68 | Cohere, |
| @@ -116,6 +116,7 @@ | ||
| 116 | 116 | Relace, |
| 117 | 117 | Inception, |
| 118 | 118 | Voyage, |
| 119 | + LlamaStack, | |
| 119 | 120 | ]; |
| 120 | 121 | |
| 121 | 122 | export async function llmFromDescription( |
added docs/docs/customize/model-providers/more/llamastack.mdx +113 −0
| @@ -0,0 +1,113 @@ | ||
| 1 | +import TabItem from "@theme/TabItem"; | |
| 2 | +import Tabs from "@theme/Tabs"; | |
| 3 | + | |
| 4 | +# Llama Stack | |
| 5 | + | |
| 6 | +[Llama Stack](https://llama-stack.readthedocs.io/en/latest/index.html) is an open-source library that standardizes the core building blocks that simplify AI application development. It codifies best practices across the Llama ecosystem. More specifically, it provides | |
| 7 | + | |
| 8 | +- **Unified API layer** for Inference, RAG, Agents, Tools, Safety, Evals, and Telemetry. | |
| 9 | +- **Plugin architecture** to support the rich ecosystem of different API implementations in various environments, including local development, on-premises, cloud, and mobile. | |
| 10 | +- **Prepackaged verified distributions** which offer a one-stop solution for developers to get started quickly and reliably in any environment. | |
| 11 | +- **Multiple developer interfaces** like CLI and SDKs for Python, Typescript, iOS, and Android. | |
| 12 | +- **Standalone applications** as examples for how to build production-grade AI applications with Llama Stack. | |
| 13 | + | |
| 14 | +To try Llama Stack locally, run: | |
| 15 | + | |
| 16 | +```shell | |
| 17 | +curl -LsSf https://github.com/meta-llama/llama-stack/raw/main/install.sh | bash | |
| 18 | +``` | |
| 19 | + | |
| 20 | +Learn more about how to get started with llama stack in this [guide](https://llama-stack.readthedocs.io/en/latest/getting_started/index.html) | |
| 21 | + | |
| 22 | +## Chat model | |
| 23 | + | |
| 24 | +We recommend configuring **Llama 4 Maverick** as your chat model. | |
| 25 | + | |
| 26 | +<Tabs groupId="config-example"> | |
| 27 | + <TabItem value="yaml" label="YAML"> | |
| 28 | + ```yaml title="config.yaml" | |
| 29 | + models: | |
| 30 | + - name: Llama4 Maverick | |
| 31 | + provider: llamastack | |
| 32 | + model: meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8 | |
| 33 | + apiBase: http://<llama stack endpoint>/v1/openai/v1/ | |
| 34 | + ``` | |
| 35 | + </TabItem> | |
| 36 | + <TabItem value="json" label="JSON"> | |
| 37 | + ```json title="config.json" | |
| 38 | + { | |
| 39 | + "models": [ | |
| 40 | + { | |
| 41 | + "title": "Llama4 Maverick", | |
| 42 | + "provider": "llamastack", | |
| 43 | + "model": "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8", | |
| 44 | + "apiBase": "http://<llama stack endpoint>/v1/openai/v1/" | |
| 45 | + } | |
| 46 | + ] | |
| 47 | + } | |
| 48 | + ``` | |
| 49 | + </TabItem> | |
| 50 | +</Tabs> | |
| 51 | + | |
| 52 | +## Autocomplete model | |
| 53 | + | |
| 54 | +We recommend configuring **CodeLlama 7B** as your autocomplete model. | |
| 55 | + | |
| 56 | +<Tabs groupId="config-example"> | |
| 57 | + <TabItem value="yaml" label="YAML"> | |
| 58 | + ```yaml title="config.yaml" | |
| 59 | + models: | |
| 60 | + - name: CodeLlama 7B | |
| 61 | + provider: llamastack | |
| 62 | + model: codellama:7b | |
| 63 | + apiBase: http://<llama stack endpoint>/v1/openai/v1/ | |
| 64 | + roles: | |
| 65 | + - autocomplete | |
| 66 | + ``` | |
| 67 | + </TabItem> | |
| 68 | + <TabItem value="json" label="JSON"> | |
| 69 | + ```json title="config.json" | |
| 70 | + { | |
| 71 | + "tabAutocompleteModel": { | |
| 72 | + "title": "CodeLlama 7B", | |
| 73 | + "provider": "llamastack", | |
| 74 | + "model": "codellama:7b", | |
| 75 | + "apiBase": "http://<llama stack endpoint>/v1/openai/v1/" | |
| 76 | + } | |
| 77 | + } | |
| 78 | + ``` | |
| 79 | + </TabItem> | |
| 80 | +</Tabs> | |
| 81 | + | |
| 82 | +## Embeddings model | |
| 83 | + | |
| 84 | +By default, Llama Stack uses **all-MiniLM-L6-v2** as the embeddings model. | |
| 85 | + | |
| 86 | +<Tabs groupId="config-example"> | |
| 87 | + <TabItem value="yaml" label="YAML"> | |
| 88 | + ```yaml title="config.yaml" | |
| 89 | + models: | |
| 90 | + - name: all-MiniLM-L6-v2 | |
| 91 | + provider: llamastack | |
| 92 | + model: all-MiniLM-L6-v2 | |
| 93 | + apiBase: http://<llama stack endpoint>/v1/openai/v1/ | |
| 94 | + roles: | |
| 95 | + - embed | |
| 96 | + ``` | |
| 97 | + </TabItem> | |
| 98 | + <TabItem value="json" label="JSON"> | |
| 99 | + ```json title="config.json" | |
| 100 | + { | |
| 101 | + "embeddingsProvider": { | |
| 102 | + "provider": "llamastack", | |
| 103 | + "model": "all-MiniLM-L6-v2", | |
| 104 | + "apiBase": "http://<llama stack endpoint>/v1/openai/v1/" | |
| 105 | + } | |
| 106 | + } | |
| 107 | + ``` | |
| 108 | + </TabItem> | |
| 109 | +</Tabs> | |
| 110 | + | |
| 111 | +## Reranking model | |
| 112 | + | |
| 113 | +Llama Stack currently did not support Reranking API yet. | |
| No newline at the end of the file |
added packages/openai-adapters/src/apis/LlamaStack.ts +55 −0
| @@ -0,0 +1,55 @@ | ||
| 1 | +import { streamSse } from "@continuedev/fetch"; | |
| 2 | +import { ChatCompletionChunk } from "openai/resources/index"; | |
| 3 | +import { LlamastackConfig } from "../types.js"; | |
| 4 | +import { chatChunk, customFetch } from "../util.js"; | |
| 5 | +import { OpenAIApi } from "./OpenAI.js"; | |
| 6 | +import { FimCreateParamsStreaming } from "./base.js"; | |
| 7 | + | |
| 8 | +export const Llamastack_API_BASE = "http://localhost:8321/v1/openai/v1/"; | |
| 9 | +export class LlamastackApi extends OpenAIApi { | |
| 10 | + constructor(config: LlamastackConfig) { | |
| 11 | + super({ | |
| 12 | + ...config, | |
| 13 | + provider: "openai", | |
| 14 | + apiBase: config.apiBase ?? Llamastack_API_BASE, | |
| 15 | + apiKey: config.apiKey ?? "dummy", | |
| 16 | + }); | |
| 17 | + } | |
| 18 | + | |
| 19 | + async *fimStream( | |
| 20 | + body: FimCreateParamsStreaming, | |
| 21 | + signal: AbortSignal, | |
| 22 | + ): AsyncGenerator<ChatCompletionChunk, any, unknown> { | |
| 23 | + const endpoint = new URL("completions", this.apiBase); | |
| 24 | + const resp = await customFetch(this.config.requestOptions)(endpoint, { | |
| 25 | + method: "POST", | |
| 26 | + body: JSON.stringify({ | |
| 27 | + model: body.model, | |
| 28 | + prompt: body.prompt, | |
| 29 | + suffix: body.suffix, | |
| 30 | + max_tokens: body.max_tokens, | |
| 31 | + max_completion_tokens: (body as any).max_completion_tokens, | |
| 32 | + temperature: body.temperature, | |
| 33 | + top_p: body.top_p, | |
| 34 | + frequency_penalty: body.frequency_penalty, | |
| 35 | + presence_penalty: body.presence_penalty, | |
| 36 | + stop: body.stop, | |
| 37 | + stream: true, | |
| 38 | + }), | |
| 39 | + headers: { | |
| 40 | + "Content-Type": "application/json", | |
| 41 | + Accept: "application/json", | |
| 42 | + "x-api-key": this.config.apiKey ?? "", | |
| 43 | + Authorization: `Bearer ${this.config.apiKey}`, | |
| 44 | + }, | |
| 45 | + signal, | |
| 46 | + }); | |
| 47 | + for await (const chunk of streamSse(resp as any)) { | |
| 48 | + yield chatChunk({ | |
| 49 | + content: chunk.choices[0].text, | |
| 50 | + finish_reason: chunk.finish_reason, | |
| 51 | + model: body.model, | |
| 52 | + }); | |
| 53 | + } | |
| 54 | + } | |
| 55 | +} |
modified packages/openai-adapters/src/index.ts +3 −0
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | import { GeminiApi } from "./apis/Gemini.js"; |
| 8 | 8 | import { InceptionApi } from "./apis/Inception.js"; |
| 9 | 9 | import { JinaApi } from "./apis/Jina.js"; |
| 10 | +import { LlamastackApi } from "./apis/LlamaStack.js"; | |
| 10 | 11 | import { MockApi } from "./apis/Mock.js"; |
| 11 | 12 | import { MoonshotApi } from "./apis/Moonshot.js"; |
| 12 | 13 | import { OpenAIApi } from "./apis/OpenAI.js"; |
| @@ -51,6 +52,8 @@ | ||
| 51 | 52 | return new InceptionApi(config); |
| 52 | 53 | case "watsonx": |
| 53 | 54 | return new WatsonXApi(config); |
| 55 | + case "llamastack": | |
| 56 | + return new LlamastackApi(config); | |
| 54 | 57 | case "x-ai": |
| 55 | 58 | return openAICompatible("https://api.x.ai/v1/", config); |
| 56 | 59 | case "voyage": |
modified packages/openai-adapters/src/types.ts +7 −0
| @@ -71,9 +71,15 @@ | ||
| 71 | 71 | }); |
| 72 | 72 | export type DeepseekConfig = z.infer<typeof DeepseekConfigSchema>; |
| 73 | 73 | |
| 74 | +export const LlamastackConfigSchema = OpenAIConfigSchema.extend({ | |
| 75 | + provider: z.literal("llamastack"), | |
| 76 | +}); | |
| 77 | +export type LlamastackConfig = z.infer<typeof LlamastackConfigSchema>; | |
| 78 | + | |
| 74 | 79 | export const MockConfigSchema = BasePlusConfig.extend({ |
| 75 | 80 | provider: z.literal("mock"), |
| 76 | 81 | }); |
| 82 | + | |
| 77 | 83 | export type MockConfig = z.infer<typeof MockConfigSchema>; |
| 78 | 84 | |
| 79 | 85 | // Other APIs |
| @@ -146,5 +152,6 @@ | ||
| 146 | 152 | JinaConfigSchema, |
| 147 | 153 | MockConfigSchema, |
| 148 | 154 | InceptionConfigSchema, |
| 155 | + LlamastackConfigSchema, | |
| 149 | 156 | ]); |
| 150 | 157 | export type LLMConfig = z.infer<typeof LLMConfigSchema>; |