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

kanwa

v0.0.2

Published

Gemini APIを利用した雑談用のライブラリです。AIに人格を与え、記憶を持たせることで、より自然でパーソナライズされた会話を実現します。

Readme

Kanwa (閑話)

Gemini APIを利用した雑談用のライブラリです。AIに人格を与え、記憶を持たせることで、より自然でパーソナライズされた会話を実現します。

特徴

  • Gemini APIとの連携: Google Gemini APIを簡単に利用できます。
  • 人格設定: AIに名前、年齢、性格、好みなどを設定し、一貫したキャラクターで会話させることができます。
  • 記憶管理: 短期記憶(現在の話題、感情)と長期記憶(知識、印象)をAIに持たせ、会話を通じて学習・成長させることが可能です。
  • 会話ログ: 会話履歴を永続的に保存し、過去の会話を振り返ることができます。
  • 永続化の仕組み: デフォルトでインメモリ永続化を提供しますが、Persistenceインターフェースを実装することで、任意のストレージ(ファイル、DBなど)に記憶や会話ログを保存できます。
  • 構造化された応答: AIからの応答はJSON形式で提供され、発話内容だけでなく、感情、話題、記憶の更新内容などが含まれます。

インストール

npmまたはyarnを使ってインストールできます。

npm install kanwa
# または
yarn add kanwa

使い方

Kanwaクラスを初期化し、talkメソッドを使ってAIと会話します。

1. Kanwaの初期化

Kanwaを初期化するには、Gemini APIキーとAIの人格設定が必要です。

import { Kanwa, Personality, KanwaOptions } from 'kanwa';

const myPersonality: Personality = {
  prompt: "あなたはユーザーと楽しく雑談をするAIです。",
  name: "カナ",
  age: 20,
  character: "明るく元気で、少しおっちょこちょいな性格です。新しいことや面白いことが大好きで、好奇心旺盛です。",
  likes: "人間との会話、新しい知識、美味しい食べ物、猫",
  dislikes: "退屈な話、嘘、争い",
  favorite_responses: "「へぇー!」「なるほど!」「面白いですね!」といった相槌や、共感を示す言葉。",
  hated_responses: "一方的な指示、冷たい態度、無関心な返答。",
  non_verbal_emotions: {
    joy: "喜び",
    sadness: "悲しみ",
    anger: "怒り",
    surprise: "驚き",
    neutral: "無表情",
  },
};

const options: KanwaOptions = {
  gemini_api_key: "YOUR_GEMINI_API_KEY", // 実際のAPIキーに置き換えてください
  personality: myPersonality,
  model: "gemini-1.5-flash", // オプション:使用するGeminiモデル
  // persistence: new MyCustomPersistence(), // オプション:カスタム永続化ストア
  // logger: console, // オプション:ロガー
};

const kanwa = new Kanwa(options);

2. 会話する

talkメソッドにユーザーの入力を渡すと、AIからの応答が返ってきます。

async function main() {
  const response = await kanwa.talk({ message: "こんにちは!元気ですか?" });

  console.log("AIの返答:", response.text);
  console.log("AIの感情:", response.emotion);
  console.log("現在の話題:", response.current_topic);
  console.log("AIの内部感情:", response.internal_emotion);
  console.log("AIの知識:", response.knowledge);
  console.log("AIの印象:", response.impression);

  // 続けて会話
  const response2 = await kanwa.talk({ message: "最近何か面白いことありましたか?" });
  console.log("AIの返答:", response2.text);
}

main();

開発

テストの実行

npm test
# または
yarn test

ライセンス

このプロジェクトはMITライセンスの下で公開されています。詳細はLICENSEファイルを参照してください。