first take relace provider

This commit is contained in:
Nate 2025-03-19 11:03:16 -07:00
parent 9889b469dd
commit 2f8d4901fd
11 changed files with 184 additions and 66 deletions

View file

@ -58,6 +58,7 @@ const PROVIDER_HANDLES_TEMPLATING: string[] = [
"vertexai",
"watsonx",
"nebius",
"relace",
];
const PROVIDER_SUPPORTS_IMAGES: string[] = [

12
core/llm/llms/Relace.ts Normal file
View file

@ -0,0 +1,12 @@
import { LLMOptions } from "../..";
import { LlmApiRequestType } from "../openaiTypeConverters";
import OpenAI from "./OpenAI";
export class Relace extends OpenAI {
static providerName = "relace";
static defaultOptions: Partial<LLMOptions> | undefined = {
apiBase: "https://instantapply.endpoint.relace.run/v1/code/apply",
};
protected useOpenAIAdapterFor: (LlmApiRequestType | "*")[] = ["*"];
}

View file

@ -19,7 +19,6 @@ import Cohere from "./Cohere";
import DeepInfra from "./DeepInfra";
import Deepseek from "./Deepseek";
import Fireworks from "./Fireworks";
import NCompass from "./NCompass";
import Flowise from "./Flowise";
import FreeTrial from "./FreeTrial";
import FunctionNetwork from "./FunctionNetwork";
@ -35,11 +34,14 @@ import Mistral from "./Mistral";
import MockLLM from "./Mock";
import Moonshot from "./Moonshot";
import Msty from "./Msty";
import NCompass from "./NCompass";
import Nebius from "./Nebius";
import Novita from "./Novita";
import Nvidia from "./Nvidia";
import Ollama from "./Ollama";
import OpenAI from "./OpenAI";
import OpenRouter from "./OpenRouter";
import { Relace } from "./Relace";
import Replicate from "./Replicate";
import SageMaker from "./SageMaker";
import SambaNova from "./SambaNova";
@ -49,7 +51,6 @@ import ContinueProxy from "./stubs/ContinueProxy";
import TestLLM from "./Test";
import TextGenWebUI from "./TextGenWebUI";
import Together from "./Together";
import Novita from "./Novita";
import VertexAI from "./VertexAI";
import Vllm from "./Vllm";
import WatsonX from "./WatsonX";
@ -102,6 +103,7 @@ export const LLMClasses = [
xAI,
SiliconFlow,
Scaleway,
Relace,
];
export async function llmFromDescription(

81
core/package-lock.json generated
View file

@ -16,7 +16,7 @@
"@continuedev/config-yaml": "^1.0.63",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.2",
"@continuedev/openai-adapters": "^1.0.10",
"@continuedev/openai-adapters": "file:../packages/openai-adapters",
"@modelcontextprotocol/sdk": "^1.5.0",
"@mozilla/readability": "^0.5.0",
"@octokit/rest": "^20.1.1",
@ -106,6 +106,28 @@
"node": ">=20.11.0"
}
},
"../packages/openai-adapters": {
"name": "@continuedev/openai-adapters",
"version": "1.0.16",
"license": "Apache-2.0",
"dependencies": {
"@azure/openai": "^1.0.0-beta.12",
"@continuedev/config-types": "^1.0.5",
"@continuedev/config-yaml": "^1.0.51",
"@continuedev/fetch": "^1.0.3",
"json-schema": "^0.4.0",
"node-fetch": "^3.3.2",
"openai": "^4.76.0",
"zod": "^3.24.2"
},
"devDependencies": {
"@types/follow-redirects": "^1.14.4",
"@types/json-schema": "^7.0.15",
"cross-env": "^7.0.3",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.2"
}
},
"node_modules/@75lb/deep-merge": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/@75lb/deep-merge/-/deep-merge-1.1.2.tgz",
@ -894,22 +916,6 @@
}
}
},
"node_modules/@azure-rest/core-client": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/@azure-rest/core-client/-/core-client-1.4.0.tgz",
"integrity": "sha512-ozTDPBVUDR5eOnMIwhggbnVmOrka4fXCs8n8mvUo4WLLc38kki6bAOByDoVZZPz/pZy2jMt2kwfpvy/UjALj6w==",
"dependencies": {
"@azure/abort-controller": "^2.0.0",
"@azure/core-auth": "^1.3.0",
"@azure/core-rest-pipeline": "^1.5.0",
"@azure/core-tracing": "^1.0.1",
"@azure/core-util": "^1.0.0",
"tslib": "^2.6.2"
},
"engines": {
"node": ">=18.0.0"
}
},
"node_modules/@azure/abort-controller": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.1.2.tgz",
@ -1007,17 +1013,6 @@
"node": ">=18.0.0"
}
},
"node_modules/@azure/core-sse": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/@azure/core-sse/-/core-sse-2.1.3.tgz",
"integrity": "sha512-KSSdIKy8kvWCpYr8Hzpu22j3wcXsVTYE0IlgmI1T/aHvBDsLgV91y90UTfVWnuiuApRLCCVC4gS09ApBGOmYQA==",
"dependencies": {
"tslib": "^2.6.2"
},
"engines": {
"node": ">=18.0.0"
}
},
"node_modules/@azure/core-tracing": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@azure/core-tracing/-/core-tracing-1.2.0.tgz",
@ -1156,23 +1151,6 @@
"uuid": "dist/bin/uuid"
}
},
"node_modules/@azure/openai": {
"version": "1.0.0-beta.13",
"resolved": "https://registry.npmjs.org/@azure/openai/-/openai-1.0.0-beta.13.tgz",
"integrity": "sha512-oHE5ScnPTXALmyEBgqokZlYVT7F76EfrKjMWF+YcFJdUxk9Adhvht2iL5v+QpmlAIMdkih1q8DkTs/tApDjBpw==",
"dependencies": {
"@azure-rest/core-client": "^1.1.7",
"@azure/core-auth": "^1.4.0",
"@azure/core-rest-pipeline": "^1.13.0",
"@azure/core-sse": "^2.0.0",
"@azure/core-util": "^1.4.0",
"@azure/logger": "^1.0.3",
"tslib": "^2.4.0"
},
"engines": {
"node": ">=18.0.0"
}
},
"node_modules/@babel/code-frame": {
"version": "7.26.2",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz",
@ -2999,17 +2977,8 @@
"integrity": "sha512-MyYmP4tbTzOnlT6hItC9tFkVZpYkaAg45AUXqdXzEfZhz8ZWpaiN8jZ789KLVmq+NKqhMUbKAHIZUUY1d39eRw=="
},
"node_modules/@continuedev/openai-adapters": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/@continuedev/openai-adapters/-/openai-adapters-1.0.10.tgz",
"integrity": "sha512-hTiCxlXsek/jpVbtHDQCe4JnCmJ+jbye9ionXCDmg9oAKKEymW1UVVrX08xcdCkfKnxAP2ESgqFSMok314q+fg==",
"dependencies": {
"@azure/openai": "^1.0.0-beta.12",
"@continuedev/config-types": "^1.0.5",
"@continuedev/fetch": "^1.0.3",
"node-fetch": "^3.3.2",
"openai": "^4.76.0",
"zod": "^3.23.8"
}
"resolved": "../packages/openai-adapters",
"link": true
},
"node_modules/@esbuild/android-arm": {
"version": "0.17.19",

View file

@ -49,7 +49,7 @@
"@continuedev/config-yaml": "^1.0.63",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.2",
"@continuedev/openai-adapters": "^1.0.10",
"@continuedev/openai-adapters": "file:../packages/openai-adapters",
"@modelcontextprotocol/sdk": "^1.5.0",
"@mozilla/readability": "^0.5.0",
"@octokit/rest": "^20.1.1",

View file

@ -215,7 +215,8 @@
"moonshot",
"siliconflow",
"function-network",
"scaleway"
"scaleway",
"relace"
],
"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)",
@ -261,7 +262,8 @@
"### Moonshot\nTo get started with Moonshot AI, obtain your API key from [Moonshot AI](https://platform.moonshot.cn/). Moonshot AI provides high-quality large language models with competitive pricing.\n> [Reference](https://platform.moonshot.cn/docs/api)",
"### SiliconFlow\nTo get started with SiliconFlow, obtain your API key from [SiliconCloud](https://cloud.siliconflow.cn/account/ak). SiliconCloud provides cost-effective GenAI services based on excellent open source basic models.\n> [Models](https://siliconflow.cn/zh-cn/models)",
"### Function Network offers private, affordable user-owned AI\nTo get started with Function Network, obtain your API key from [Function Network](https://www.function.network/join-waitlist). Function Network provides a variety of models for chat, completion, and embeddings.",
"### Scaleway\n Generative APIs are serverless endpoints for the most popular AI models.\nHosted in European data centers and priced competitively per million tokens used, models served by Scaleway are ideal for users requiring low latency, full data privacy, and 100% compliance with EU AI Act. To get access to the Scaleway Generative APIs, read the [Quickstart guide](https://www.scaleway.com/en/docs/ai-data/generative-apis/quickstart/) and get a [valid API key](https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/)."
"### Scaleway\n Generative APIs are serverless endpoints for the most popular AI models.\nHosted in European data centers and priced competitively per million tokens used, models served by Scaleway are ideal for users requiring low latency, full data privacy, and 100% compliance with EU AI Act. To get access to the Scaleway Generative APIs, read the [Quickstart guide](https://www.scaleway.com/en/docs/ai-data/generative-apis/quickstart/) and get a [valid API key](https://www.scaleway.com/en/docs/identity-and-access-management/iam/how-to/create-api-keys/).",
"### Relace\n Relace provides a fast apply model. To get started, obtain an API key from [here](https://app.relace.ai/settings/api-keys)."
],
"type": "string"
},

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "1.1.11",
"version": "1.1.12",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "1.1.11",
"version": "1.1.12",
"license": "Apache-2.0",
"dependencies": {
"@continuedev/fetch": "^1.0.3",
@ -106,10 +106,10 @@
"@aws-sdk/client-sagemaker-runtime": "^3.758.0",
"@aws-sdk/credential-providers": "^3.758.0",
"@continuedev/config-types": "^1.0.13",
"@continuedev/config-yaml": "^1.0.60",
"@continuedev/config-yaml": "^1.0.63",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.2",
"@continuedev/openai-adapters": "^1.0.10",
"@continuedev/openai-adapters": "file:../packages/openai-adapters",
"@modelcontextprotocol/sdk": "^1.5.0",
"@mozilla/readability": "^0.5.0",
"@octokit/rest": "^20.1.1",

2
gui/package-lock.json generated
View file

@ -110,7 +110,7 @@
"@continuedev/config-yaml": "^1.0.63",
"@continuedev/fetch": "^1.0.4",
"@continuedev/llm-info": "^1.0.2",
"@continuedev/openai-adapters": "^1.0.10",
"@continuedev/openai-adapters": "file:../packages/openai-adapters",
"@modelcontextprotocol/sdk": "^1.5.0",
"@mozilla/readability": "^0.5.0",
"@octokit/rest": "^20.1.1",

View file

@ -0,0 +1,128 @@
import {
Completion,
CompletionCreateParamsNonStreaming,
CompletionCreateParamsStreaming,
} from "openai/resources/completions.mjs";
import {
CreateEmbeddingResponse,
EmbeddingCreateParams,
} from "openai/resources/embeddings.mjs";
import {
ChatCompletion,
ChatCompletionChunk,
ChatCompletionCreateParamsNonStreaming,
ChatCompletionCreateParamsStreaming,
} from "openai/resources/index.mjs";
import { Model } from "openai/resources/models.mjs";
import { z } from "zod";
import { OpenAIConfigSchema } from "../types.js";
import { chatChunk, customFetch } from "../util.js";
import {
BaseLlmApi,
CreateRerankResponse,
FimCreateParamsStreaming,
RerankCreateParams,
} from "./base.js";
// Relace only supports apply through a /v1/apply endpoint
export class RelaceApi implements BaseLlmApi {
private apiBase = "https://instantapply.endpoint.relace.run/v1/code/apply";
constructor(private readonly config: z.infer<typeof OpenAIConfigSchema>) {
this.apiBase = config.apiBase ?? this.apiBase;
this.config = config;
}
chatCompletionNonStream(
body: ChatCompletionCreateParamsNonStreaming,
signal: AbortSignal,
): Promise<ChatCompletion> {
throw new Error(
"Relace provider does not support non-streaming chat completion.",
);
}
// We convert from what would be sent to OpenAI (a prediction for the existing code and a user message with the new code)
// to Relace's format
async *chatCompletionStream(
body: ChatCompletionCreateParamsStreaming,
signal: AbortSignal,
): AsyncGenerator<ChatCompletionChunk> {
const fetch = customFetch(this.config.requestOptions);
const headers = {
"Content-Type": "application/json",
Authorization: `Bearer ${this.config.apiKey}`,
};
const prediction = body.prediction?.content ?? "";
const initialCode =
typeof prediction === "string"
? prediction
: prediction.map((p) => p.text).join("");
const userContent = body.messages.find((m) => m.role === "user")?.content;
if (!userContent) {
throw new Error("No edit snippet provided.");
}
const editSnippet =
typeof userContent === "string"
? userContent
: userContent
.filter((p) => p.type === "text")
.map((p) => p.text)
.join("");
const data = {
initialCode,
editSnippet,
};
const response = await fetch(this.apiBase, {
method: "POST",
headers,
body: JSON.stringify(data),
signal,
});
const result = (await response.json()) as any;
const mergedCode = result.mergedCode;
yield chatChunk({
content: mergedCode,
model: body.model,
});
}
completionNonStream(
body: CompletionCreateParamsNonStreaming,
signal: AbortSignal,
): Promise<Completion> {
throw new Error(
"Relace provider does not support non-streaming completion.",
);
}
completionStream(
body: CompletionCreateParamsStreaming,
signal: AbortSignal,
): AsyncGenerator<Completion> {
throw new Error("Relace provider does not support streaming completion.");
}
fimStream(
body: FimCreateParamsStreaming,
signal: AbortSignal,
): AsyncGenerator<ChatCompletionChunk> {
throw new Error(
"Relace provider does not support streaming FIM completion.",
);
}
embed(body: EmbeddingCreateParams): Promise<CreateEmbeddingResponse> {
throw new Error("Relace provider does not support embeddings.");
}
rerank(body: RerankCreateParams): Promise<CreateRerankResponse> {
throw new Error("Relace provider does not support reranking.");
}
list(): Promise<Model[]> {
throw new Error("Relace provider does not support model listing.");
}
}

View file

@ -10,6 +10,7 @@ import { JinaApi } from "./apis/Jina.js";
import { MockApi } from "./apis/Mock.js";
import { MoonshotApi } from "./apis/Moonshot.js";
import { OpenAIApi } from "./apis/OpenAI.js";
import { RelaceApi } from "./apis/Relace.js";
import { LLMConfig, OpenAIConfigSchema } from "./types.js";
dotenv.config();
@ -42,6 +43,8 @@ export function constructLlmApi(config: LLMConfig): BaseLlmApi | undefined {
return new DeepSeekApi(config);
case "moonshot":
return new MoonshotApi(config);
case "relace":
return new RelaceApi(config);
case "x-ai":
return openAICompatible("https://api.x.ai/v1/", config);
case "voyage":

View file

@ -55,6 +55,7 @@ export const OpenAIConfigSchema = BasePlusConfig.extend({
z.literal("x-ai"),
z.literal("scaleway"),
z.literal("ncompass"),
z.literal("relace"),
]),
});
export type OpenAIConfig = z.infer<typeof OpenAIConfigSchema>;