continue-custom/core/indexing/embeddings/DeepInfraEmbeddingsProvider.ts
Nate Sesti ff821ff159
OpenAI Adapters (#1859)
* embeddings support in openai-adapters

* rerank support in openai-adapters

* cohere embed/rerank

* continue-proxy reranker and embeddings providers

* test for openai-adapters

* embeddings provider and reranker for continue proxy
2024-07-28 18:22:37 -07:00

31 lines
1 KiB
TypeScript

import { EmbeddingsProviderName, EmbedOptions } from "../../index.js";
import { withExponentialBackoff } from "../../util/withExponentialBackoff.js";
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js";
class DeepInfraEmbeddingsProvider extends BaseEmbeddingsProvider {
static providerName: EmbeddingsProviderName = "deepinfra";
static defaultOptions: Partial<EmbedOptions> | undefined = {
model: "sentence-transformers/all-MiniLM-L6-v2",
};
async embed(chunks: string[]) {
const fetchWithBackoff = () =>
withExponentialBackoff<Response>(() =>
this.fetch(
`https://api.deepinfra.com/v1/inference/${this.options.model}`,
{
method: "POST",
headers: {
Authorization: `bearer ${this.options.apiKey}`,
},
body: JSON.stringify({ inputs: chunks }),
},
),
);
const resp = await fetchWithBackoff();
const data = await resp.json();
return data.embeddings;
}
}
export default DeepInfraEmbeddingsProvider;