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

zhipuai-sdk-nodejs-v4

Package Overview
Dependencies
Maintainers
2
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zhipuai-sdk-nodejs-v4

智谱开放平台大模型接口 Nodejs SDK (Big Model API SDK in Nodejs),让开发者更便捷的调用智谱开放API

  • 0.1.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
67
decreased by-35.58%
Maintainers
2
Weekly downloads
 
Created
Source

智谱大模型开放接口SDK

智谱开放平台大模型接口 Nodejs SDK (Big Model API SDK in Nodejs),让开发者更便捷的调用智谱开放API

简介

目前 SDK 处于刚开始开发阶段,有 bug 或者缺少需要的功能请提 issues

安装

npm install zhipuai-sdk-nodejs-v4
# or
yarn add zhipuai-sdk-nodejs-v4

使用

使用 apiKey 创建 Client,大部分操作都在这里进行

创建一个对话

调用 createCompletions 快速创建一个对话

import { ZhipuAI } from 'zhipuai-sdk-nodejs-v4';

const dialogue = async () => {
    const ai = new ZhipuAI()
    const data = await ai.createCompletions({
        model: "glm-4",
        messages: [
            {"role": "user", "content": "你好"},
            {"role": "assistant", "content": "我是人工智能助手"},
            {"role": "user", "content": "你叫什么名字"},
            {"role": "assistant", "content": "我叫chatGLM"},
            {"role": "user", "content": "你都可以做些什么事"}
        ],
        stream: false, 
    })
    console.log(data, "message")
}

dialogue()

流式调用

import { ZhipuAI } from 'zhipuai-sdk-nodejs-v4';

const dialogue = async () => {
    const ai = new ZhipuAI()
    const result = await ai.createCompletions({
        model: "glm-4",
        messages: [
            { "role": "user", "content": "你好" },
            { "role": "assistant", "content": "我是人工智能助手" },
            { "role": "user", "content": "你叫什么名字" }
        ],
        stream: true
    })
    for await (const chunk of result) {
        console.log(chunk.toString())
    }
}

dialogue()

生成一个图片

调用 createImages 快速生成一个图片

import { ZhipuAI } from 'zhipuai-sdk-nodejs-v4';

const createIamge = async () => {
    const ai = new ZhipuAI()
    const result = await ai.createImages({
        model: "cogview-3",
        prompt: "一只可爱的小猫咪"
    })
    console.log(result.data, "image url list")
}

createIamge()

创建向量

调用 createEmbeddings 快速创建向量

import { ZhipuAI } from 'zhipuai-sdk-nodejs-v4';

const createEmbeddings = async () => {
    const ai = new ZhipuAI()
    const result = await ai.createEmbeddings({
        model: "embedding-2", 
        input: "你好"
    })
    console.log(result, "embedding")
}

createEmbeddings()

文件管理

调用 createFiles 快速创建文件 调用 findFiles 查询文件列表

import { ZhipuAI } from 'zhipuai-sdk-nodejs-v4';
import { openAsBlob } from 'fs';

const filesOperations = async () => {
    const ai = new ZhipuAI()
    const result = await ai.createFiles({
        file: await openAsBlob("file path"),
        purpose: "test"
    })
    console.log(result, "create file")

    const fileList = await ai.findFiles(
        purpose?: string;
        limit?: number;
        after?: string;
        order?: "desc" | "asc";
    )
    console.log(fileList, "find file list")
}

filesOperations()

FAQs

Package last updated on 20 Mar 2024

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