Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@singlestore/ai

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@singlestore/ai - npm Package Compare versions

Comparing version 0.0.15 to 0.0.16

80

dist/index.d.ts
import { ChatCompletionMessageParam } from 'openai/resources/chat/completions';
import { OpenAI } from 'openai';
import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions.mjs';
import { EmbeddingCreateParams } from 'openai/resources/embeddings';

@@ -7,58 +9,62 @@ type ChatCompletionChunk = string;

type ChatCompletionMessage = ChatCompletionMessageParam;
interface CreateChatCompletionOptions<T = any> {
model: T | (string & {});
systemRole: string;
stream: boolean;
history: ChatCompletionMessage[];
interface CreateChatCompletionOptions {
model?: string;
systemRole?: string;
stream?: boolean;
history?: ChatCompletionMessage[];
}
type CreateChatCompletionResult<T = any> = T extends {
type CreateChatCompletionResult<T extends CreateChatCompletionOptions = CreateChatCompletionOptions> = T extends {
stream: true;
} ? ChatCompletionStream : string;
type OnChatCompletionStreamChunk = (chunk: ChatCompletionChunk) => Promise<void> | void;
interface ChatCompletions {
getModels(): string[];
declare abstract class ChatCompletions {
abstract getModels(): Promise<string[]> | string[];
handleStream(stream: ChatCompletionStream, onChunk?: OnChatCompletionStreamChunk): Promise<string>;
create<T extends Partial<CreateChatCompletionOptions>>(prompt: string, options?: T): Promise<CreateChatCompletionResult<T>>;
abstract create(prompt: string, options?: CreateChatCompletionOptions): Promise<CreateChatCompletionResult>;
}
type _OpenAICreateChatCompletionOptions = Omit<Partial<ChatCompletionCreateParamsBase>, keyof CreateChatCompletionOptions>;
type OpenAIChatCompletionModel = ChatCompletionCreateParamsBase["model"];
interface OpenAICreateChatCompletionOptions extends CreateChatCompletionOptions, _OpenAICreateChatCompletionOptions {
model?: OpenAIChatCompletionModel;
}
declare class OpenAIChatCompletions extends ChatCompletions {
private _openai;
constructor(_openai: OpenAI);
getModels(): OpenAIChatCompletionModel[];
create<T extends OpenAICreateChatCompletionOptions>(prompt: string, options?: T): Promise<CreateChatCompletionResult<T>>;
}
type Embedding = number[];
interface CreateEmbeddingsOptions<T = any> {
model: T | (string & {});
interface CreateEmbeddingsOptions {
model?: string;
}
interface Embeddings {
getModels(): string[];
create<T extends Partial<CreateEmbeddingsOptions>>(input: string | string[], options?: T): Promise<Embedding[]>;
declare abstract class Embeddings {
abstract getModels(): string[];
abstract create(input: string | string[], options?: CreateEmbeddingsOptions): Promise<Embedding[]>;
}
type OpenAIstring = "gpt-4o" | "gpt-4o-2024-05-13" | "gpt-4o-2024-08-06" | "gpt-4o-mini" | "gpt-4o-mini-2024-07-18" | "gpt-4-turbo" | "gpt-4-turbo-2024-04-09" | "gpt-4-turbo-preview" | "gpt-4-0125-preview" | "gpt-4-1106-preview" | "gpt-4" | "gpt-4-0613" | "gpt-3.5-turbo-0125" | "gpt-3.5-turbo" | "gpt-3.5-turbo-1106" | "gpt-3.5-turbo-instruct";
type CreateOpenAIChatCompletionOptions = CreateChatCompletionOptions<OpenAIstring> & Omit<Parameters<OpenAI["chat"]["completions"]["create"]>[0], keyof CreateChatCompletionOptions>;
declare class OpenAIChatCompletions implements ChatCompletions {
private _openai;
constructor(_openai: OpenAI);
getModels(): OpenAIstring[];
create<T extends Partial<CreateOpenAIChatCompletionOptions>>(prompt: string, options?: T): Promise<CreateChatCompletionResult<T>>;
handleStream(stream: ChatCompletionStream, onChunk?: OnChatCompletionStreamChunk): Promise<string>;
type _OpenAICreateEmbeddingsOptions = Omit<Partial<EmbeddingCreateParams>, "input" | keyof CreateEmbeddingsOptions>;
type OpenAIEmbeddingModel = EmbeddingCreateParams["model"];
interface OpenAICreateEmbeddingsOptions extends CreateEmbeddingsOptions, _OpenAICreateEmbeddingsOptions {
model?: OpenAIEmbeddingModel;
}
type OpenAIEmbeddingModel = "text-embedding-3-small" | "text-embedding-3-large" | "text-embedding-ada-002";
type OpenAIChatEmbeddingsCreateOptions = CreateEmbeddingsOptions<OpenAIEmbeddingModel> & Omit<Parameters<OpenAI["embeddings"]["create"]>[0], "input" | keyof CreateEmbeddingsOptions>;
declare class OpenAIEmbeddings implements Embeddings {
declare class OpenAIEmbeddings extends Embeddings {
private _openai;
constructor(_openai: OpenAI);
getModels(): OpenAIEmbeddingModel[];
create<T extends Partial<OpenAIChatEmbeddingsCreateOptions>>(input: string | string[], options?: T): Promise<Embedding[]>;
create<T extends OpenAICreateEmbeddingsOptions>(input: string | string[], options?: T): Promise<Embedding[]>;
}
type AIConfig<T extends Embeddings, U extends ChatCompletions> = {
embeddings?: T;
chatCompletions?: U;
interface AIConfig {
embeddings?: Embeddings;
chatCompletions?: ChatCompletions;
openAIApiKey?: string;
};
type AIBase = AI<Embeddings, ChatCompletions>;
declare class AI<T extends Embeddings = OpenAIEmbeddings, U extends ChatCompletions = OpenAIChatCompletions> {
embeddings: T;
chatCompletions: U;
constructor(config: AIConfig<T, U>);
}
declare class AI<T extends AIConfig = AIConfig> {
embeddings: T["embeddings"] extends Embeddings ? T["embeddings"] : OpenAIEmbeddings;
chatCompletions: T["chatCompletions"] extends ChatCompletions ? T["chatCompletions"] : OpenAIChatCompletions;
constructor(config: T);
}
export { AI, type AIBase, type AIConfig, type ChatCompletionChunk, type ChatCompletionMessage, type ChatCompletionStream, type ChatCompletions, type CreateChatCompletionOptions, type CreateChatCompletionResult, type CreateEmbeddingsOptions, type CreateOpenAIChatCompletionOptions, type Embedding, type Embeddings, type OnChatCompletionStreamChunk, OpenAIChatCompletions, type OpenAIChatEmbeddingsCreateOptions, type OpenAIEmbeddingModel, OpenAIEmbeddings, type OpenAIstring };
export { AI, type AIConfig, type ChatCompletionChunk, type ChatCompletionMessage, type ChatCompletionStream, ChatCompletions, type CreateChatCompletionOptions, type CreateChatCompletionResult, type CreateEmbeddingsOptions, type Embedding, Embeddings, type OnChatCompletionStreamChunk, type OpenAIChatCompletionModel, OpenAIChatCompletions, type OpenAICreateChatCompletionOptions, type OpenAICreateEmbeddingsOptions, type OpenAIEmbeddingModel, OpenAIEmbeddings };

@@ -23,3 +23,5 @@ "use strict";

__export(src_exports, {
AI: () => AI
AI: () => AI,
ChatCompletions: () => ChatCompletions,
Embeddings: () => Embeddings
});

@@ -29,5 +31,18 @@ module.exports = __toCommonJS(src_exports);

// src/chat-completions/index.ts
var ChatCompletions = class {
async handleStream(stream, onChunk) {
let text = "";
for await (const chunk of stream) {
text += chunk;
await onChunk?.(chunk);
}
return text;
}
};
// src/chat-completions/openai.ts
var OpenAIChatCompletions = class {
var OpenAIChatCompletions = class extends ChatCompletions {
constructor(_openai) {
super();
this._openai = _openai;

@@ -77,15 +92,12 @@ }

}
async handleStream(stream, onChunk) {
let text = "";
for await (const chunk of stream) {
text += chunk;
await onChunk?.(chunk);
}
return text;
}
};
// src/embeddings/index.ts
var Embeddings = class {
};
// src/embeddings/openai.ts
var OpenAIEmbeddings = class {
var OpenAIEmbeddings = class extends Embeddings {
constructor(_openai) {
super();
this._openai = _openai;

@@ -109,4 +121,4 @@ }

const openai = new import_openai.OpenAI({ apiKey: config.openAIApiKey });
this.embeddings = config.embeddings || new OpenAIEmbeddings(openai);
this.chatCompletions = config.chatCompletions || new OpenAIChatCompletions(openai);
this.embeddings = config.embeddings ?? new OpenAIEmbeddings(openai);
this.chatCompletions = config.chatCompletions ?? new OpenAIChatCompletions(openai);
}

@@ -116,4 +128,6 @@ };

0 && (module.exports = {
AI
AI,
ChatCompletions,
Embeddings
});
//# sourceMappingURL=index.js.map
{
"name": "@singlestore/ai",
"version": "0.0.15",
"version": "0.0.16",
"license": "Apache-2.0",

@@ -5,0 +5,0 @@ "sideEffects": false,

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