| 1 | import { LLMOptions } from "../../index.js"; |
| 2 | |
| 3 | import OpenAI from "./OpenAI.js"; |
| 4 | |
| 5 | class DeepInfra extends OpenAI { |
| 6 | static providerName = "deepinfra"; |
| 7 | static defaultOptions: Partial<LLMOptions> = { |
| 8 | apiBase: "https://api.deepinfra.com/v1/openai/", |
| 9 | }; |
| 10 | maxStopWords: number | undefined = 16; |
| 11 | |
| 12 | protected async _embed(chunks: string[]): Promise<number[][]> { |
| 13 | const resp = await this.fetch( |
| 14 | `https://api.deepinfra.com/v1/inference/${this.model}`, |
| 15 | { |
| 16 | method: "POST", |
| 17 | headers: { |
| 18 | Authorization: `bearer ${this.apiKey}`, |
| 19 | }, |
| 20 | body: JSON.stringify({ inputs: chunks }), |
| 21 | }, |
| 22 | ); |
| 23 | |
| 24 | const data = await resp.json(); |
| 25 | return data.embeddings; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | export default DeepInfra; |