Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clients/new-js/packages/ai-embeddings/openai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface OpenAIArgs {
organizationId?: string;
dimensions?: number;
apiKey?: string;
apiBase?: string;
}

export class OpenAIEmbeddingFunction implements EmbeddingFunction {
Expand All @@ -30,6 +31,7 @@ export class OpenAIEmbeddingFunction implements EmbeddingFunction {
private readonly modelName: string;
private readonly dimensions: number | undefined;
private readonly organizationId: string | undefined;
private readonly apiBase: string | undefined;
private client: OpenAI;

constructor(args: OpenAIArgs) {
Expand All @@ -38,6 +40,7 @@ export class OpenAIEmbeddingFunction implements EmbeddingFunction {
modelName,
dimensions,
organizationId,
apiBase = "",
} = args;

const apiKey = args.apiKey || process.env[apiKeyEnvVar];
Expand All @@ -51,8 +54,9 @@ export class OpenAIEmbeddingFunction implements EmbeddingFunction {
this.organizationId = organizationId;
this.apiKeyEnvVar = apiKeyEnvVar;
this.dimensions = dimensions;
this.apiBase = apiBase;

this.client = new OpenAI({ apiKey, organization: this.organizationId });
this.client = new OpenAI({ apiKey, organization: this.organizationId, baseURL: this.apiBase });
}

public async generate(texts: string[]): Promise<number[][]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ collection = await client.getCollection({
});
```

To use the OpenAI embedding models on other platforms such as GitHub AI Models, you can use the `apiBase` parameter:
```typescript
import { OpenAIEmbeddingFunction } from "@chroma-core/openai";

const embeddingFunction = new OpenAIEmbeddingFunction({
apiKey: "apiKey",
apiBase: "https://models.github.ai/inference",
modelName: "text-embedding-3-small",
});
```


{% /Tab %}

{% /Tabs %}