npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zhipuai-sdk-nodejs-v4

v0.1.12

Published

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

Downloads

150

Readme

智谱大模型开放接口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()