@completionhq/completion-node

中文文档
0.0.4发布于 2024/04/15MITTypeScriptESM + CJS近 30 天下载 8186

The Completion Node SDK is a fast and lightweight way to interact with the Completion API.

原始使用文档
文档目录6 节
  1. Key Features
  2. Installation
  3. Usage
  4. Basic Logging
  5. Log with compiled prompt
  6. Use compiled prompt to log

Completion Library

Completion lets you:

  • Monitor and debug your LLM prompts in production.
  • Track the usage and cost of your LLM models.

Key Features

  • Monitor Prompts: Track the prompts sent to your LLM models in real-time. We intentionally separate prompt arguments from the prompt template to ensure that you can monitor the prompts, automatically detect version changes, and debug issues on historical data.
  • Cost Tracking: Track the usage and cost of your LLM models. We provide a detailed breakdown of the cost of each prompt, including the cost of the model, the cost of the prompt, and the total cost.
  • Version Control: Manage the versions of your prompts. We automatically detect changes in the prompt template and arguments, allowing you to track the evolution of your prompts over time.

Installation

Install the Completion Node library using npm or yarn:

npm install @completionhq/completion-node

# or

yarn add @completionhq/completion-node

Usage

Below are examples demonstrating how to use Completion in your Node.js application.

Completion is LLM-agnostic, meaning it can be used with any LLM model, including those from OpenAI, Anthropic, Google, Mistral etc.

Basic Logging

import { Completion } from '@completionhq/completion-node';

const completion = new Completion({
  apiKey: 'abc123',
});

const messagesTemplate = [
  {
    role: 'User',
    message: 'Hello, how are you {name}?',
  },
  {
    role: 'Assistant',
    message: 'I am good, thank you. How can I help you today?',
  },
];

const promptArguments = {
  name: 'Alice',
};

const output = "Is there anything I can help you with today?";

await completion.log({
  templateName: 'greeting',
  messagesTemplate,
  promptArguments,
  output,
  model: 'gpt-3.5-turbo',
});

Log with compiled prompt


const compiledMessages = [
  {
    role: 'User',
    message: 'Hello, how are you Alice?',
  },
  {
    role: 'Assistant',
    message: 'I am good, thank you. How can I help you today?',
  },
];
await completion.log({
  templateName: 'greeting',
  compiledMessages,
  output,
  model: 'gpt-3.5-turbo',
});

Use compiled prompt to log

const compiledPrompt = "User: Hello, how are you Alice?\nAssistant: I am good, thank you. How can I help you today?";

await completion.log({
  templateName: 'greeting',
  compiledPrompt,
  output,
  model: 'gpt-3.5-turbo',
});

版本与发布记录

@completionhq/completion-node 共发布 4 个版本,首次发布于 2024/04/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.4latest2024/04/152 年前
0.0.32024/04/152 年前
0.0.22024/04/152 年前
0.0.12024/04/152 年前

关于 @completionhq/completion-node 的常见问题

@completionhq/completion-node 是什么?

The Completion Node SDK is a fast and lightweight way to interact with the Completion API.

如何安装 @completionhq/completion-node?

在项目目录运行 npm install @completionhq/completion-node,或使用 pnpm add / yarn add / bun add。

@completionhq/completion-node 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@completionhq/completion-node 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@completionhq/completion-node 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12.*。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@completionhq/completion-node 可以商用吗?

@completionhq/completion-node 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@completionhq/completion-node 的下载量有多少?

根据 npm 官方下载统计,@completionhq/completion-node 在 2026/10/11 – 2026/11/09 这 30 天内被下载 8,186 次,日均约 273 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@completionhq/completion-node 还在维护吗?

最新版本 0.0.4 发布于 2024/04/15(2 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/04/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。