@singlestore/ai
Advanced tools
Comparing version 0.0.28 to 0.0.29
@@ -1,9 +0,96 @@ | ||
import { AnyChatCompletionTool, ChatCompletionsManager, OpenAIChatCompletions } from './chat-completions/index.js'; | ||
import { EmbeddingsManager, OpenAIEmbeddingsManager } from './embeddings.js'; | ||
import 'openai/resources/chat/completions'; | ||
import 'zod'; | ||
import 'openai'; | ||
import 'openai/resources/chat/completions.mjs'; | ||
import 'openai/resources/embeddings'; | ||
import z$1, { z } from 'zod'; | ||
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'; | ||
interface ChatCompletion { | ||
content: string; | ||
} | ||
type ChatCompletionStream = AsyncGenerator<ChatCompletion>; | ||
type OnChatCompletionChunk = (chunk: ChatCompletion) => Promise<void> | void; | ||
interface ChatCompletionMessage { | ||
role: Extract<ChatCompletionMessageParam["role"], "system" | "assistant" | "user">; | ||
content: string | null; | ||
} | ||
type ChatCompletionToolCall<T extends string, U extends z.AnyZodObject | undefined, K> = (params: U extends z.AnyZodObject ? z.infer<U> : void) => Promise<{ | ||
name: T; | ||
value: K; | ||
params?: U extends z.AnyZodObject ? z.infer<U> : undefined; | ||
}>; | ||
interface ChatCompletionToolConfig<T extends string, U extends z.AnyZodObject | undefined, K extends ChatCompletionToolCall<T, U, any>> { | ||
name: T; | ||
description: string; | ||
params?: U; | ||
call: K; | ||
} | ||
type AnyChatCompletionTool = ChatCompletionTool<string, z.AnyZodObject | undefined, ChatCompletionToolCall<string, any | undefined, any>>; | ||
type MergeChatCompletionTools<T extends AnyChatCompletionTool[] | undefined, U extends AnyChatCompletionTool[] | undefined> = T extends AnyChatCompletionTool[] ? U extends AnyChatCompletionTool[] ? [...T, ...U] : T : U extends AnyChatCompletionTool[] ? U : undefined; | ||
declare class ChatCompletionTool<T extends string, U extends z.AnyZodObject | undefined, K extends ChatCompletionToolCall<T, U, any>> { | ||
name: T; | ||
description: string; | ||
params: U; | ||
call: K; | ||
constructor(config: ChatCompletionToolConfig<T, U, K>); | ||
} | ||
interface CreateChatCompletionParams<TStream extends boolean | undefined, TChatCompletionTool extends AnyChatCompletionTool[] | undefined> { | ||
prompt?: string; | ||
model?: string; | ||
systemRole?: string; | ||
stream?: TStream; | ||
messages?: ChatCompletionMessage[]; | ||
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?: 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; | ||
} | ||
type CreateChatCompletionResult<TStream extends boolean | undefined> = TStream extends true ? ChatCompletionStream : ChatCompletion; | ||
declare abstract class ChatCompletionsManager<TChatCompletionTool extends AnyChatCompletionTool[] | undefined> { | ||
tools: TChatCompletionTool; | ||
initTools(tools: TChatCompletionTool): void; | ||
abstract getModels(): Promise<string[]> | string[]; | ||
handleStream(stream: ChatCompletionStream, onChunk?: OnChatCompletionChunk): Promise<ChatCompletion>; | ||
abstract create(params: CreateChatCompletionParams<any, any>): Promise<CreateChatCompletionResult<any>>; | ||
} | ||
type OpenAIChatCompletionModel = ChatCompletionCreateParamsBase["model"]; | ||
interface _OpenAICreateChatCompletionParams extends Omit<Partial<ChatCompletionCreateParamsBase>, keyof CreateChatCompletionParams<any, any>> { | ||
} | ||
interface OpenAICreateChatCompletionParams<TStream extends boolean | undefined, TChatCompletionTool extends AnyChatCompletionTool[] | undefined> extends CreateChatCompletionParams<TStream, TChatCompletionTool>, _OpenAICreateChatCompletionParams { | ||
model?: OpenAIChatCompletionModel; | ||
} | ||
declare class OpenAIChatCompletions<TChatCompletionTool extends AnyChatCompletionTool[] | undefined> extends ChatCompletionsManager<TChatCompletionTool> { | ||
private _openai; | ||
constructor(_openai: OpenAI); | ||
getModels(): OpenAIChatCompletionModel[]; | ||
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>>; | ||
} | ||
type Embedding = number[]; | ||
interface CreateEmbeddingsParams { | ||
model?: string; | ||
} | ||
declare abstract class EmbeddingsManager { | ||
abstract getModels(): string[]; | ||
abstract create(input: string | string[], params?: CreateEmbeddingsParams): Promise<Embedding[]>; | ||
} | ||
type _OpenAICreateEmbeddingsParams = Omit<Partial<EmbeddingCreateParams>, "input" | keyof CreateEmbeddingsParams>; | ||
type OpenAIEmbeddingModel = EmbeddingCreateParams["model"]; | ||
interface OpenAICreateEmbeddingsParams extends CreateEmbeddingsParams, _OpenAICreateEmbeddingsParams { | ||
model?: OpenAIEmbeddingModel; | ||
} | ||
declare class OpenAIEmbeddingsManager extends EmbeddingsManager { | ||
private _openai; | ||
constructor(_openai: OpenAI); | ||
getModels(): OpenAIEmbeddingModel[]; | ||
create(input: string | string[], params?: OpenAICreateEmbeddingsParams): Promise<Embedding[]>; | ||
} | ||
interface AIConfig<TChatCompletionTools extends AnyChatCompletionTool[] | undefined, TChatCompletionsManager extends ChatCompletionsManager<TChatCompletionTools>, TEmbeddingsManager extends EmbeddingsManager> { | ||
@@ -10,0 +97,0 @@ openAIApiKey?: string; |
{ | ||
"name": "@singlestore/ai", | ||
"version": "0.0.28", | ||
"version": "0.0.29", | ||
"license": "Apache-2.0", | ||
@@ -19,2 +19,7 @@ "sideEffects": false, | ||
}, | ||
"./embeddings": { | ||
"types": "./dist/embeddings/index.d.ts", | ||
"import": "./dist/embeddings/index.mjs", | ||
"require": "./dist/embeddings/index.js" | ||
}, | ||
"./chat-completions": { | ||
@@ -26,10 +31,5 @@ "types": "./dist/chat-completions/index.d.ts", | ||
"./chat-completions/errors": { | ||
"types": "./dist/chat-completions/errors.d.ts", | ||
"import": "./dist/chat-completions/errors.mjs", | ||
"require": "./dist/chat-completions/errors.js" | ||
}, | ||
"./embeddings": { | ||
"types": "./dist/embeddings.d.ts", | ||
"import": "./dist/embeddings.mjs", | ||
"require": "./dist/embeddings.js" | ||
"types": "./dist/chat-completions/errors/index.d.ts", | ||
"import": "./dist/chat-completions/errors/index.mjs", | ||
"require": "./dist/chat-completions/errors/index.js" | ||
} | ||
@@ -36,0 +36,0 @@ }, |
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
168186
1426
0
26