Socket
Socket
Sign inDemoInstall

chromadb

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chromadb - npm Package Compare versions

Comparing version 1.7.2 to 1.7.3

15

dist/chromadb.d.ts
import * as openai from 'openai';
import * as cohere_ai from 'cohere-ai';
import * as _google_generative_ai from '@google/generative-ai';

@@ -1245,15 +1244,11 @@

declare class CohereEmbeddingFunction implements IEmbeddingFunction {
private api_key;
private cohereAiApi?;
private model;
private cohereAiApi?;
constructor({ cohere_api_key, model }: {
private apiKey;
constructor({ cohere_api_key, model, }: {
cohere_api_key: string;
model?: string;
});
private loadClient;
generate(texts: string[]): Promise<any>;
/** @ignore */
static import(): Promise<{
cohere: typeof cohere_ai;
}>;
private initCohereClient;
generate(texts: string[]): Promise<number[][]>;
}

@@ -1260,0 +1255,0 @@

{
"name": "chromadb",
"version": "1.7.2",
"version": "1.7.3",
"description": "A JavaScript interface for chroma",

@@ -80,3 +80,3 @@ "keywords": [],

"@google/generative-ai": "^0.1.1",
"cohere-ai": "^5.0.0 || ^6.0.0",
"cohere-ai": "^5.0.0 || ^6.0.0 || ^7.0.0",
"openai": "^3.0.0 || ^4.0.0"

@@ -83,0 +83,0 @@ },

@@ -27,3 +27,3 @@ ## chromadb

ids: ["test-id-" + i.toString()],
embeddings, [1, 2, 3, 4, 5],
embeddings: [1, 2, 3, 4, 5],
documents: ["test"],

@@ -30,0 +30,0 @@ });

import { IEmbeddingFunction } from "./IEmbeddingFunction";
let CohereAiApi: any;
interface CohereAIAPI {
createEmbedding: (params: {
model: string;
input: string[];
}) => Promise<number[][]>;
}
export class CohereEmbeddingFunction implements IEmbeddingFunction {
private api_key: string;
private model: string;
private cohereAiApi?: any;
class CohereAISDK56 implements CohereAIAPI {
private cohereClient: any;
private apiKey: string;
constructor({ cohere_api_key, model }: { cohere_api_key: string, model?: string }) {
// we used to construct the client here, but we need to async import the types
// for the openai npm package, and the constructor can not be async
this.api_key = cohere_api_key;
this.model = model || "large";
}
constructor(configuration: { apiKey: string }) {
this.apiKey = configuration.apiKey;
}
private async loadClient() {
if(this.cohereAiApi) return;
try {
// eslint-disable-next-line global-require,import/no-extraneous-dependencies
const { cohere } = await CohereEmbeddingFunction.import();
CohereAiApi = cohere;
CohereAiApi.init(this.api_key);
} catch (_a) {
// @ts-ignore
if (_a.code === 'MODULE_NOT_FOUND') {
throw new Error("Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`");
}
throw _a; // Re-throw other errors
}
this.cohereAiApi = CohereAiApi;
}
private async loadClient() {
if (this.cohereClient) return;
//@ts-ignore
const { default: cohere } = await import("cohere-ai");
// @ts-ignore
cohere.init(this.apiKey);
this.cohereClient = cohere;
}
public async generate(texts: string[]) {
public async createEmbedding(params: {
model: string;
input: string[];
}): Promise<number[][]> {
await this.loadClient();
return await this.cohereClient
.embed({
texts: params.input,
model: params.model,
})
.then((response: any) => {
return response.body.embeddings;
});
}
}
await this.loadClient();
class CohereAISDK7 implements CohereAIAPI {
private cohereClient: any;
private apiKey: string;
const response = await this.cohereAiApi.embed({
texts: texts,
model: this.model,
});
return response.body.embeddings;
}
constructor(configuration: { apiKey: string }) {
this.apiKey = configuration.apiKey;
}
/** @ignore */
static async import(): Promise<{
private async loadClient() {
if (this.cohereClient) return;
//@ts-ignore
const cohere = await import("cohere-ai").then((cohere) => {
return cohere;
});
// @ts-ignore
this.cohereClient = new cohere.CohereClient({
token: this.apiKey,
});
}
public async createEmbedding(params: {
model: string;
input: string[];
}): Promise<number[][]> {
await this.loadClient();
return await this.cohereClient
.embed({ texts: params.input, model: params.model })
.then((response: any) => {
return response.embeddings;
});
}
}
export class CohereEmbeddingFunction implements IEmbeddingFunction {
private cohereAiApi?: CohereAIAPI;
private model: string;
private apiKey: string;
constructor({
cohere_api_key,
model,
}: {
cohere_api_key: string;
model?: string;
}) {
this.model = model || "large";
this.apiKey = cohere_api_key;
}
private async initCohereClient() {
if (this.cohereAiApi) return;
try {
// @ts-ignore
this.cohereAiApi = await import("cohere-ai").then((cohere) => {
// @ts-ignore
cohere: typeof import("cohere-ai");
}> {
try {
// @ts-ignore
const { default: cohere } = await import("cohere-ai");
return { cohere };
} catch (e) {
throw new Error(
"Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`"
);
if (cohere.CohereClient) {
return new CohereAISDK7({ apiKey: this.apiKey });
} else {
return new CohereAISDK56({ apiKey: this.apiKey });
}
});
} catch (e) {
// @ts-ignore
if (e.code === "MODULE_NOT_FOUND") {
throw new Error(
"Please install the cohere-ai package to use the CohereEmbeddingFunction, `npm install -S cohere-ai`"
);
}
throw e;
}
}
public async generate(texts: string[]): Promise<number[][]> {
await this.initCohereClient();
// @ts-ignore
return await this.cohereAiApi.createEmbedding({
model: this.model,
input: texts,
});
}
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc