| 1 | import { |
| 2 | BaseCompletionOptions, |
| 3 | IdeSettings, |
| 4 | ILLM, |
| 5 | ILLMLogger, |
| 6 | JSONModelDescription, |
| 7 | LLMOptions, |
| 8 | } from "../.."; |
| 9 | import { renderTemplatedString } from "../../promptFiles/v1/renderTemplatedString"; |
| 10 | import { DEFAULT_CHAT_SYSTEM_MESSAGE } from "../constructMessages"; |
| 11 | import { BaseLLM } from "../index"; |
| 12 | |
| 13 | import Anthropic from "./Anthropic"; |
| 14 | import Asksage from "./Asksage"; |
| 15 | import Azure from "./Azure"; |
| 16 | import Bedrock from "./Bedrock"; |
| 17 | import BedrockImport from "./BedrockImport"; |
| 18 | import Cerebras from "./Cerebras"; |
| 19 | import Cloudflare from "./Cloudflare"; |
| 20 | import Cohere from "./Cohere"; |
| 21 | import DeepInfra from "./DeepInfra"; |
| 22 | import Deepseek from "./Deepseek"; |
| 23 | import Docker from "./Docker"; |
| 24 | import Fireworks from "./Fireworks"; |
| 25 | import Flowise from "./Flowise"; |
| 26 | import FreeTrial from "./FreeTrial"; |
| 27 | import FunctionNetwork from "./FunctionNetwork"; |
| 28 | import Gemini from "./Gemini"; |
| 29 | import Groq from "./Groq"; |
| 30 | import HuggingFaceInferenceAPI from "./HuggingFaceInferenceAPI"; |
| 31 | import HuggingFaceTEIEmbeddingsProvider from "./HuggingFaceTEI"; |
| 32 | import HuggingFaceTGI from "./HuggingFaceTGI"; |
| 33 | import Inception from "./Inception"; |
| 34 | import Kindo from "./Kindo"; |
| 35 | import LlamaCpp from "./LlamaCpp"; |
| 36 | import Llamafile from "./Llamafile"; |
| 37 | import LMStudio from "./LMStudio"; |
| 38 | import Mistral from "./Mistral"; |
| 39 | import MockLLM from "./Mock"; |
| 40 | import Moonshot from "./Moonshot"; |
| 41 | import Msty from "./Msty"; |
| 42 | import NCompass from "./NCompass"; |
| 43 | import Nebius from "./Nebius"; |
| 44 | import Novita from "./Novita"; |
| 45 | import Nvidia from "./Nvidia"; |
| 46 | import Ollama from "./Ollama"; |
| 47 | import OpenAI from "./OpenAI"; |
| 48 | import OpenRouter from "./OpenRouter"; |
| 49 | import OVHcloud from "./OVHcloud"; |
| 50 | import { Relace } from "./Relace"; |
| 51 | import Replicate from "./Replicate"; |
| 52 | import SageMaker from "./SageMaker"; |
| 53 | import SambaNova from "./SambaNova"; |
| 54 | import Scaleway from "./Scaleway"; |
| 55 | import SiliconFlow from "./SiliconFlow"; |
| 56 | import ContinueProxy from "./stubs/ContinueProxy"; |
| 57 | import TestLLM from "./Test"; |
| 58 | import TextGenWebUI from "./TextGenWebUI"; |
| 59 | import Together from "./Together"; |
| 60 | import Venice from "./Venice"; |
| 61 | import VertexAI from "./VertexAI"; |
| 62 | import Vllm from "./Vllm"; |
| 63 | import Voyage from "./Voyage"; |
| 64 | import WatsonX from "./WatsonX"; |
| 65 | import xAI from "./xAI"; |
| 66 | |
| 67 | export const LLMClasses = [ |
| 68 | Anthropic, |
| 69 | Cohere, |
| 70 | FreeTrial, |
| 71 | FunctionNetwork, |
| 72 | Gemini, |
| 73 | Llamafile, |
| 74 | Moonshot, |
| 75 | Ollama, |
| 76 | Replicate, |
| 77 | TextGenWebUI, |
| 78 | Together, |
| 79 | Novita, |
| 80 | HuggingFaceTGI, |
| 81 | HuggingFaceTEIEmbeddingsProvider, |
| 82 | HuggingFaceInferenceAPI, |
| 83 | Kindo, |
| 84 | LlamaCpp, |
| 85 | OpenAI, |
| 86 | OVHcloud, |
| 87 | LMStudio, |
| 88 | Mistral, |
| 89 | Bedrock, |
| 90 | BedrockImport, |
| 91 | SageMaker, |
| 92 | DeepInfra, |
| 93 | Flowise, |
| 94 | Groq, |
| 95 | Fireworks, |
| 96 | NCompass, |
| 97 | ContinueProxy, |
| 98 | Cloudflare, |
| 99 | Deepseek, |
| 100 | Docker, |
| 101 | Msty, |
| 102 | Azure, |
| 103 | WatsonX, |
| 104 | OpenRouter, |
| 105 | Nvidia, |
| 106 | Vllm, |
| 107 | SambaNova, |
| 108 | MockLLM, |
| 109 | TestLLM, |
| 110 | Cerebras, |
| 111 | Asksage, |
| 112 | Nebius, |
| 113 | Venice, |
| 114 | VertexAI, |
| 115 | xAI, |
| 116 | SiliconFlow, |
| 117 | Scaleway, |
| 118 | Relace, |
| 119 | Inception, |
| 120 | Voyage, |
| 121 | ]; |
| 122 | |
| 123 | export async function llmFromDescription( |
| 124 | desc: JSONModelDescription, |
| 125 | readFile: (filepath: string) => Promise<string>, |
| 126 | uniqueId: string, |
| 127 | ideSettings: IdeSettings, |
| 128 | llmLogger: ILLMLogger, |
| 129 | completionOptions?: BaseCompletionOptions, |
| 130 | ): Promise<BaseLLM | undefined> { |
| 131 | const cls = LLMClasses.find((llm) => llm.providerName === desc.provider); |
| 132 | |
| 133 | if (!cls) { |
| 134 | return undefined; |
| 135 | } |
| 136 | |
| 137 | const finalCompletionOptions = { |
| 138 | ...completionOptions, |
| 139 | ...desc.completionOptions, |
| 140 | }; |
| 141 | |
| 142 | let baseChatSystemMessage: string | undefined = undefined; |
| 143 | if (desc.systemMessage !== undefined) { |
| 144 | baseChatSystemMessage = DEFAULT_CHAT_SYSTEM_MESSAGE; |
| 145 | baseChatSystemMessage += "\n\n"; |
| 146 | baseChatSystemMessage += await renderTemplatedString( |
| 147 | desc.systemMessage, |
| 148 | readFile, |
| 149 | {}, |
| 150 | ); |
| 151 | } |
| 152 | |
| 153 | let options: LLMOptions = { |
| 154 | ...desc, |
| 155 | completionOptions: { |
| 156 | ...finalCompletionOptions, |
| 157 | model: (desc.model || cls.defaultOptions?.model) ?? "codellama-7b", |
| 158 | maxTokens: |
| 159 | finalCompletionOptions.maxTokens ?? |
| 160 | cls.defaultOptions?.completionOptions?.maxTokens, |
| 161 | }, |
| 162 | baseChatSystemMessage, |
| 163 | baseAgentSystemMessage: baseChatSystemMessage, |
| 164 | logger: llmLogger, |
| 165 | uniqueId, |
| 166 | }; |
| 167 | |
| 168 | if (desc.provider === "continue-proxy") { |
| 169 | options.apiKey = ideSettings.userToken; |
| 170 | if (ideSettings.remoteConfigServerUrl) { |
| 171 | options.apiBase = new URL( |
| 172 | "/proxy/v1", |
| 173 | ideSettings.remoteConfigServerUrl, |
| 174 | ).toString(); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | return new cls(options); |
| 179 | } |
| 180 | |
| 181 | export function llmFromProviderAndOptions( |
| 182 | providerName: string, |
| 183 | llmOptions: LLMOptions, |
| 184 | ): ILLM { |
| 185 | const cls = LLMClasses.find((llm) => llm.providerName === providerName); |
| 186 | |
| 187 | if (!cls) { |
| 188 | throw new Error(`Unknown LLM provider type "${providerName}"`); |
| 189 | } |
| 190 | |
| 191 | return new cls(llmOptions); |
| 192 | } |