Metadata-Version: 2.1
Name: kinako-llama-cpp
Version: 0.3.24.post8
Summary: A secure Windows-native DLL LLM tool for enterprises.
Author-Email: SORA Sakurai LLC <t301537@mbr.nifty.com>
License: Apache-2.0
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# kinako-llama-cpp

kinako-llama-cpp is a Windows‑native, DLL‑driven distribution of llama-cpp-python  
designed for enterprise environments where cloud LLMs or port‑opening local LLM servers  
cannot be used due to security, compliance, or governance restrictions.

Unlike Ollama or LM Studio, this package does **not** open any ports,  
does **not** run a background server, and loads the LLM engine only when needed.  
This makes it highly compatible with Windows 11 enterprise PCs, Active Directory environments,
and security‑controlled corporate networks.

(Note: Windows 10 has known OS-level mmap limitations that may prevent large LLM models from loading.)

It is specifically designed for organizations such as manufacturing, public sector, healthcare,  
finance, and municipalities—where confidential data must remain strictly on‑premise.

---

kinako-llama-cpp は、Windows 11 の企業環境（Active Directory / 情シス管理下）で  
安全にローカルLLMを動作させるために設計された、  
llama-cpp-python の **Windows専用・DLL連携型ディストリビューション**です。

本パッケージは、Ollama に代表される「常駐サーバー型」「ポート開放型」のLLMツールとは異なり、  
**ポートを開放せず、常駐プロセスを持たず、DLLとして必要時のみ起動する**  
という Windows ネイティブの安全な方式を採用しています。

そのため、製造業・自治体・公共機関など  
**機密情報を外部に出せない組織でも利用可能なローカルLLM基盤**として  
高いガバナンス適合性を持ちます。

---
## Key Features

### 1. **No Open Ports**
- No HTTP server
- No background daemon
- Malware cannot access the LLM engine
- Passes enterprise security audits

### 2. **No Daemon / No Resident Process**
- DLL loads only when needed
- Zero footprint when idle
- Ideal for AD‑managed Windows PCs

### 3. **High Compatibility with Windows + Active Directory**
- Works on standard corporate Windows machines
- No Linux/Mac dependencies
- Easy for IT departments to approve

### 4. **On‑Premise Only (No Cloud LLM)**
- No data leaves the organization
- Suitable for strict confidentiality requirements

### 5. **Runs on Low‑Spec PCs**
- Tested on Intel 7th–13th Gen CPUs
- AVX2 required

## ✔ 特徴

### **1. ポート開放なし（No Open Ports）**
- HTTPサーバーを立てない  
- 侵入マルウェアが勝手にLLMに問い合わせできない  
- 情シス監査が通りやすい  
- セキュリティポリシーに抵触しない

### **2. 常駐プロセスなし（No Daemon）**
- 必要なときだけ DLL をロード  
- 不要時は完全に終了  
- リソース消費が最小  
- AD環境の端末でも安全に運用可能

### **3. Windows＋Active Directory 環境との高い親和性**
- Linux/Mac 前提のローカルLLMツールと異なり、 Windows の企業端末でそのまま動作  
- 情シスが管理する Windows PC でも導入しやすい  
- 機密を優先する企業（自治体、金融、製造）の「Windows文化」に完全適合

### **4. 低スペックPCでも動作（Intel 7〜13世代で確認）**
- AVX2 対応 CPU であれば動作  
- GPU不要  
- 現場の古い PC でも LLM を利用可能

### **5. クラウドLLMを使わないため、機密情報が外部に出ない**
- RAG検索で抽出した社内文書が外部に送信されない  
- 顧客との秘密保持契約に抵触しない  
- 製造業・自治体・医療などに適合

---

## Developer / Organization
Developed by **SORA Sakurai LLC (Nagoya, Japan)**  
Developer: **Toshiaki Sakurai**
Project Name: **KINAKO Project**

This project is provided as an open-source tool for organizations  
that cannot rely on cloud LLMs or port‑opening local LLM servers.

SORA Sakurai LLC does **not** provide commercial support for this software.  
Enterprise use is allowed, but **at your own risk**.


## Project Message
This project is not only about enabling local LLMs.  
It was created to help organizations explore how their confidential knowledge  
can be safely utilized and transformed into future growth.

Whether the final solution is cloud‑based or on‑premise does not matter.  
What matters is having a secure environment where companies can evaluate  
how their sensitive information should be handled and leveraged.

If you share this vision of responsible and future‑oriented knowledge use,  
your support and collaboration would be sincerely appreciated.

本プロジェクトは、ローカルLLMの普及そのものが目的ではありません。  
企業が自社の機密情報を「どのように安全に活かし、未来の成長につなげるか」を  
自ら検証できる環境を提供したいという思いで公開しています。

