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

@singlestore/client

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@singlestore/client - npm Package Compare versions

Comparing version 0.0.26 to 0.0.27

46

dist/index.d.ts

@@ -1,3 +0,2 @@

import * as _singlestore_ai from '@singlestore/ai';
import { AnyAI } from '@singlestore/ai';
import { AnyAI, CreateChatCompletionResult } from '@singlestore/ai';
import * as mysql2_promise from 'mysql2/promise';

@@ -140,3 +139,2 @@ import { PoolOptions, Pool, ResultSetHeader, RowDataPacket } from 'mysql2/promise';

type VectorScoreKey = "v_score";
type ExtractAICreateChatCompletionsOptions<U extends AnyAI | undefined> = U extends AnyAI ? Parameters<U["chatCompletions"]["create"]>[1] : never;
declare class Table<T extends TableType = TableType, U extends AnyAI | undefined = undefined> {

@@ -155,3 +153,3 @@ private _connection;

static drop(connection: Connection, databaseName: string, name: string): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>;
showInfo<T extends boolean>(extended?: T): Promise<T extends true ? TableInfoExtended<string> : TableInfo<string>>;
showInfo<K extends boolean>(extended?: K): Promise<K extends true ? TableInfoExtended<string> : TableInfo<string>>;
drop(): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>;

@@ -165,23 +163,19 @@ column(name: TableColumnName<T> | (string & {})): Column;

insert(values: Partial<T["columns"]> | Partial<T["columns"]>[]): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]][]>;
select<U extends QueryBuilderArgs<T["columns"]>>(...args: U): Promise<(ExtractQueryColumns<T["columns"], ExtractQueryOptions<U>> & RowDataPacket)[]>;
select<K extends QueryBuilderArgs<T["columns"]>>(...args: K): Promise<(ExtractQueryColumns<T["columns"], ExtractQueryOptions<K>> & RowDataPacket)[]>;
update(values: Partial<T["columns"]>, filters: QueryFilters<T["columns"]>): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>;
delete(filters?: QueryFilters<T["columns"]>): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>;
vectorSearch<A extends [search: {
vectorSearch<K extends {
prompt: string;
vectorColumn: TableColumnName<T>;
}, ...QueryBuilderArgs<T["columns"]>]>(...args: A): Promise<(ExtractQueryColumns<T["columns"], ExtractQueryOptions<A extends [any, ...infer _A] ? _A extends QueryBuilderArgs<T["columns"]> ? _A : never : never>> & {
embeddingParams?: U extends AnyAI ? Parameters<U["embeddings"]["create"]>[1] : never;
}, V extends QueryBuilderArgs<T["columns"]>>(...args: [params: K, ...V]): Promise<(ExtractQueryColumns<T["columns"], ExtractQueryOptions<V extends QueryBuilderArgs<T["columns"]> ? V : never>> & {
v_score: number;
} & RowDataPacket)[]>;
createChatCompletion<K extends ExtractAICreateChatCompletionsOptions<U>>(...args: [
search: {
prompt: string;
vectorColumn: TableColumnName<T>;
template?: string;
} & K,
...QueryBuilderArgs<T["columns"]>
]): Promise<_singlestore_ai.ChatCompletionStream | _singlestore_ai.ChatCompletion>;
createChatCompletion<K extends Parameters<this["vectorSearch"]>[0] & (U extends AnyAI ? Parameters<U["chatCompletions"]["create"]>[0] : never) & {
template?: string;
}, V extends QueryBuilderArgs<T["columns"]>>(...args: [params: K, ...V]): Promise<CreateChatCompletionResult<K["stream"]>>;
}
interface DatabaseType<T extends Record<string, TableType> = Record<string, TableType>> {
tables: T;
interface DatabaseType {
tables: Record<string, TableType>;
}

@@ -218,3 +212,3 @@ interface DatabaseSchema<T extends DatabaseType> {

};
type AnyDatabase = Database<DatabaseType<any>, AnyAI | undefined>;
type AnyDatabase = Database<any, AnyAI | undefined>;
type DatabaseTableName<T extends DatabaseType> = Extract<keyof T["tables"], string>;

@@ -230,3 +224,3 @@ declare class Database<T extends DatabaseType = DatabaseType, U extends AnyAI | undefined = undefined> {

static drop(connection: Connection, name: string): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>;
showInfo<T extends boolean>(extended?: T): Promise<T extends true ? DatabaseInfoExtended<string> : DatabaseInfo<string>>;
showInfo<K extends boolean>(extended?: K): Promise<K extends true ? DatabaseInfoExtended<string> : DatabaseInfo<string>>;
describe(): Promise<{

@@ -259,7 +253,7 @@ tables: {

drop(): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>;
table<N, K extends DatabaseTableName<T> | (string & {}) = DatabaseTableName<T> | (string & {})>(name: K): Table<N extends TableType ? N : T["tables"][K] extends TableType ? T["tables"][K] : TableType, U>;
showTablesInfo<U extends boolean>(extended?: U): Promise<(U extends true ? TableInfoExtended<Extract<keyof T["tables"], string>> : TableInfo<Extract<keyof T["tables"], string>>)[]>;
createTable<T extends TableType = TableType>(schema: TableSchema<T>): Promise<Table<T, U>>;
table<K, V extends DatabaseTableName<T> | (string & {}) = DatabaseTableName<T> | (string & {})>(name: V): Table<K extends TableType ? K : T["tables"][V] extends TableType ? T["tables"][V] : TableType, U>;
showTablesInfo<K extends boolean>(extended?: K): Promise<(K extends true ? TableInfoExtended<Extract<keyof T["tables"], string>> : TableInfo<Extract<keyof T["tables"], string>>)[]>;
createTable<K extends TableType = TableType>(schema: TableSchema<K>): Promise<Table<K, U>>;
dropTable(name: DatabaseTableName<T> | (string & {})): Promise<[ResultSetHeader, mysql2_promise.FieldPacket[]]>;
query<T extends any[]>(statement: string): Promise<T>;
query<K extends any[]>(statement: string): Promise<K>;
}

@@ -287,6 +281,6 @@

static connect<T extends WorkspaceType = WorkspaceType, U extends AnyAI | undefined = undefined>({ ai, name, ...config }: ConnectWorkspaceConfig<T, U>): Workspace<T, U>;
database<N, K extends WorkspaceDatabaseName<T> | (string & {}) = WorkspaceDatabaseName<T> | (string & {})>(name: K): Database<N extends DatabaseType<Record<string, TableType>> ? N : T["databases"][K] extends DatabaseType<Record<string, TableType>> ? T["databases"][K] : DatabaseType<Record<string, TableType>>, U>;
createDatabase<T extends DatabaseType = DatabaseType>(schema: DatabaseSchema<T>): Promise<Database<T, U>>;
database<K, V extends WorkspaceDatabaseName<T> | (string & {}) = WorkspaceDatabaseName<T> | (string & {})>(name: V): Database<K extends DatabaseType ? K : T["databases"][V] extends DatabaseType ? T["databases"][V] : DatabaseType, U>;
createDatabase<K extends DatabaseType = DatabaseType>(schema: DatabaseSchema<K>): Promise<Database<K, U>>;
dropDatabase(name: WorkspaceDatabaseName<T> | (string & {})): Promise<[mysql2.ResultSetHeader, mysql2.FieldPacket[]]>;
showDatabasesInfo<U extends boolean>(extended?: U): Promise<(U extends true ? DatabaseInfoExtended<Extract<keyof T["databases"], string>> : DatabaseInfo<Extract<keyof T["databases"], string>>)[]>;
showDatabasesInfo<K extends boolean>(extended?: K): Promise<(K extends true ? DatabaseInfoExtended<Extract<keyof T["databases"], string>> : DatabaseInfo<Extract<keyof T["databases"], string>>)[]>;
}

@@ -293,0 +287,0 @@

@@ -361,5 +361,5 @@ "use strict";

async vectorSearch(...args) {
const [search, ...queryBuilderArgs] = args;
const [{ prompt, vectorColumn }, ...queryBuilderArgs] = args;
const { columns, clauses, values } = new QueryBuilder(...queryBuilderArgs);
const promptEmbedding = (await this.ai.embeddings.create(search.prompt))[0] || [];
const promptEmbedding = (await this.ai.embeddings.create(prompt))[0] || [];
let orderByClause = `ORDER BY ${this.vScoreKey} DESC`;

@@ -370,3 +370,3 @@ if (clauses.orderBy) {

const query = ` SET @promptEmbedding = '${JSON.stringify(promptEmbedding)}' :> vector(${promptEmbedding.length}) :> blob;
SELECT ${[columns, `${search.vectorColumn} <*> @promptEmbedding AS ${this.vScoreKey}`].join(", ")}
SELECT ${[columns, `${vectorColumn} <*> @promptEmbedding AS ${this.vScoreKey}`].join(", ")}
FROM ${this._path}

@@ -379,9 +379,16 @@ ${[clauses.where, clauses.groupBy, orderByClause, clauses.limit].join(" ")}

async createChatCompletion(...args) {
const [{ prompt, vectorColumn, template, systemRole, ...createChatCompletionOptions }, ...vectorSearchArgs] = args;
const [
{ prompt, vectorColumn, template, systemRole, embeddingParams, ...createChatCompletionParams },
...vectorSearchArgs
] = args;
const _systemRole = systemRole ?? ` You are a helpful assistant. Answer the user's question based on the context provided. If the context provided doesn't answer the question asked don't answer the user's question. `;
const _template = template ?? `The user asked: <question>
The most similar context: <context>`;
const context = await this.vectorSearch({ prompt, vectorColumn }, ...vectorSearchArgs);
const context = prompt ? await this.vectorSearch({ prompt, vectorColumn, embeddingParams }, ...vectorSearchArgs) : "";
const _prompt = _template.replace("<question>", prompt).replace("<context>", JSON.stringify(context));
return this.ai.chatCompletions.create(_prompt, { ...createChatCompletionOptions, systemRole: _systemRole });
return await this.ai.chatCompletions.create({
...createChatCompletionParams,
prompt: _prompt,
systemRole: _systemRole
});
}

@@ -388,0 +395,0 @@ };

{
"name": "@singlestore/client",
"version": "0.0.26",
"version": "0.0.27",
"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