Merge branch 'main' into inceptionlabs-provider
This commit is contained in:
commit
a7f70484a8
4 changed files with 185 additions and 2 deletions
133
core/llm/llms/Docker.ts
Normal file
133
core/llm/llms/Docker.ts
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
import { spawn } from "child_process";
|
||||
import { LLMOptions, ModelInstaller } from "../../index.js";
|
||||
import OpenAI from "./OpenAI.js";
|
||||
|
||||
/**
|
||||
* Docker Model Runner provider
|
||||
*
|
||||
* Integrates with Docker Desktop's Model Runner feature (currently in beta)
|
||||
* that allows running local AI models through Docker.
|
||||
*
|
||||
* Docker Model Runner provides an OpenAI-compatible API endpoint, making it
|
||||
* easy to integrate with existing OpenAI-compatible code.
|
||||
*
|
||||
* More information at: https://docs.docker.com/desktop/features/model-runner/
|
||||
*/
|
||||
class Docker extends OpenAI implements ModelInstaller {
|
||||
static providerName = "docker";
|
||||
static defaultOptions: Partial<LLMOptions> = {
|
||||
apiBase: "http://model-runner.docker.internal/v1/",
|
||||
model: "gemma3-4B-F4", // Default model
|
||||
};
|
||||
|
||||
private modelMap: Record<string, string> = {
|
||||
// Map of "continue model name" to Docker model name
|
||||
// Models can be pulled using: docker model pull <model_name>
|
||||
"llama3.3-70b": "ai/llama3.3:70B-Q4_K_M",
|
||||
"smollm2-360M-F4": "ai/smollm2:360M-Q4_K_M",
|
||||
"smollm2-360M-F16": "ai/ai/smollm2:360M-F16",
|
||||
"qwen2.5-7B-F16": "ai/qwen2.5:7B-F16",
|
||||
"qwen2.5-7B-F4": "ai/qwen2.5:7B-Q4_K_M",
|
||||
"phi4-14B-F16": "ai/phi4:14B-F16",
|
||||
"phi4-14B-F4": "ai/phi4:14B-Q4_K_M",
|
||||
"mistral-7B-F16": "ai/mistral:7B-F16",
|
||||
"mistral-7B-F4": "ai/mistral:7B-Q4_K_M",
|
||||
"mistral-nemo-12B": "ai/mistral-nemo:12B-Q4_K_M",
|
||||
"gemma3-4B-F16": "ai/gemma3:4B-F16",
|
||||
"gemma3-4B-F4": "ai/gemma3:4B-Q4_K_M",
|
||||
"llama3.2-3B-F16": "ai/llama3.2:3B-F16",
|
||||
"llama3.2-3B-F4": "ai/llama3.2:3B-Q4_K_M",
|
||||
"llama3.2-1B-F16": "ai/llama3.2:1B-F16",
|
||||
"llama3.2-1B-F8": "ai/llama3.2:1B-Q8_0",
|
||||
"qwq-32B-F16": "ai/qwq:32B-F16",
|
||||
"qwq-32B-F4": "ai/qwq:32B-Q4_K_M",
|
||||
"deepseek-r1-distill-llama-70B-F4": "ai/deepseek-r1-distill-llama:70B-Q4_K_M",
|
||||
"deepseek-r1-distill-llama-8B-F16": "ai/deepseek-r1-distill-llama:8B-F16",
|
||||
"deepseek-r1-distill-llama-8B-Q4": "ai/deepseek-r1-distill-llama:8B-Q4_K_M"
|
||||
};
|
||||
|
||||
constructor(options: LLMOptions) {
|
||||
super(options);
|
||||
|
||||
// Handle model name mapping
|
||||
if (this.model && this.modelMap[this.model]) {
|
||||
this.model = this.modelMap[this.model];
|
||||
}
|
||||
}
|
||||
|
||||
private async executeDockerCommand(
|
||||
args: string[],
|
||||
signal?: AbortSignal
|
||||
): Promise<{ stdout: string; stderr: string }> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const proc = spawn('docker', args, { shell: true });
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
proc.stdout.on('data', (data) => {
|
||||
stdout += data.toString();
|
||||
});
|
||||
|
||||
proc.stderr.on('data', (data) => {
|
||||
stderr += data.toString();
|
||||
});
|
||||
|
||||
proc.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
resolve({ stdout, stderr });
|
||||
} else {
|
||||
reject(new Error(`Docker command failed with code ${code}: ${stderr}`));
|
||||
}
|
||||
});
|
||||
|
||||
if (signal) {
|
||||
signal.addEventListener('abort', () => {
|
||||
proc.kill();
|
||||
reject(new Error('Docker command was aborted'));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async listModels(): Promise<string[]> {
|
||||
try {
|
||||
// Execute docker model ls and parse the output
|
||||
const { stdout } = await this.executeDockerCommand(['model', 'ls', '--format', '{{.Repository}}/{{.Tag}}']);
|
||||
return stdout.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(Boolean);
|
||||
} catch (error) {
|
||||
console.error("Failed to list Docker models:", error);
|
||||
return Object.values(this.modelMap);
|
||||
}
|
||||
}
|
||||
|
||||
async installModel(
|
||||
modelName: string,
|
||||
signal: AbortSignal,
|
||||
progressReporter?: (task: string, increment: number, total: number) => void
|
||||
): Promise<any> {
|
||||
const targetModel = this.modelMap[modelName] || modelName;
|
||||
|
||||
try {
|
||||
// Report starting the installation
|
||||
progressReporter?.(`Installing Docker model ${targetModel}`, 0, 100);
|
||||
|
||||
// Pull the model
|
||||
const { stdout, stderr } = await this.executeDockerCommand(['model', 'pull', targetModel], signal);
|
||||
|
||||
// Report completion
|
||||
progressReporter?.(`Docker model ${targetModel} installed successfully`, 100, 100);
|
||||
|
||||
return { success: true, stdout, stderr };
|
||||
} catch (error) {
|
||||
console.error(`Failed to install Docker model ${targetModel}:`, error);
|
||||
// Fix: Type check the error before accessing message property
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
throw new Error(`Failed to install Docker model ${targetModel}: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Docker;
|
||||
48
core/llm/llms/Inception.ts
Normal file
48
core/llm/llms/Inception.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { CompletionOptions, LLMOptions } from "../../index.js";
|
||||
import { streamSse } from "../stream.js";
|
||||
|
||||
import OpenAI from "./OpenAI.js";
|
||||
|
||||
class Inception extends OpenAI {
|
||||
static providerName = "inception";
|
||||
static defaultOptions: Partial<LLMOptions> = {};
|
||||
|
||||
supportsFim(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
async *_streamFim(
|
||||
prefix: string,
|
||||
suffix: string,
|
||||
signal: AbortSignal,
|
||||
options: CompletionOptions,
|
||||
): AsyncGenerator<string> {
|
||||
const endpoint = new URL("completions", this.apiBase);
|
||||
const resp = await this.fetch(endpoint, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
model: options.model,
|
||||
prompt: prefix,
|
||||
suffix,
|
||||
max_tokens: options.maxTokens,
|
||||
temperature: options.temperature,
|
||||
top_p: options.topP,
|
||||
frequency_penalty: options.frequencyPenalty,
|
||||
presence_penalty: options.presencePenalty,
|
||||
stop: options.stop,
|
||||
stream: true,
|
||||
}),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
Authorization: `Bearer ${this.apiKey}`,
|
||||
},
|
||||
signal,
|
||||
});
|
||||
for await (const chunk of streamSse(resp)) {
|
||||
yield chunk.choices[0].text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Inception;
|
||||
|
|
@ -18,6 +18,7 @@ import Cloudflare from "./Cloudflare";
|
|||
import Cohere from "./Cohere";
|
||||
import DeepInfra from "./DeepInfra";
|
||||
import Deepseek from "./Deepseek";
|
||||
import Docker from "./Docker";
|
||||
import Fireworks from "./Fireworks";
|
||||
import Flowise from "./Flowise";
|
||||
import FreeTrial from "./FreeTrial";
|
||||
|
|
@ -26,7 +27,7 @@ import Gemini from "./Gemini";
|
|||
import Groq from "./Groq";
|
||||
import HuggingFaceInferenceAPI from "./HuggingFaceInferenceAPI";
|
||||
import HuggingFaceTGI from "./HuggingFaceTGI";
|
||||
import InceptionLabs from "./InceptionLabs";
|
||||
import Inception from "./Inception";
|
||||
import Kindo from "./Kindo";
|
||||
import LlamaCpp from "./LlamaCpp";
|
||||
import Llamafile from "./Llamafile";
|
||||
|
|
@ -72,7 +73,6 @@ export const LLMClasses = [
|
|||
Novita,
|
||||
HuggingFaceTGI,
|
||||
HuggingFaceInferenceAPI,
|
||||
InceptionLabs,
|
||||
Kindo,
|
||||
LlamaCpp,
|
||||
OpenAI,
|
||||
|
|
@ -89,6 +89,7 @@ export const LLMClasses = [
|
|||
ContinueProxy,
|
||||
Cloudflare,
|
||||
Deepseek,
|
||||
Docker,
|
||||
Msty,
|
||||
Azure,
|
||||
WatsonX,
|
||||
|
|
@ -106,6 +107,7 @@ export const LLMClasses = [
|
|||
SiliconFlow,
|
||||
Scaleway,
|
||||
Relace,
|
||||
Inception,
|
||||
];
|
||||
|
||||
export async function llmFromDescription(
|
||||
|
|
|
|||
BIN
gui/public/logos/docker.png
Normal file
BIN
gui/public/logos/docker.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
Loading…
Add table
Reference in a new issue