Skip to content

Commit

Permalink
🎨 refactoring for continue-proxy LLM (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
sestinj committed Jun 23, 2024
1 parent b3acdbd commit 26553cb
Show file tree
Hide file tree
Showing 14 changed files with 219 additions and 431 deletions.
3 changes: 3 additions & 0 deletions core/continueServer/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export interface EmbeddingsCacheResponse<T extends ArtifactType> {
}

export interface IContinueServerClient {
connected: boolean;
url: URL | undefined;
getUserToken(): Promise<string | undefined>;
getConfig(): Promise<{ configJson: string; configJs: string }>;
getFromIndexCache<T extends ArtifactType>(
keys: string[],
Expand Down
22 changes: 20 additions & 2 deletions core/continueServer/stubs/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,28 @@ import type {
} from "../interface.js";

export class ContinueServerClient implements IContinueServerClient {
url: URL | undefined;

constructor(
private readonly serverUrl: string,
serverUrl: string | undefined,
private readonly userToken: Promise<string | undefined>,
) {}
) {
try {
this.url =
typeof serverUrl !== "string" || serverUrl === ""
? undefined
: new URL(serverUrl);
} catch (e) {
console.warn("Invalid Continue server url", e);
this.url = undefined;
}
}

getUserToken(): Promise<string | undefined> {
return this.userToken;
}

connected: boolean = false;

public async getConfig(): Promise<{ configJson: string; configJs: string }> {
throw new Error("Not Implemented");
Expand Down
1 change: 1 addition & 0 deletions core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ type ModelProvider =
| "deepinfra"
| "flowise"
| "groq"
| "continue-proxy"
| "custom";

export type ModelName =
Expand Down
10 changes: 5 additions & 5 deletions core/indexing/LanceDbIndex.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// NOTE: vectordb requirement must be listed in extensions/vscode to avoid error
import { v4 as uuidv4 } from "uuid";
import type { Table } from "vectordb";
import type {
import { Table } from "vectordb";
import { IContinueServerClient } from "../continueServer/interface.js";
import {
BranchAndDir,
Chunk,
EmbeddingsProvider,
IndexTag,
IndexingProgressUpdate,
} from "../index.js";
import { ContinueServerClient } from "../continueServer/stubs/client.js";
import { MAX_CHUNK_SIZE } from "../llm/constants.js";
import { getBasename } from "../util/index.js";
import { getLanceDbPath } from "../util/paths.js";
Expand Down Expand Up @@ -39,7 +39,7 @@ export class LanceDbIndex implements CodebaseIndex {
constructor(
private readonly embeddingsProvider: EmbeddingsProvider,
private readonly readFile: (filepath: string) => Promise<string>,
private readonly continueServerClient?: ContinueServerClient,
private readonly continueServerClient: IContinueServerClient,
) {}

private tableNameForTag(tag: IndexTag) {
Expand Down Expand Up @@ -175,7 +175,7 @@ export class LanceDbIndex implements CodebaseIndex {
};

// Check remote cache
if (this.continueServerClient !== undefined) {
if (this.continueServerClient.connected) {
try {
const keys = results.compute.map(({ cacheKey }) => cacheKey);
const resp = await this.continueServerClient.getFromIndexCache(
Expand Down
6 changes: 3 additions & 3 deletions core/indexing/chunk/ChunkCodebaseIndex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IContinueServerClient } from "../../continueServer/interface.js";
import { Chunk, IndexTag, IndexingProgressUpdate } from "../../index.js";
import { ContinueServerClient } from "../../continueServer/stubs/client.js";
import { MAX_CHUNK_SIZE } from "../../llm/constants.js";
import { getBasename } from "../../util/index.js";
import { DatabaseConnection, SqliteDb, tagToString } from "../refreshIndex.js";
Expand All @@ -22,7 +22,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex {

constructor(
private readonly readFile: (filepath: string) => Promise<string>,
private readonly continueServerClient?: ContinueServerClient,
private readonly continueServerClient: IContinueServerClient,
) {
this.readFile = readFile;
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
}

// Check the remote cache
if (this.continueServerClient !== undefined) {
if (this.continueServerClient.connected) {
try {
const keys = results.compute.map(({ cacheKey }) => cacheKey);
const resp = await this.continueServerClient.getFromIndexCache(
Expand Down
17 changes: 4 additions & 13 deletions core/indexing/indexCodebase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IDE, IndexTag, IndexingProgressUpdate } from "../index.js";
import { ConfigHandler } from "../config/handler.js";
import { ContinueServerClient } from "../continueServer/stubs/client.js";
import { IContinueServerClient } from "../continueServer/interface.js";
import { IDE, IndexTag, IndexingProgressUpdate } from "../index.js";
import { CodeSnippetsCodebaseIndex } from "./CodeSnippetsIndex.js";
import { FullTextSearchCodebaseIndex } from "./FullTextSearch.js";
import { LanceDbIndex } from "./LanceDbIndex.js";
Expand All @@ -21,21 +21,12 @@ export class PauseToken {
}

export class CodebaseIndexer {
private continueServerClient?: ContinueServerClient;
constructor(
private readonly configHandler: ConfigHandler,
private readonly ide: IDE,
private readonly pauseToken: PauseToken,
private readonly continueServerUrl: string | undefined,
private readonly userToken: string | undefined,
) {
if (this.continueServerUrl) {
this.continueServerClient = new ContinueServerClient(
this.continueServerUrl,
Promise.resolve(this.userToken),
);
}
}
private readonly continueServerClient: IContinueServerClient,
) {}

private async getIndexesToBuild(): Promise<CodebaseIndex[]> {
const config = await this.configHandler.loadConfig();
Expand Down
2 changes: 2 additions & 0 deletions core/llm/autodetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const PROVIDER_HANDLES_TEMPLATING: ModelProvider[] = [
"together",
"anthropic",
"bedrock",
"continue-proxy",
];

const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [
Expand All @@ -50,6 +51,7 @@ const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [
"free-trial",
"anthropic",
"bedrock",
"continue-proxy",
];

const MODEL_SUPPORTS_IMAGES: string[] = [
Expand Down
44 changes: 23 additions & 21 deletions core/llm/llms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import OpenAIFreeTrial from "./OpenAIFreeTrial.js";
import Replicate from "./Replicate.js";
import TextGenWebUI from "./TextGenWebUI.js";
import Together from "./Together.js";
import ContinueProxy from "./stubs/ContinueProxy.js";

function convertToLetter(num: number): string {
let result = "";
Expand Down Expand Up @@ -76,26 +77,27 @@ export async function renderTemplatedString(
}

const LLMs = [
Anthropic,
Cohere,
FreeTrial,
Gemini,
Llamafile,
Ollama,
Replicate,
TextGenWebUI,
Together,
HuggingFaceTGI,
HuggingFaceInferenceAPI,
LlamaCpp,
OpenAI,
LMStudio,
Mistral,
Bedrock,
DeepInfra,
OpenAIFreeTrial,
Flowise,
Groq,
Anthropic,
Cohere,
FreeTrial,
Gemini,
Llamafile,
Ollama,
Replicate,
TextGenWebUI,
Together,
HuggingFaceTGI,
HuggingFaceInferenceAPI,
LlamaCpp,
OpenAI,
LMStudio,
Mistral,
Bedrock,
DeepInfra,
OpenAIFreeTrial,
Flowise,
Groq,
ContinueProxy,
];

export async function llmFromDescription(
Expand Down Expand Up @@ -134,7 +136,7 @@ export async function llmFromDescription(
},
systemMessage,
writeLog,
uniqueId
uniqueId,
};

return new cls(options);
Expand Down
5 changes: 1 addition & 4 deletions core/llm/llms/stubs/ContinueProxy.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { LLMOptions, ModelProvider } from "../../..";
import { ModelProvider } from "../../..";
import OpenAI from "../OpenAI";

class ContinueProxy extends OpenAI {
static providerName: ModelProvider = "continue-proxy";
static defaultOptions: Partial<LLMOptions> = {
apiBase: "http://localhost:3000/proxy/v1",
};
}

export default ContinueProxy;
6 changes: 4 additions & 2 deletions docs/static/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"mistral",
"deepinfra",
"flowise",
"groq"
"groq",
"continue-proxy"
],
"markdownEnumDescriptions": [
"### OpenAI\nUse gpt-4, gpt-3.5-turbo, or any other OpenAI model. See [here](https://openai.com/product#made-for-developers) to obtain an API key.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/openai)",
Expand All @@ -174,7 +175,8 @@
"### LMStudio\nLMStudio provides a professional and well-designed GUI for exploring, configuring, and serving LLMs. It is available on both Mac and Windows. To get started:\n1. Download from [lmstudio.ai](https://lmstudio.ai/) and open the application\n2. Search for and download the desired model from the home screen of LMStudio.\n3. In the left-bar, click the '<->' icon to open the Local Inference Server and press 'Start Server'.\n4. Once your model is loaded and the server has started, you can begin using Continue.\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/lmstudio)",
"### Llamafile\nTo get started with llamafiles, find and download a binary on their [GitHub repo](https://github.com/Mozilla-Ocho/llamafile#binary-instructions). Then run it with the following command:\n\n```shell\nchmod +x ./llamafile\n./llamafile\n```\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/llamafile)",
"### Mistral API\n\nTo get access to the Mistral API, obtain your API key from the [Mistral platform](https://docs.mistral.ai/)",
"### DeepInfra\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/deepinfra)"
"### DeepInfra\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/deepinfra)",
"### Continue Proxy\n\nContinue Enterprise users can use the Continue Proxy as a single point of access to models."
],
"type": "string"
},
Expand Down
6 changes: 4 additions & 2 deletions extensions/intellij/src/main/resources/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"mistral",
"deepinfra",
"flowise",
"groq"
"groq",
"continue-proxy"
],
"markdownEnumDescriptions": [
"### OpenAI\nUse gpt-4, gpt-3.5-turbo, or any other OpenAI model. See [here](https://openai.com/product#made-for-developers) to obtain an API key.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/openai)",
Expand All @@ -174,7 +175,8 @@
"### LMStudio\nLMStudio provides a professional and well-designed GUI for exploring, configuring, and serving LLMs. It is available on both Mac and Windows. To get started:\n1. Download from [lmstudio.ai](https://lmstudio.ai/) and open the application\n2. Search for and download the desired model from the home screen of LMStudio.\n3. In the left-bar, click the '<->' icon to open the Local Inference Server and press 'Start Server'.\n4. Once your model is loaded and the server has started, you can begin using Continue.\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/lmstudio)",
"### Llamafile\nTo get started with llamafiles, find and download a binary on their [GitHub repo](https://github.com/Mozilla-Ocho/llamafile#binary-instructions). Then run it with the following command:\n\n```shell\nchmod +x ./llamafile\n./llamafile\n```\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/llamafile)",
"### Mistral API\n\nTo get access to the Mistral API, obtain your API key from the [Mistral platform](https://docs.mistral.ai/)",
"### DeepInfra\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/deepinfra)"
"### DeepInfra\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/deepinfra)",
"### Continue Proxy\n\nContinue Enterprise users can use the Continue Proxy as a single point of access to models."
],
"type": "string"
},
Expand Down
6 changes: 4 additions & 2 deletions extensions/vscode/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
"mistral",
"deepinfra",
"flowise",
"groq"
"groq",
"continue-proxy"
],
"markdownEnumDescriptions": [
"### OpenAI\nUse gpt-4, gpt-3.5-turbo, or any other OpenAI model. See [here](https://openai.com/product#made-for-developers) to obtain an API key.\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/openai)",
Expand All @@ -174,7 +175,8 @@
"### LMStudio\nLMStudio provides a professional and well-designed GUI for exploring, configuring, and serving LLMs. It is available on both Mac and Windows. To get started:\n1. Download from [lmstudio.ai](https://lmstudio.ai/) and open the application\n2. Search for and download the desired model from the home screen of LMStudio.\n3. In the left-bar, click the '<->' icon to open the Local Inference Server and press 'Start Server'.\n4. Once your model is loaded and the server has started, you can begin using Continue.\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/lmstudio)",
"### Llamafile\nTo get started with llamafiles, find and download a binary on their [GitHub repo](https://github.com/Mozilla-Ocho/llamafile#binary-instructions). Then run it with the following command:\n\n```shell\nchmod +x ./llamafile\n./llamafile\n```\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/llamafile)",
"### Mistral API\n\nTo get access to the Mistral API, obtain your API key from the [Mistral platform](https://docs.mistral.ai/)",
"### DeepInfra\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/deepinfra)"
"### DeepInfra\n\n> [Reference](https://docs.continue.dev/reference/Model%20Providers/deepinfra)",
"### Continue Proxy\n\nContinue Enterprise users can use the Continue Proxy as a single point of access to models."
],
"type": "string"
},
Expand Down
Loading

0 comments on commit 26553cb

Please sign in to comment.