@singlestore/ai
Advanced tools
Comparing version 0.0.23 to 0.0.24
@@ -111,4 +111,4 @@ import z$1, { z } from 'zod'; | ||
* | ||
* @typeParam T - Indicates whether the completion should be streamed (boolean). | ||
* @typeParam U - An array of tools that can be used during the chat completion. | ||
* @typeParam TStream - Indicates whether the completion should be streamed (boolean). | ||
* @typeParam TChatCompletionTool - An array of tools that can be used during the chat completion. | ||
* | ||
@@ -118,5 +118,5 @@ * @property {string} [prompt] - The initial prompt to generate the chat completion. | ||
* @property {string} [systemRole] - The role of the system in the conversation. | ||
* @property {T} [stream] - Whether the completion should be streamed. | ||
* @property {TStream} [stream] - Whether the completion should be streamed. | ||
* @property {ChatCompletionMessage[]} [messages] - An array of previous messages in the conversation. | ||
* @property {U} [tools] - An array of tools that can be used during the completion. | ||
* @property {TChatCompletionTool} [tools] - An array of tools that can be used during the completion. | ||
* | ||
@@ -127,14 +127,14 @@ * @property {Record<string, (tool: AnyChatCompletionTool, params: any) => Promise<void>>} [toolCallHandlers] - Optional handlers for when a tool is called during the completion. | ||
*/ | ||
interface CreateChatCompletionParams<T extends boolean | undefined, U extends AnyChatCompletionTool[] | undefined> { | ||
interface CreateChatCompletionParams<TStream extends boolean | undefined, TChatCompletionTool extends AnyChatCompletionTool[] | undefined> { | ||
prompt?: string; | ||
model?: string; | ||
systemRole?: string; | ||
stream?: T; | ||
stream?: TStream; | ||
messages?: ChatCompletionMessage[]; | ||
tools?: U; | ||
toolCallHandlers?: U extends AnyChatCompletionTool[] ? { | ||
[K in U[number] as K["name"]]?: (tool: K, params: K["params"] extends z$1.AnyZodObject ? z$1.infer<K["params"]> : undefined) => Promise<void>; | ||
tools?: TChatCompletionTool; | ||
toolCallHandlers?: TChatCompletionTool extends AnyChatCompletionTool[] ? { | ||
[K in TChatCompletionTool[number] as K["name"]]?: (tool: K, params: K["params"] extends z$1.AnyZodObject ? z$1.infer<K["params"]> : undefined) => Promise<void>; | ||
} : undefined; | ||
toolCallResultHandlers?: U extends AnyChatCompletionTool[] ? { | ||
[K in U[number] as K["name"]]?: (tool: K, result: Awaited<ReturnType<K["call"]>>, params: K["params"] extends z$1.AnyZodObject ? z$1.infer<K["params"]> : undefined) => Promise<void>; | ||
toolCallResultHandlers?: TChatCompletionTool extends AnyChatCompletionTool[] ? { | ||
[K in TChatCompletionTool[number] as K["name"]]?: (tool: K, result: Awaited<ReturnType<K["call"]>>, params: K["params"] extends z$1.AnyZodObject ? z$1.infer<K["params"]> : undefined) => Promise<void>; | ||
} : undefined; | ||
@@ -145,17 +145,17 @@ } | ||
* | ||
* @typeParam T - Indicates whether the result is a stream or a single completion. | ||
* @typeParam TStream - Indicates whether the result is a stream or a single completion. | ||
* | ||
* @returns If T is true, returns a `ChatCompletionStream`, otherwise returns a single `ChatCompletion`. | ||
*/ | ||
type CreateChatCompletionResult<T extends boolean | undefined> = T extends true ? ChatCompletionStream : ChatCompletion; | ||
type CreateChatCompletionResult<TStream extends boolean | undefined> = TStream extends true ? ChatCompletionStream : ChatCompletion; | ||
/** | ||
* Abstract class representing a chat completions generator, capable of handling various tools. | ||
* | ||
* @typeParam T - An array of tools that can be used during the chat completion. | ||
* @typeParam TChatCompletionTool - An array of tools that can be used during the chat completion. | ||
*/ | ||
declare abstract class ChatCompletions<T extends AnyChatCompletionTool[] | undefined> { | ||
declare abstract class ChatCompletions<TChatCompletionTool extends AnyChatCompletionTool[] | undefined> { | ||
/** | ||
* The tools that can be used during chat completion. Initialized to undefined. | ||
*/ | ||
tools: T; | ||
tools: TChatCompletionTool; | ||
/** | ||
@@ -166,3 +166,3 @@ * Initializes the tools to be used in chat completion. | ||
*/ | ||
initTools(tools: T): void; | ||
initTools(tools: TChatCompletionTool): void; | ||
/** | ||
@@ -206,8 +206,8 @@ * Retrieves the models available for generating chat completions. | ||
* | ||
* @typeParam T - Indicates whether the completion should be streamed (boolean). | ||
* @typeParam U - An array of tools that can be used during the chat completion. | ||
* @typeParam TStream - Indicates whether the completion should be streamed (boolean). | ||
* @typeParam TChatCompletionTool - An array of tools that can be used during the chat completion. | ||
* | ||
* @property {OpenAIChatCompletionModel} [model] - The model to use for generating the completion. | ||
*/ | ||
interface OpenAICreateChatCompletionParams<T extends boolean | undefined, U extends AnyChatCompletionTool[] | undefined> extends CreateChatCompletionParams<T, U>, _OpenAICreateChatCompletionParams { | ||
interface OpenAICreateChatCompletionParams<TStream extends boolean | undefined, TChatCompletionTool extends AnyChatCompletionTool[] | undefined> extends CreateChatCompletionParams<TStream, TChatCompletionTool>, _OpenAICreateChatCompletionParams { | ||
model?: OpenAIChatCompletionModel; | ||
@@ -218,5 +218,5 @@ } | ||
* | ||
* @typeParam T - An array of tools that can be used during the chat completion. | ||
* @typeParam TChatCompletionTool - An array of tools that can be used during the chat completion. | ||
*/ | ||
declare class OpenAIChatCompletions<T extends AnyChatCompletionTool[] | undefined> extends ChatCompletions<T> { | ||
declare class OpenAIChatCompletions<TChatCompletionTool extends AnyChatCompletionTool[] | undefined> extends ChatCompletions<TChatCompletionTool> { | ||
private _openai; | ||
@@ -233,10 +233,10 @@ constructor(_openai: OpenAI); | ||
* | ||
* @typeParam U - Indicates whether the completion should be streamed (boolean). | ||
* @typeParam K - An array of tools that can be used during the chat completion. | ||
* @typeParam TStream - Indicates whether the completion should be streamed (boolean). | ||
* @typeParam TChatCompletionTool - An array of tools that can be used during the chat completion. | ||
* | ||
* @param {OpenAICreateChatCompletionParams<U, MergeChatCompletionTools<T, K>>} params - Parameters for creating the chat completion, including prompt, system role, messages, tools, and handlers. | ||
* @param {OpenAICreateChatCompletionParams<TStream, MergeChatCompletionTools<TChatCompletionTool, TChatCompletionTool>>} params - Parameters for creating the chat completion, including prompt, system role, messages, tools, and handlers. | ||
* | ||
* @returns A promise that resolves to either a single chat completion or a stream of chat completions, depending on the `stream` parameter. | ||
*/ | ||
create<U extends boolean | undefined = false, K extends AnyChatCompletionTool[] | undefined = undefined>({ prompt, systemRole, messages, tools, toolCallHandlers, toolCallResultHandlers, ...params }: OpenAICreateChatCompletionParams<U, MergeChatCompletionTools<T, K>>): Promise<CreateChatCompletionResult<U>>; | ||
create<TStream extends boolean | undefined = false, TChatCompletionTool extends AnyChatCompletionTool[] | undefined = undefined>({ prompt, systemRole, messages, tools, toolCallHandlers, toolCallResultHandlers, ...params }: OpenAICreateChatCompletionParams<TStream, MergeChatCompletionTools<TChatCompletionTool, TChatCompletionTool>>): Promise<CreateChatCompletionResult<TStream>>; | ||
} | ||
@@ -334,16 +334,16 @@ | ||
* | ||
* @typeParam T - The type of `Embeddings` to be used, defaulting to `OpenAIEmbeddings`. | ||
* @typeParam U - An array of tools that can be used during chat completions, or undefined. | ||
* @typeParam K - The type of `ChatCompletions` to be used, defaulting to `OpenAIChatCompletions`. | ||
* @typeParam TEmbeddings - The type of `Embeddings` to be used, defaulting to `OpenAIEmbeddings`. | ||
* @typeParam TChatCompletionTool - An array of tools that can be used during chat completions, or undefined. | ||
* @typeParam TChatCompletion - The type of `ChatCompletions` to be used, defaulting to `OpenAIChatCompletions`. | ||
* | ||
* @property {string} [openAIApiKey] - The API key for authenticating with the OpenAI API. | ||
* @property {T} [embeddings] - An instance of `Embeddings` used for generating embeddings. Defaults to `OpenAIEmbeddings`. | ||
* @property {K} [chatCompletions] - An instance of `ChatCompletions` used for generating chat completions. Defaults to `OpenAIChatCompletions`. | ||
* @property {U} [chatCompletionTools] - An optional array of tools that can be used during chat completions. | ||
* @property {TEmbeddings} [embeddings] - An instance of `Embeddings` used for generating embeddings. Defaults to `OpenAIEmbeddings`. | ||
* @property {TChatCompletion} [chatCompletions] - An instance of `ChatCompletions` used for generating chat completions. Defaults to `OpenAIChatCompletions`. | ||
* @property {TChatCompletionTool} [chatCompletionTools] - An optional array of tools that can be used during chat completions. | ||
*/ | ||
interface AIConfig<T extends Embeddings, U extends AnyChatCompletionTool[] | undefined, K extends ChatCompletions<U>> { | ||
interface AIConfig<TEmbeddings extends Embeddings, TChatCompletionTool extends AnyChatCompletionTool[] | undefined, TChatCompletion extends ChatCompletions<TChatCompletionTool>> { | ||
openAIApiKey?: string; | ||
embeddings?: T; | ||
chatCompletions?: K; | ||
chatCompletionTools?: U; | ||
embeddings?: TEmbeddings; | ||
chatCompletions?: TChatCompletion; | ||
chatCompletionTools?: TChatCompletionTool; | ||
} | ||
@@ -358,20 +358,20 @@ /** | ||
* | ||
* @typeParam T - The type of `Embeddings` to be used, defaulting to `OpenAIEmbeddings`. | ||
* @typeParam U - An array of tools that can be used during chat completions, or undefined. | ||
* @typeParam K - The type of `ChatCompletions` to be used, defaulting to `OpenAIChatCompletions`. | ||
* @typeParam TEmbeddings - The type of `Embeddings` to be used, defaulting to `OpenAIEmbeddings`. | ||
* @typeParam TChatCompletionTool - An array of tools that can be used during chat completions, or undefined. | ||
* @typeParam TChatCompletions - The type of `ChatCompletions` to be used, defaulting to `OpenAIChatCompletions`. | ||
* | ||
* @property {T} embeddings - An instance of `Embeddings` used for generating embeddings. | ||
* @property {K} chatCompletions - An instance of `ChatCompletions` used for generating chat completions. | ||
* @property {TEmbeddings} embeddings - An instance of `Embeddings` used for generating embeddings. | ||
* @property {TChatCompletions} chatCompletions - An instance of `ChatCompletions` used for generating chat completions. | ||
*/ | ||
declare class AI<T extends Embeddings = OpenAIEmbeddings, U extends AnyChatCompletionTool[] | undefined = undefined, K extends ChatCompletions<any> = OpenAIChatCompletions<U>> { | ||
embeddings: T; | ||
chatCompletions: K; | ||
declare class AI<TEmbeddings extends Embeddings = OpenAIEmbeddings, TChatCompletionTool extends AnyChatCompletionTool[] | undefined = undefined, TChatCompletions extends ChatCompletions<any> = OpenAIChatCompletions<TChatCompletionTool>> { | ||
embeddings: TEmbeddings; | ||
chatCompletions: TChatCompletions; | ||
/** | ||
* Constructs a new `AI` instance. | ||
* | ||
* @param {AIConfig<T, U, K>} config - The configuration object for initializing the `AI` instance. | ||
* @param {AIConfig<TEmbeddings, TChatCompletionTool, TChatCompletions>} config - The configuration object for initializing the `AI` instance. | ||
*/ | ||
constructor(config: AIConfig<T, U, K>); | ||
constructor(config: AIConfig<TEmbeddings, TChatCompletionTool, TChatCompletions>); | ||
} | ||
export { AI, type AIConfig, type AnyAI, type AnyChatCompletionTool, type ChatCompletion, type ChatCompletionMessage, type ChatCompletionStream, ChatCompletionTool, type ChatCompletionToolCall, ChatCompletions, type CreateChatCompletionParams, type CreateChatCompletionResult, type CreateEmbeddingsParams, type Embedding, Embeddings, type MergeChatCompletionTools, type OnChatCompletionChunk, type OpenAIChatCompletionModel, OpenAIChatCompletions, type OpenAICreateChatCompletionParams, type OpenAICreateEmbeddingsParams, type OpenAIEmbeddingModel, OpenAIEmbeddings }; |
@@ -108,6 +108,6 @@ "use strict"; | ||
* | ||
* @typeParam U - Indicates whether the completion should be streamed (boolean). | ||
* @typeParam K - An array of tools that can be used during the chat completion. | ||
* @typeParam TStream - Indicates whether the completion should be streamed (boolean). | ||
* @typeParam TChatCompletionTool - An array of tools that can be used during the chat completion. | ||
* | ||
* @param {OpenAICreateChatCompletionParams<U, MergeChatCompletionTools<T, K>>} params - Parameters for creating the chat completion, including prompt, system role, messages, tools, and handlers. | ||
* @param {OpenAICreateChatCompletionParams<TStream, MergeChatCompletionTools<TChatCompletionTool, TChatCompletionTool>>} params - Parameters for creating the chat completion, including prompt, system role, messages, tools, and handlers. | ||
* | ||
@@ -303,3 +303,3 @@ * @returns A promise that resolves to either a single chat completion or a stream of chat completions, depending on the `stream` parameter. | ||
* | ||
* @param {AIConfig<T, U, K>} config - The configuration object for initializing the `AI` instance. | ||
* @param {AIConfig<TEmbeddings, TChatCompletionTool, TChatCompletions>} config - The configuration object for initializing the `AI` instance. | ||
*/ | ||
@@ -306,0 +306,0 @@ constructor(config) { |
{ | ||
"name": "@singlestore/ai", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128305