Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@singlestore/ai
Advanced tools
`@singlestore/ai` is a module of the `@singlestore/client` package that provides AI capabilities, including chat completions and embeddings, integrated with OpenAI models. Additionally, it offers flexibility for users to integrate their own AI models and
@singlestore/ai
is a module of the @singlestore/client
package that provides AI capabilities,
including chat completions and embeddings, integrated with OpenAI models. Additionally, it offers flexibility for users to integrate their own AI models and tools.
To install the @singlestore/ai
module, use npm:
npm install @singlestore/client
First, initialize the AI module with your OpenAI API key or your custom AI instance:
import { AI } from "@singlestore/ai";
const ai = new AI({
openAIApiKey: "your-openai-api-key", // or your custom AI instance
});
You can provide your own AI models and tools instead of using OpenAI. For example:
import { AI, ChatCompletionTool } from "@singlestore/ai";
const customTool = new ChatCompletionTool({
name: "CustomTool",
description: "A custom tool for chat completion",
params: {},
call: async (params) => {
// Custom tool logic
},
});
const ai = new AI({
chatCompletionTools: [customTool],
embeddings: new CustomEmbeddings(), // Your custom embeddings class
});
Create chat completions with integrated tools and streaming capabilities:
const completion = await ai.chatCompletions.create({
prompt: "Tell me a joke.",
systemRole: "You are a helpful assistant.",
stream: false,
});
console.log(completion.content);
Generate embeddings for your text:
const embeddings = await ai.embeddings.create("This is a sample text.");
console.log(embeddings);
The following section describes the main classes and methods available in the @singlestore/ai
module.
The main class that provides access to chat completions and embeddings.
new AI(config: AIConfig)
config.openAIApiKey
(string): Your OpenAI API key.config.chatCompletionTools
(ChatCompletionTool[] | undefined): An optional array of tools to be used in chat completions.config.embeddings
(Embeddings | undefined): An optional custom embeddings instance.Handles creating chat completions and managing the stream of chat data.
async create(params: OpenAICreateChatCompletionParams)
Creates a chat completion with optional support for tools and streaming.
prompt
(string | undefined): The initial user prompt.systemRole
(string | undefined): The system role for the AI.messages
(ChatMessage[] | undefined): An array of messages in the chat.stream
(boolean | undefined): If true, returns an async generator for streaming completions.tools
(ChatCompletionTool[] | undefined): Tools to be used during chat completion.toolCallHandlers
(ToolCallHandlers | undefined): Handlers for tool calls.toolCallResultHandlers
(ToolCallResultHandlers | undefined): Handlers for tool call results.Promise<ChatCompletion | AsyncGenerator<ChatCompletionStream>>
: A promise that resolves to either a single chat completion or a stream of chat completions.initTools(tools: ChatCompletionTool[])
Initializes tools to be used in chat completions.
tools
(ChatCompletionTool[]): An array of tools.Handles generating text embeddings using OpenAI models.
async create(input: string | string[], params?: OpenAICreateEmbeddingsParams)
Generates embeddings for the provided input text.
input
(string | string[]): The input text or array of texts to generate embeddings for.params
(OpenAICreateEmbeddingsParams | undefined): Optional parameters for creating embeddings.Promise<Embedding[]>
: A promise that resolves to an array of embedding vectors generated by OpenAI.An object representing a chat completion.
content
(string): The content of the chat completion.An async generator that yields chunks of chat completions.
An object representing a text embedding.
embedding
(number[]): An array of numbers representing the embedding vector.An object representing a message in the chat.
role
(string): The role of the message sender (e.g., 'system', 'user', 'assistant').content
(string): The content of the message.An object representing a tool used in chat completions.
name
(string): The name of the tool.description
(string): A description of what the tool does.params
(object | undefined): Parameters required by the tool.call
(function): The function that executes the tool.Parameters used for creating a chat completion.
model
(string): The model to use for the chat completion (e.g., 'gpt-4').temperature
(number | undefined): Sampling temperature for randomness in outputs.prompt
(string | undefined): The initial user prompt.systemRole
(string | undefined): The system role for the AI.messages
(ChatMessage[] | undefined): An array of messages in the chat.stream
(boolean | undefined): If true, returns an async generator for streaming completions.tools
(ChatCompletionTool[] | undefined): Tools to be used during chat completion.Parameters used for creating embeddings.
model
(string): The model to use for generating embeddings (e.g., 'text-embedding-ada-002').input
(string | string[]): The input text or array of texts to generate embeddings for.FAQs
A module that enhances the [`@singlestore/client`](https://github.com/singlestore-labs/singlestore/tree/main/packages/client) package with AI functionality, allowing you to integrate AI features like embeddings and chat completions.
The npm package @singlestore/ai receives a total of 13 weekly downloads. As such, @singlestore/ai popularity was classified as not popular.
We found that @singlestore/ai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.