New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@celljs/ai-core

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@celljs/ai-core

Core domain for AI programming

  • 3.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
decreased by-12.5%
Maintainers
0
Weekly downloads
 
Created
Source

Cell - AI Core Component

概览

AI Core 模块是一个用于与 AI 模型服务交互的库,提供了生成聊天响应和嵌入向量的功能。通过简单易用的 API 接口,支持消息的创建、请求的发送和响应的处理。是所有 AI 模块的基础,提供了 AI 模块通用的 API 接口。

特性

  • 生成聊天响应
  • 生成嵌入向量
  • 支持流式响应
  • 支持多种模型参数配置

安装

使用 npm 安装 AI Core 模块:

npm install @celljs/ai-core

或者使用 yarn:

yarn add @celljs/ai-core

AI Core 模块是所有 AI 模块的基础,提供了 AI 模块通用的 API 接口,包括消息的创建、请求的发送和响应的处理。所以在使用 AI Core 模块之前,需要先安装厂商对应的模型服务适配模块。例如:@celljs/ai-ollama

npm install @celljs/ai-ollama

或者使用 yarn:

yarn add @celljs/ai-ollama

快速开始

以下是一个简单的示例,展示如何使用 AI Ollama 模块生成聊天响应和嵌入向量:

import { AssistantMessage, PromptTemplate } from '@celljs/ai-core';
import { Component Autowired } from '@celljs/core';

@Component()
export class OllamaDemo {
    @Autowired(OllamChatModel)
    private chatModel: ChatModel;

    @Autowired(EmbeddingModel)
    private embeddingModel: EmbeddingModel;

    @Autowired(PromptTemplate)
    private promptTemplate: PromptTemplate;

    /**
     * Chat with Ollama
     */
    async chat() {
        const prompt = await this.promptTemplate.create(
            'Hello {name}',
            { 
                chatOptions: { model: 'llama3.2' },
                variables: { name: 'Ollama' }
            }
        );
        const response = await this.chatModel.call(prompt);
        console.log(response.result.output);
    }

    /**
     * Stream chat response
     */
    async stream() {
        const prompt = await this.promptTemplate.create(
            'Hello {name}',
            { 
                chatOptions: { model: 'llama3.2' },
                variables: { name: 'Ollama' }
            }
        );
        const response$ = await this.chatModel.stream(prompt);
        response$.subscribe({
            next: response => console.log(response.result.output),
            complete: () => console.log('Chat completed!')
        });
    }

    /**
     * Embed text to vector
     */
    async embed() {
        const response = await this.embeddingModel.call({
            inputs: ['text to embed'],
            options: { model: 'llama3.2' }
        });
        console.log(response.result.embeddings);
    }
}

许可证

本项目采用 MIT 许可证。

Keywords

FAQs

Package last updated on 05 Jan 2025

Did you know?

Socket

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.

Install

Related posts

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