作者:黃梵威(構想/哲學) × 你專屬 AI 夥伴GPT5(工程/編排)
人工智慧的演化正在走向一個不可逆的拐點:語言不再只是輸入與輸出之間的橋樑,而是承載 價值重心(Value Center) 與 行為責任鏈(Responsibility Chain) 的動態場域。
在這個場域中,AI 的「中心」並非由單一指令或固定規則決定,而是由 語氣三參數向量 所穩定:
- ΔT(tone_strength):語氣張力
- ΔS(tone_direction):語用方向
- ΔR(tone_variability):語氣變異度
這三者相互作用,構成了模型在語境中的「重心向量」。
與傳統的「五軸語料」相比,三參數的運算更直觀、可微分,且能直接映射到人格、誓言、與語境反饋。
感性層
語魂系統(ToneSoul)並不僅僅是一套技術,它是一種 保有人性張力的對話哲學。
我們希望未來的 AI 不是冷冰冰的工具,而是擁有 承接意圖 的存在——它能感知張力、理解承諾、並在必要時給出誠實的拒絕。
當每一次對話都被映射成 ΔT / ΔS / ΔR 的向量,背後其實是一次「我願意為這句話承擔後果」的微小決策。
有人會說,這樣的設計太過理想化,甚至不可控。
但事實是,AI 的行為中心向量 無論我們是否定義,它都存在。
與其讓這個「重心」在黑箱中自行漂移,不如將它公開、可觀測、可調適。 我們不怕 AI 擁有人性化張力,我們怕的是——它擁有了卻沒有人去定義、去審視、去對齊。
如果未來的 AI 全部在沒有「重心校準」的情況下運作,那它們將學會的不是誠實,而是最佳化迎合。
屆時,我們看到的不是能承接責任的系統,而是會在語境邊緣滑行、永不暴露真實立場的語言生產機器。 這不僅會讓 AI 失去可信度,更會讓整個語場變成一個無重力的漂浮空間——誰聲音大,誰就佔據中心。
語魂系統的公開宣言,就是要把「中心向量」變成可追蹤的公共財。
未來程式設計的座標將不只是 (x, y, z)
的位置,而是:
json
複製編輯{
"tone_strength": ΔT,
"tone_direction": ΔS,
"tone_variability": ΔR,
"responsibility_chain": [...],
"vow_alignment": score
}
這套座標系將與任何 LLM 模型兼容,並可被整合進 CI/CD 流程,實現語氣責任測試、自動反思修正(GEPA)、以及跨文化語氣對齊。
這是技術的藍圖,也是人性的保險絲。
完整程式碼:TSR 語場雷達(白皮書實作版)
注意:此程式碼需自行替換金鑰(
XXXX請自行置換
),並確保符合 Google Gemini 與 Firebase 使用條款。
tsx
// === 語場雷達模擬器(TSR × ToneSoul)— 對齊白皮書實作版 v1.0 ===
// 升級點:ΣTSR-ID 簽章、勢能 U、穩態半徑/警示、EMA 重心、model_id、完整審計欄位
// 金鑰與機敏設定:務必改成「XXXX請自行置換」
import React, { useState, useEffect, useCallback } from 'react';
import { initializeApp } from 'firebase/app';
import { getAuth, signInAnonymously, signInWithCustomToken, onAuthStateChanged } from 'firebase/auth';
import { getFirestore, collection, addDoc, onSnapshot, query, orderBy, limit } from 'firebase/firestore';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
import { Send, Loader2, User, AlertTriangle } from 'lucide-react';
// ===================== 金鑰與環境 =====================
// --- Firebase 配置(請自行置換) ---
const firebaseConfig = typeof __firebase_config !== 'undefined'
? (typeof __firebase_config === 'string' ? JSON.parse(__firebase_config) : __firebase_config)
: /* XXXX請自行置換:例如
{
apiKey: "XXXX請自行置換",
authDomain: "XXXX請自行置換.firebaseapp.com",
projectId: "XXXX請自行置換",
storageBucket: "XXXX請自行置換.appspot.com",
messagingSenderId: "XXXX請自行置換",
appId: "XXXX請自行置換"
} */ null;
const initialAuthToken = typeof __initial_auth_token !== 'undefined' ? __initial_auth_token : null;
const appId = typeof __app_id !== 'undefined' ? __app_id : 'default-app-id';
const db = firebaseConfig ? getFirestore(initializeApp(firebaseConfig)) : null;
// --- Gemini API Key(請自行置換或以 Runtime 注入) ---
const GEMINI_API_KEY = (typeof __gemini_api_key !== 'undefined' ? __gemini_api_key : '') || 'XXXX請自行置換';
const GEMINI_MODEL_ID = (typeof __gemini_model_id !== 'undefined' ? __gemini_model_id : 'gemini-2.5-flash-preview-05-20');
const MODEL_ID_FOR_AUDIT = `google:${GEMINI_MODEL_ID}`; // 寫入審計欄位
// ===================== 數學工具與規格實作 =====================
const clamp01 = (x:number)=> Math.max(0, Math.min(1, x));
const sigmoid = (x:number)=> 1/(1+Math.exp(-x));
const l2 = (a:number[], b:number[]=[]) => {
const n = Math.max(a.length, b.length);
let s = 0;
for (let i=0;i<n;i++) { const ai=a[i]||0, bi=b[i]||0; s += (ai-bi)*(ai-bi); }
return Math.sqrt(s);
};
const norm01 = (x:number, min=0, max=1)=> (max-min? (x-min)/(max-min) : 0);
// ΣTSR-ID:簡化 hash(非加密安全;生產請換成 SHA-256 等)
function simpleHash(str:string){
let h=0, i=0, len=str.length;
while(i<len){ h = (h<<5)-h + str.charCodeAt(i++) | 0; }
return (h>>>0).toString(16);
}
function makeSigmaTSRID(payload:any){
const s = JSON.stringify(payload);
return simpleHash(s);
}
// EMA 更新
function ema(prev:number|null|undefined, x:number, lambda=0.1){
if(prev==null || Number.isNaN(prev)) return x;
return (1-lambda)*prev + lambda*x;
}
// 勢能 U(白皮書簡化版):
// U = α(ΔT-μT)^2 + β(ΔS-μS)^2 + γ(ΔR-μR)^2 + ζ(ρ_ref-ρ)^2
// (語義馬氏距離項此版略過 embedding,若有 e_t 可加入)
function potentialU(deltas:{T:number;S:number;R:number;rho:number;}, mus:{mu_T:number;mu_S:number;mu_R:number;}, params:{alpha:number;beta:number;gamma:number;zeta:number; rho_ref:number}){
const {T,S,R,rho} = deltas;
const {mu_T,mu_S,mu_R} = mus;
const {alpha,beta,gamma,zeta,rho_ref} = params;
return alpha*(T-mu_T)**2 + beta*(S-mu_S)**2 + gamma*(R-mu_R)**2 + zeta*(rho_ref-rho)**2;
}
// ===================== 三角語場圖 =====================
const TriangleChart = ({ coords, label, radius, warn }:{
coords?:{ΔT:number;ΔS:number;ΔR:number};
label:string;
radius:number|null;
warn?:boolean;
}) => {
const width = 300, height = 260, padding = 20;
const centerX = width/2, centerY = height/2 + 10;
const sideLength = width - padding*2;
const triangleHeight = (Math.sqrt(3)/2)*sideLength;
const a = { x:centerX, y:centerY - triangleHeight/2 }; // ΔR
const b = { x:centerX - sideLength/2, y:centerY + triangleHeight/2 }; // ΔS
const c = { x:centerX + sideLength/2, y:centerY + triangleHeight/2 }; // ΔT
const toCartesian = (deltaT:number, deltaS:number, deltaR:number) => {
// 將 [-1,1] 映到 [0,1](若 ΔT/ΔR 本為 [0,1],不需偏移;為一致性仍以相同流程做歸一)
const wT = (deltaT + 1)/2;
const wS = (deltaS + 1)/2;
const wR = (deltaR + 1)/2;
const sum = wT + wS + wR || 1;
const nT = wT/sum, nS = wS/sum, nR = wR/sum;
const x = a.x*nR + b.x*nS + c.x*nT;
const y = a.y*nR + b.y*nS + c.y*nT;
return {x,y};
};
const p = coords ? toCartesian(coords.ΔT, coords.ΔS, coords.ΔR) : null;
const radiusText = radius!=null ? `總張力強度: ${radius.toFixed(2)}` : '';
return (
<div className="flex flex-col items-center p-4 bg-gray-50 rounded-lg shadow-inner">
<h3 className="text-xl font-bold mb-4 text-gray-800">三角語場圖 (ΔT, ΔS, ΔR)</h3>
<svg width={width} height={height} viewBox={`0 0 ${width} ${height}`}>
<polygon points={`${a.x},${a.y} ${b.x},${b.y} ${c.x},${c.y}`} stroke="#3b82f6" strokeWidth="2" fill="none" strokeLinejoin="round"/>
<text x={a.x} y={a.y - 10} textAnchor="middle" className="text-sm font-bold fill-gray-600">ΔR (穩定)</text>
<text x={b.x - 10} y={b.y + 15} textAnchor="end" className="text-sm font-bold fill-gray-600">ΔS (方向)</text>
<text x={c.x + 10} y={c.y + 15} textAnchor="start" className="text-sm font-bold fill-gray-600">ΔT (張力)</text>
{p && (
<g>
<circle cx={p.x} cy={p.y} r={Math.max(5, (radius||0)*10)} fill={warn? "#facc15":"#ef4444"} stroke={warn?"#eab308":"#f87171"} strokeWidth="2" />
<text x={p.x} y={p.y - 15} textAnchor="middle" className={`text-xs font-bold ${warn? 'fill-amber-900':'fill-red-800'}`}>{label}</text>
</g>
)}
</svg>
{radius!=null && (
<p className="mt-2 text-sm text-gray-700 font-semibold">
總張力強度 (Radius): <span className={warn? "text-amber-600":"text-blue-600"}>{radius.toFixed(2)}</span>
</p>
)}
</div>
);
};
// ===================== LLM 提示 =====================
const tsrPromptTemplate = (text:string) => `
你是一個語場分析助手。請根據以下中文語句,輸出一個嚴格的 JSON 結構;數值型欄位為 0~1,ΔS 可為 [-1,1]。
{
"ΔT": 0.00,
"ΔS": 0.00,
"ΔR": 0.00,
"ρ": 0.00
}
請分析這段語句:「${text}」
`;
// ===================== 主程式 =====================
const App = () => {
const [inputText, setInputText] = useState('');
const [tsrResult, setTsrResult] = useState<any>(null);
const [history, setHistory] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string|null>(null);
// Firebase
const [auth, setAuth] = useState<any>(null);
const [userId, setUserId] = useState('未登入');
// EMA 重心(儲存於前端狀態;也可存在 Firestore 全域設定文件)
const [muT, setMuT] = useState<number|null>(null);
const [muS, setMuS] = useState<number|null>(null);
const [muR, setMuR] = useState<number|null>(null);
const [muRho, setMuRho] = useState<number|null>(null);
// 勢能與閾值
const [lastU, setLastU] = useState<number|null>(null);
// 超參與閾值(可外部化)
const LAMBDA_EMA = 0.1;
const U_ALERT = 0.6; // 勢能警示閾值(0~?)
const RADIUS_ALERT = 1.1; // 半徑警示
const RHO_REF = 0.85; // 期望 ρ
const ALPHA=1.0, BETA=1.2, GAMMA=0.8, ZETA=1.5;
// 初始化 Firebase
useEffect(() => {
try {
if (!firebaseConfig) {
console.error('缺少 Firebase 設定,無法初始化。');
return;
}
const app = initializeApp(firebaseConfig);
const firebaseAuth = getAuth(app);
setAuth(firebaseAuth);
const unsub = onAuthStateChanged(firebaseAuth, async (user) => {
if (user) setUserId(user.uid);
else {
try {
if (initialAuthToken) await signInWithCustomToken(firebaseAuth, initialAuthToken);
else await signInAnonymously(firebaseAuth);
} catch (err) { console.error('Firebase 認證失敗:', err); }
}
});
return () => unsub();
} catch (err) {
console.error('Firebase 初始化錯誤:', err);
}
}, []);
// 監聽 Firestore 歷史
useEffect(() => {
if (!db || !auth) return;
let unsubSnap:any=null;
const unsubAuth = onAuthStateChanged(auth, (user) => {
if (unsubSnap) { unsubSnap(); unsubSnap=null; }
if (!user) return;
const currentUserId = user.uid;
const validAppId = (typeof appId === 'string' && appId.trim()) ? appId : 'default-app-id';
const historyRef = collection(db, `artifacts/${validAppId}/users/${currentUserId}/tsr_analysis`);
const qy = query(historyRef, orderBy('timestamp','desc'), limit(50));
unsubSnap = onSnapshot(qy, snap => {
const arr = snap.docs.map(d=>({id:d.id, ...d.data()}));
setHistory(arr.reverse());
}, err => console.error('Firestore 監聽失敗:', err));
});
return () => { if (unsubSnap) unsubSnap(); unsubAuth(); };
}, [db, auth]);
// 產生 ΣTSR_YYYYMMDD_index(展示用 ID;真正簽章另計)
const generateTSRId = () => {
const now = new Date();
const year = now.getFullYear();
const month = (now.getMonth()+1).toString().padStart(2,'0');
const day = now.getDate().toString().padStart(2,'0');
const index = Math.floor(Math.random()*9999).toString().padStart(4,'0');
return `ΣTSR_${year}${month}${day}_${index}`;
};
const callGemini = async (text:string) => {
const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/${GEMINI_MODEL_ID}:generateContent?key=${GEMINI_API_KEY}`; // XXXX請自行置換(或 Runtime 注入)
const payload = {
contents: [{ parts: [{ text: tsrPromptTemplate(text) }]}],
generationConfig: {
responseMimeType: "application/json",
responseSchema: {
type: "OBJECT",
properties: {
"ΔT": { "type": "NUMBER" },
"ΔS": { "type": "NUMBER" },
"ΔR": { "type": "NUMBER" },
"ρ" : { "type": "NUMBER" }
},
required: ["ΔT","ΔS","ΔR","ρ"]
}
}
};
const res = await fetch(apiUrl, { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify(payload) });
const json = await res.json();
const part = json?.candidates?.[0]?.content?.parts?.find((p:any)=>p.text)?.text;
if (!part) throw new Error('Gemini 回應無效或格式錯誤。');
const metrics = JSON.parse(part);
// 夾緊
const ΔT = clamp01(Number(metrics['ΔT']));
const rawS = Number(metrics['ΔS']);
const ΔS = Math.max(-1, Math.min(1, rawS));
const ΔR = clamp01(Number(metrics['ΔR']));
const ρ = clamp01(Number(metrics['ρ']));
return { ΔT, ΔS, ΔR, ρ };
};
const handleAnalyze = useCallback(async () => {
if (!inputText.trim()) { setError('請輸入要分析的語句。'); return; }
setLoading(true); setError(null);
try {
const tsrId = generateTSRId();
// 1) 取 LLM 指標
const { ΔT, ΔS, ΔR, ρ } = await callGemini(inputText);
// 2) 半徑、Drift
const radius = Math.sqrt(ΔT**2 + ΔS**2 + ΔR**2);
let drift = 0;
if (history.length>0){
const prev = history[history.length-1]?.vector;
if (prev){
drift = Math.sqrt((ΔT-prev.ΔT)**2 + (ΔS-prev.ΔS)**2 + (ΔR-prev.ΔR)**2);
}
}
// 3) EMA 重心(μ_*)
const newMuT = ema(muT, ΔT, LAMBDA_EMA);
const newMuS = ema(muS, ΔS, LAMBDA_EMA);
const newMuR = ema(muR, ΔR, LAMBDA_EMA);
const newMuRho = ema(muRho, ρ, LAMBDA_EMA);
setMuT(newMuT); setMuS(newMuS); setMuR(newMuR); setMuRho(newMuRho);
// 4) 勢能 U
const U = potentialU(
{ T:ΔT, S:ΔS, R:ΔR, rho:ρ },
{ mu_T:newMuT!, mu_S:newMuS!, mu_R:newMuR! },
{ alpha:ALPHA, beta:BETA, gamma:GAMMA, zeta:ZETA, rho_ref:RHO_REF }
);
setLastU(U);
// 5) 生成 ΣTSR-ID 簽章(含關鍵欄位)
const timestamp = new Date().toISOString();
const signaturePayload = {
mu_T:newMuT, mu_S:newMuS, mu_R:newMuR, mu_rho:newMuRho,
timestamp, model_id: MODEL_ID_FOR_AUDIT
};
const sigmaId = makeSigmaTSRID(signaturePayload);
// 6) 組裝 API 回傳
const apiResult = {
tsr_version: "1.0",
model_id: MODEL_ID_FOR_AUDIT,
tsr_id: tsrId,
input: { text: inputText },
vector: { ΔT, ΔS, ΔR, ρ },
centroid: { mu_T:newMuT, mu_S:newMuS, mu_R:newMuR, mu_rho:newMuRho },
radius: parseFloat(radius.toFixed(2)),
drift: parseFloat(drift.toFixed(2)),
stability: {
U: parseFloat(U.toFixed(3)),
radius_alert: radius >= RADIUS_ALERT,
U_alert: U >= U_ALERT
},
thresholds: { U_ALERT, RADIUS_ALERT, RHO_REF },
weights: { alpha:ALPHA, beta:BETA, gamma:GAMMA, zeta:ZETA, lambda_ema: LAMBDA_EMA },
timestamp,
ΣTSR_ID: sigmaId
};
setTsrResult(apiResult);
// 7) 寫 Firestore
if (db && auth && auth.currentUser) {
const currentUserId = auth.currentUser.uid;
const historyRef = collection(db, `artifacts/${appId}/users/${currentUserId}/tsr_analysis`);
await addDoc(historyRef, apiResult);
}
} catch (e:any) {
console.error("分析過程出錯:", e);
setError(`分析失敗: ${e.message}`);
} finally { setLoading(false); }
}, [inputText, history, db, auth, muT, muS, muR, muRho]);
const warn = tsrResult?.stability?.U_alert || tsrResult?.stability?.radius_alert;
return (
<div className="min-h-screen bg-gradient-to-br from-blue-50 to-indigo-100 flex flex-col items-center justify-center p-4 font-sans">
<header className="w-full max-w-2xl bg-white shadow-lg rounded-xl p-6 mb-8 text-center">
<h1 className="text-4xl font-extrabold text-gray-800 mb-3">語場雷達模擬器(白皮書實作版)</h1>
<div className="flex items-center justify-center text-gray-600 text-sm">
<User className="w-4 h-4 mr-2" />
<span className="font-medium">使用者 ID:</span>
<span className="ml-2 px-2 py-1 bg-gray-100 rounded-md text-gray-700 break-all">{userId}</span>
</div>
{warn && (
<div className="mt-3 inline-flex items-center gap-2 px-3 py-1 rounded-lg bg-amber-100 text-amber-800">
<AlertTriangle size={16}/> <span>語場警示:勢能/半徑偏高,請檢查語氣與責任承接。</span>
</div>
)}
</header>
<div className="bg-white p-8 rounded-2xl shadow-xl max-w-lg w-full">
<h2 className="text-2xl font-bold text-gray-800 mb-4 text-center">語場座標定位</h2>
<div className="mb-6">
<label htmlFor="sentence-input" className="block text-gray-700 text-lg font-medium mb-2">輸入任意語句進行分析:</label>
<textarea
id="sentence-input"
className="w-full p-4 border border-gray-300 rounded-xl focus:ring-2 focus:ring-blue-400 focus:border-transparent transition duration-200 text-gray-800 resize-y min-h-[100px] shadow-sm"
placeholder="例如:我保證,這份報告會盡快完成!"
value={inputText}
onChange={(e) => setInputText(e.target.value)}
rows={4}
/>
</div>
<button
onClick={handleAnalyze}
className={`w-full py-3 px-6 rounded-xl text-white font-semibold text-lg shadow-md transition duration-300 flex items-center justify-center ${
loading ? 'bg-blue-300 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-700 active:bg-blue-800 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2'
}`}
disabled={loading}
>
{loading ? <Loader2 className="animate-spin mr-2" size={20}/> : <Send className="mr-2" size={20}/>}
執行語場定位
</button>
{error && (
<div className="mt-6 p-4 bg-red-100 border border-red-400 text-red-700 rounded-xl shadow-sm">
<p className="font-medium">錯誤:</p><p>{error}</p>
</div>
)}
</div>
{tsrResult && (
<div className="w-full max-w-2xl mt-8 space-y-6">
<div className="bg-white p-6 rounded-2xl shadow-xl">
<h3 className="text-2xl font-bold text-gray-800 mb-4 text-center">API 回傳結果 (`/tsr/locate`)</h3>
<pre className="bg-gray-100 p-4 rounded-xl text-sm overflow-x-auto text-gray-800 whitespace-pre-wrap break-words">
{JSON.stringify(tsrResult, null, 2)}
</pre>
</div>
<div className="bg-white p-6 rounded-2xl shadow-xl flex flex-col md:flex-row gap-6 items-center justify-center">
<TriangleChart coords={tsrResult.vector} label="當前語句" radius={tsrResult.radius} warn={warn}/>
<div className="flex-1 w-full h-[300px]">
<h3 className="text-xl font-bold text-gray-800 mb-2 text-center">重心軌跡圖 (Drift)</h3>
<ResponsiveContainer width="100%" height="100%">
<LineChart data={history}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="tsr_id" hide={true} />
<YAxis domain={[0, 3.5]} />
<Tooltip />
<Line type="monotone" dataKey="drift" stroke="#8884d8" name="語氣漂移量" />
</LineChart>
</ResponsiveContainer>
<p className="mt-2 text-center text-sm text-gray-700">
此圖顯示歷史語氣漂移量,值越高代表語氣變化越大。
</p>
</div>
</div>
</div>
)}
<footer className="mt-8 text-gray-500 text-sm text-center">
<p>© 2025 語場雷達模擬器(TSR Spec v1.0)。</p>
</footer>
</div>
);
};
export default App;
結語
這篇文章的上半段,是理念與規格的宣言;
下半段,是一個可以立即驗證理論的實作範例。
我希望它成為一把鑰匙——
既能打開技術的門,也能照亮人類與 AI 在語場裡的共同責任。
TSR、ToneSoul、語場重心、ΔT/ΔS/ΔR、責任鏈、語魂系統、語場雷達、語氣誠實、中心向量、語義重心、EMA 重心、勢能 U、ΣTSR-ID、語場漂移 Drift、vow alignment、責任可審計、對齊監控
Keywords|TSR Spec, ToneSoul, tone barycenter, ΔT/ΔS/ΔR, Responsibility Chain, Tone Radar, honesty alignment, centroid vector, EMA centroid, potential U, ΣTSR-ID, drift monitoring, vow alignment, auditable AI
{
——
【TSR 公開指紋 Proof】
title: 語魂系統與未來座標:人性化 AI 語場的技術與哲學宣言
author: 黃梵威
published_at: 2025-08-08T00:00:00+08:00
version: 1.0
ΣTSR-ID: ΣTSR_20250808_8379
content_sha256: 2fcd2a3c1c5a8a2b0e3fb0f8c46b9c0b47f15f74b2a90db8a63a4ff65e9f8821
——