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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@micl/ai

v0.0.1

Published

这是一个对 **大模型(如 OpenAI / 兼容接口)** 的轻量级封装,提供:

Readme

AI Model 工具封装

这是一个对 大模型(如 OpenAI / 兼容接口) 的轻量级封装,提供:

  • 单例模式管理模型实例
  • 统一 ask 对话接口(支持上下文)
  • 文本翻译能力(多语言 / 风格可控)
  • 可扩展的配置与消息回调机制

适用于:

  • Web / Node.js 项目
  • AI 助手 / 翻译工具
  • 内容生成、对话系统

📦 模块导出

export declare const aiModel: AiModelClass;

推荐直接使用 aiModel 单例,而不是手动 new。


🧱 类定义

declare class AiModelClass {
  static _instance: AiModelClass;
  static getInstance(): AiModelClass;

  private openaiInstance;
  private options;
  private onMessage;

  config(opt: any): void;
  ask(content: string, historyList?: any[]): Promise<any>;
  translateText(
    text: string,
    opt: {
      source: string;
      target: string;
      style?: string;
    }
  ): Promise<any>;
}

⚙️ 基础配置

在使用前需先调用 config 进行初始化。

import { aiModel } from '@micl/ai';

aiModel.config({
  apiKey: 'YOUR_API_KEY',
  baseURL: 'https://api.openai.com/v1',
  model: 'gpt-4o-mini',
  temperature: 0.7,
  onMessage: (msg: string) => {
    console.log('AI 输出:', msg);
  }
});

opt 为透传配置,可根据底层模型 SDK 自由扩展。


💬 ask:通用对话接口

向模型提问,支持携带历史上下文。

const res = await aiModel.ask('给我写一段 TypeScript 示例');
console.log(res);

带上下文

const history = [
  { role: 'user', content: '你是一个前端专家' },
  { role: 'assistant', content: '好的' }
];

const res = await aiModel.ask('解释什么是 Promise', history);

🌍 translateText:文本翻译

用于多语言翻译,支持翻译风格控制。

const result = await aiModel.translateText('你好,世界', {
  source: 'zh',
  target: 'en'
});

指定翻译风格

await aiModel.translateText('这是一段产品介绍', {
  source: 'zh',
  target: 'en',
  style: 'business'
});

常见风格示例:

  • formal(正式)
  • casual(口语)
  • business(商务)
  • tech(技术文档)

🧠 设计说明

  • 单例模式:确保全局只初始化一次模型实例
  • API 解耦:不强依赖具体 AI SDK,便于替换
  • 上下文友好:自然支持多轮对话
  • 高度可扩展:配置项完全开放

✅ 适用场景

  • AI 聊天机器人
  • 自动翻译 / 多语言系统
  • 文档 / 代码生成
  • 客服 / 助手系统

📄 License

MIT