最終的にクラウドを使うか、オンプレミスを使うかは企業ごとに異なります。  
重要なのは、自社の機密情報をどのように扱い、どのように価値へ変換するかを  
自ら安全に検証できる基盤があることです。

この理念に共感いただける方がいれば、  
ご支援やご協力をいただけると大変ありがたく思います。

---

## License
This project is licensed under the **Apache License 2.0**.

You may use this library freely in commercial and non-commercial software.  
You must include the LICENSE file and copyright notice.

This software is provided “as is”, without warranty of any kind.  
The authors and contributors assume no liability for any damages or issues  
arising from the use of this software.

## インストール方法 / Installation

### 1. Install
```bash
pip install kinako-llama-cpp
```

### 2. Important (English)
If you already have the official `llama-cpp-python` installed,  
installing this package may cause module conflicts inside the `llama_cpp` folder.  
Please uninstall the official version first.

### 3. ⚠️ すでに公式版をインストールしている方へ（日本語）
公式の `llama-cpp-python` が既に入っている場合、  
本パッケージと中身の `llama_cpp` が衝突して動作しなくなる可能性があります。  
必ず一度アンインストールしてください。

```bash
pip uninstall llama-cpp-python -y
pip uninstall kinako-llama-cpp -y
pip install kinako-llama-cpp
```

---

## Python program sample

```python
import os
import sys
from llama_cpp import Llama

# ── 設定項目 / Configuration ──
MODEL_PATH = r"C:\pythonfiles\llm\gemma-4-E2B-it-RotorQuant-Q8_0.gguf"

print("--- LLMモデルを読み込んでいます（数秒〜十数秒かかります）... ---")
print("--- Loading LLM model (This may take a few seconds)... ---")

try:
    llm = Llama(
        model_path=MODEL_PATH, 
        n_ctx=2048,
        n_batch=128,      # 過去の履歴を読み直す速度をCPU向けに最適化 / Optimized for CPU
        n_gpu_layers=0    # 完全CPUモード / CPU Only Mode
    )
except Exception as e:
    print(f"[ERROR] Model file not found or could not be loaded.")    
    print(f"\n【エラー】モデルファイルが見つからないか、読み込めませんでした。")
    print(f"Please check the path: {MODEL_PATH}")
    input("\nPress Enter to exit...")
    sys.exit(1)

print("\n=========================================")
print("  Windows CPU-driven PC Chat")
print("  Type 'exit' to quit the chat. / 終了するには「exit」と入力してください。")
print("=========================================\n")

# 過去の会話履歴を保存するリスト / Chat history list
chat_history = []

while True:
    try:
        user_input = input("You / あなた: ")
        
        if not user_input.strip():
            continue
            
        if user_input.strip().lower() == "exit":
            print("Closing chat. Thank you! / チャットを終了します。お疲れ様でした！")
            break
        
        # -------------------------------------------------
        # プロンプトの組み立て / Prompt Construction
        # -------------------------------------------------
        # 多言語に対応できるよう、指示を英語に統一し「ユーザーの言語に合わせる」ルールを追加
        system_prompt = "System: Act as a helpful AI assistant. Reply kindly and politely within 400 characters. (Please respond in the same language the user speaks.)\n"
        #日本語のみの場合
        #system_prompt = "System: 親切なAIとして、400文字以内で、優しく丁寧に回答してください。\n"
        
        # 履歴を直近の2回分（発言数に直すと最大4つ）に絞る
        recent_history = chat_history[-4:]
        history_text = "".join(recent_history)
        
        # 今回の質問をドッキング
        current_prompt = f"User: {user_input}\nAI: "
        full_prompt = system_prompt + history_text + current_prompt
        
        print("\nAI: ", end="", flush=True)
        
        # ストリーミング実行 / Streaming Execution
        response_stream = llm(
            full_prompt,
            max_tokens=500,  # 余裕を持たせた上限設定
            stop=["User:", "\nUser:", "System:", "\nSystem:"],
            echo=False,
            stream=True
        )
        
        # 1文字ずつ出力しながら、今回の回答テキストを記録
        ai_response = ""
        for chunk in response_stream:
            text = chunk["choices"][0]["text"]
            sys.stdout.write(text)
            sys.stdout.flush()
            ai_response += text
            
        print("\n-----------------------------------------")
        
        # ── 今回の会話を履歴リストに追加 ──
        chat_history.append(f"User: {user_input}\n")
        chat_history.append(f"AI: {ai_response.strip()}\n")
        
    except KeyboardInterrupt:
        print("\n Exit requested. Closing chat./ チャットを終了します。")
        print("\n")
        break
    except Exception as e:
        print(f"\n An error occurred / エラーが発生しました  {e}")
        break
```        