lightnode-sdk 0.10.5 → 0.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/add.js +29 -5
- package/package.json +1 -1
package/dist/add.js
CHANGED
|
@@ -738,6 +738,17 @@ process.exit(0);
|
|
|
738
738
|
// level runInference() helper. Keeps conversation history client-side and
|
|
739
739
|
// formats every prior turn into the next prompt so the model has context.
|
|
740
740
|
// ---------------------------------------------------------------------------
|
|
741
|
+
// Default grounding sent ahead of every turn. The underlying models (llama3)
|
|
742
|
+
// have no training knowledge of this specific project, so without grounding a
|
|
743
|
+
// small model confidently invents details (e.g. "Lightchain is a Litecoin
|
|
744
|
+
// fork" or "an IoT blockchain"). This identity + anti-hallucination prompt
|
|
745
|
+
// stops the worst drift; edit it to add your real facts. The SDK does NOT have
|
|
746
|
+
// a separate `system` channel - this text is prepended to the prompt itself.
|
|
747
|
+
const CHAT_SYSTEM_PROMPT = `You are the assistant for Lightchain AI, a decentralized AI inference network: open models (such as llama3-8b and llama3-70b) run across independent worker nodes, and every request is paid for on-chain with the network's native token, LCAI.
|
|
748
|
+
|
|
749
|
+
Important: in this app "Lightchain", "LightChain", and "Lightchain AI" always refer to THIS project, the decentralized AI inference network. It is NOT Litecoin, NOT a Litecoin fork, NOT an IoT blockchain, and NOT any other similarly named project. Never describe it that way.
|
|
750
|
+
|
|
751
|
+
If you are not certain of a specific fact about Lightchain AI, say you are not sure instead of inventing details. Keep answers clear and concise.`;
|
|
741
752
|
const NEXTJS_CHAT_PAGE = `// app/chat/page.tsx
|
|
742
753
|
// Generated by 'lightnode add chat'. Server-paid: your funded PRIVATE_KEY (in
|
|
743
754
|
// .env) pays each turn; the streaming /api/inference route runs the inference.
|
|
@@ -929,19 +940,28 @@ export const maxDuration = 120;
|
|
|
929
940
|
const NETWORK = (process.env.NETWORK ?? "testnet") as "mainnet" | "testnet";
|
|
930
941
|
const MODEL = process.env.MODEL ?? "llama3-8b";
|
|
931
942
|
|
|
943
|
+
// Grounding prepended to every turn so the model stops guessing what this
|
|
944
|
+
// project is. Edit it to add your real facts. (The SDK has no separate
|
|
945
|
+
// 'system' channel, so we fold it into the prompt below.)
|
|
946
|
+
const DEFAULT_SYSTEM = ${JSON.stringify(CHAT_SYSTEM_PROMPT)};
|
|
947
|
+
|
|
932
948
|
export async function POST(req: Request) {
|
|
933
949
|
if (!process.env.PRIVATE_KEY?.startsWith("0x")) {
|
|
934
950
|
return NextResponse.json({ error: "PRIVATE_KEY not configured" }, { status: 500 });
|
|
935
951
|
}
|
|
936
952
|
const body = (await req.json().catch(() => ({}))) as { prompt?: string; system?: string; stream?: boolean };
|
|
937
|
-
const
|
|
938
|
-
if (!
|
|
953
|
+
const userPrompt = body.prompt?.trim();
|
|
954
|
+
if (!userPrompt) return NextResponse.json({ error: "prompt is required" }, { status: 400 });
|
|
955
|
+
|
|
956
|
+
// The SDK encrypts only the prompt - there is no separate 'system' channel -
|
|
957
|
+
// so fold the grounding (or a caller override) into the front of the prompt.
|
|
958
|
+
const system = body.system?.trim() || DEFAULT_SYSTEM;
|
|
959
|
+
const prompt = system ? \`\${system}\\n\\n\${userPrompt}\` : userPrompt;
|
|
939
960
|
|
|
940
961
|
const args = {
|
|
941
962
|
network: NETWORK,
|
|
942
963
|
privateKey: process.env.PRIVATE_KEY as \`0x\${string}\`,
|
|
943
964
|
model: MODEL,
|
|
944
|
-
system: body.system?.trim() || undefined,
|
|
945
965
|
prompt,
|
|
946
966
|
};
|
|
947
967
|
|
|
@@ -1016,6 +1036,11 @@ type Turn = {
|
|
|
1016
1036
|
const MODELS = ["llama3-8b", "llama3-70b"] as const;
|
|
1017
1037
|
type ModelId = (typeof MODELS)[number];
|
|
1018
1038
|
|
|
1039
|
+
// Grounding prepended to every turn. The models have no training knowledge of
|
|
1040
|
+
// this specific project, so without it a small model invents details (e.g.
|
|
1041
|
+
// "Lightchain is a Litecoin fork"). Edit this to add your real facts.
|
|
1042
|
+
const CHAT_SYSTEM_PROMPT = ${JSON.stringify(CHAT_SYSTEM_PROMPT)};
|
|
1043
|
+
|
|
1019
1044
|
export default function ChatWeb3() {
|
|
1020
1045
|
const { address, chain } = useAccount();
|
|
1021
1046
|
const network: "mainnet" | "testnet" | null =
|
|
@@ -1137,8 +1162,7 @@ export default function ChatWeb3() {
|
|
|
1137
1162
|
setTurns([...history, { role: "user", text: next }, { role: "assistant", text: "", streaming: true }]);
|
|
1138
1163
|
setInput("");
|
|
1139
1164
|
try {
|
|
1140
|
-
const
|
|
1141
|
-
const prompt = composePrompt(history, next, system);
|
|
1165
|
+
const prompt = composePrompt(history, next, CHAT_SYSTEM_PROMPT);
|
|
1142
1166
|
const onChunk = (_chunk: string, totalSoFar: string) => {
|
|
1143
1167
|
setBusyStage("");
|
|
1144
1168
|
patchLastAssistant({ text: totalSoFar });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lightnode-sdk",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.6",
|
|
4
4
|
"description": "Read-only TypeScript client for LightChain AI: workers, jobs, models, on-chain registration, and per-model network analytics. Independent, community-built (not an official LightChain package).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|