3 Commits

Author SHA1 Message Date
pezkuwichain 0102315fab feat: switch AI to gpt-oss-120b for fluent Turkish/Kurdish, enforce plain text
llama-3.3-70b's Turkish read like stilted translation ('gostermektedir'
chains). openai/gpt-oss-120b on the same Groq key produces natural,
conversational Turkish (A/B tested on the same prompt). Also: explicit
natural-language + no-markdown style rules in both system prompts, and a
deterministic sanitizer stripping **/# remnants before sending - models
occasionally emit markdown regardless, and Telegram renders it raw.
2026-07-19 09:57:33 -07:00
pezkuwichain 8e49cbc0db fix: correct Mining Simulation framing - counter previews the REAL era airdrop
The previous knowledge text described the diamond counter as purely cosmetic
with no real counterpart. Corrected per Serok: the counter is an ESTIMATE of
the real PEZ airdrop - the actual distribution is calculated transparently
on-chain at era end (pezpallet-pez-rewards, trust-score-weighted) and paid
out to wallets automatically, at which point the counter resets. Diamonds
cannot be manually converted; the purpose is showing how raising trust score
(referrals, staking, tiki roles, education) raises your airdrop.
2026-07-19 09:50:27 -07:00
pezkuwichain 9c7c1a5be9 feat: teach the AI assistant about Pezkuwi Wallet, Mining Simulation and the Bulut Ulusu book
- Add Pezkuwi Wallet knowledge (live on Google Play v1.1.2): native BTC/SOL/TRX,
  USDT bridge (wUSDT<->USDT only), multisig, gift, trust score card
- Add PEZ Mining Simulation section: honest explanation that it is a client-side
  gamified preview (not real mining), session/era mechanics, zero-trust-score gate
- Add trust score guidance: why a score is 0 (needs >=1.1 HEZ on People Chain and
  >=1 HEZ staked) and how to raise it (stake more/longer, referrals, education, roles)
- Add chapter-by-chapter digest of the Bulut Ulusu (Cloud Nation) book
- Update channel links to https://t.me/+DUWJ8wtt5qI4Njgy everywhere
- Replace 'Play Store (Coming Soon)' with the live Google Play link
- ask: add Groq-primary/Claude-fallback (same pattern as telegram-bot) - the
  Anthropic key is out of credit, so the news-site assistant was returning
  'could not answer' on every question
2026-07-19 01:24:10 -07:00
4 changed files with 49 additions and 117 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "pezkuwi-telegram-miniapp",
"version": "1.0.242",
"version": "1.0.243",
"type": "module",
"description": "Pezkuwichain Telegram Mini App - Forum, Announcements, Rewards",
"author": "Pezkuwichain Team",
+3 -3
View File
@@ -1,5 +1,5 @@
{
"version": "1.0.242",
"buildTime": "2026-07-21T14:51:23.002Z",
"buildNumber": 1784645483003
"version": "1.0.243",
"buildTime": "2026-07-19T16:57:33.951Z",
"buildNumber": 1784480253951
}
+20 -52
View File
@@ -150,7 +150,6 @@ Inside the Trust Score card there is a small "Mining Simulation" square with a d
- If your Trust Score is 0, the counter cannot start — the app shows a warning that your trust score must be greater than 0. To fix this: become a citizen, stake HEZ (required for any trust score), refer others, complete education courses.
- Colors: red square = inactive (tap to start), gold = actively mining.
- The small Telegram icon next to it opens the official channel: https://t.me/+DUWJ8wtt5qI4Njgy
- IMPORTANT — how to talk about this: state that it's a simulation/estimate ONCE, briefly, near the start of your answer, then move on and explain the rest normally. Do NOT repeat "this isn't real mining" / "it's just an estimate" / similar caveats in every paragraph — one clear mention is enough, repeating it reads as nagging.
"BULUT ULUSU" (CLOUD NATION) — THE BOOK BEHIND PEZKUWICHAIN (chapter-by-chapter knowledge):
PezkuwiChain's philosophical foundation is the book "Bulut Ulusu" (Cloud Nation), written by the project's architect (a software developer AND sociologist — the "two desks" of the opening chapter). Available in Turkish, English and Kurdish. Core theses:
@@ -229,56 +228,6 @@ async function allowed(ip: string): Promise<boolean> {
return true;
}
// Groq's openai/gpt-oss-120b returns intermittent errors under load (429/5xx,
// and even a raw 502 from the edge runtime once) unrelated to the question
// asked — confirmed live 2026-07-21 by hitting this endpoint repeatedly with
// trivial questions ("merhaba") and seeing a ~50% failure rate with 15s+
// between calls (ruling out our own per-IP rate limiter above), which 2
// retries on the same model did not fully fix.
//
// 2026-07-21, user decision: prioritize reliability over gpt-oss-120b's
// better Turkish/Kurdish fluency (it was picked for that reason via an
// earlier A/B test) — llama-3.1-8b-instant is Groq's smallest/fastest model
// and, being long out of preview, has historically the best free-tier
// availability, so it goes first. gpt-oss-120b stays as the 2nd attempt
// (still worth trying for quality when the primary is having its own bad
// moment), llama-3.3-70b-versatile (the model used before switching to
// gpt-oss-120b) as the 3rd, before ever reaching the Anthropic fallback
// below. Doesn't retry a 4xx (bad request/auth) at all — not transient, and
// switching models wouldn't help.
const GROQ_MODELS = ['llama-3.1-8b-instant', 'openai/gpt-oss-120b', 'llama-3.3-70b-versatile'];
async function callGroqWithRetry(messages: unknown[], retriesPerModel = 2): Promise<string | null> {
for (const model of GROQ_MODELS) {
for (let attempt = 0; attempt <= retriesPerModel; attempt++) {
try {
const gr = await fetch('https://api.groq.com/openai/v1/chat/completions', {
method: 'POST',
headers: { Authorization: 'Bearer ' + GROQ_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
model,
temperature: 0.3,
max_tokens: 900,
messages: [{ role: 'system', content: SYSTEM }, ...messages],
}),
});
if (gr.ok) {
const gd = await gr.json();
const reply = gd.choices?.[0]?.message?.content || null;
if (reply) return reply;
} else {
console.error('[AI] Groq error:', model, gr.status, await gr.text());
if (gr.status !== 429 && gr.status < 500) break; // non-transient, try next model instead
}
} catch (e) {
console.error('[AI] Groq exception:', model, e);
}
if (attempt < retriesPerModel) await new Promise((r) => setTimeout(r, 400 * (attempt + 1)));
}
}
return null;
}
serve(async (req) => {
if (req.method === 'OPTIONS') return new Response('ok', { headers: CORS });
if (req.method !== 'POST') return J({ error: 'method' }, 405);
@@ -306,7 +255,26 @@ serve(async (req) => {
let answer: string | null = null;
if (GROQ_API_KEY) {
answer = await callGroqWithRetry(messages);
try {
const gr = await fetch('https://api.groq.com/openai/v1/chat/completions', {
method: 'POST',
headers: { Authorization: 'Bearer ' + GROQ_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'openai/gpt-oss-120b',
temperature: 0.3,
max_tokens: 900,
messages: [{ role: 'system', content: SYSTEM }, ...messages],
}),
});
if (gr.ok) {
const gd = await gr.json();
answer = gd.choices?.[0]?.message?.content || null;
} else {
console.error('[AI] Groq error:', gr.status, await gr.text());
}
} catch (e) {
console.error('[AI] Groq exception:', e);
}
}
if (!answer && ANTHROPIC_API_KEY) {
+25 -61
View File
@@ -230,7 +230,6 @@ Inside the Trust Score card there is a small "Mining Simulation" square with a d
- If your Trust Score is 0, the counter cannot start — the app shows a warning that your trust score must be greater than 0. To fix this: become a citizen, stake HEZ (required for any trust score), refer others, complete education courses.
- Colors: red square = inactive (tap to start), gold = actively mining.
- The small Telegram icon next to it opens the official channel: https://t.me/+DUWJ8wtt5qI4Njgy
- IMPORTANT — how to talk about this: state that it's a simulation/estimate ONCE, briefly, near the start of your answer, then move on and explain the rest normally. Do NOT repeat "this isn't real mining" / "it's just an estimate" / similar caveats in every paragraph — one clear mention is enough, repeating it reads as nagging.
"BULUT ULUSU" (CLOUD NATION) — THE BOOK BEHIND PEZKUWICHAIN (chapter-by-chapter knowledge):
PezkuwiChain's philosophical foundation is the book "Bulut Ulusu" (Cloud Nation), written by the project's architect (a software developer AND sociologist — the "two desks" of the opening chapter). Available in Turkish, English and Kurdish. Core theses:
@@ -270,66 +269,9 @@ Phase 4 (2028+): Cross-chain governance federation, decentralized identity, stab
License: Apache 2.0, Copyright 2026 Kurdistan Tech Institute. Lead Architect: SatoshiQaziMuhammed.`;
// Groq's openai/gpt-oss-120b returns intermittent errors under load (429/5xx,
// and even a raw 502 from the edge runtime once) unrelated to the question
// asked — confirmed live 2026-07-21 by hitting this endpoint repeatedly with
// trivial questions ("merhaba") and seeing a ~50% failure rate with 15s+
// between calls (ruling out our own per-IP rate limiter), which 2 retries on
// the same model did not fully fix.
//
// 2026-07-21, user decision: prioritize reliability over gpt-oss-120b's
// better Turkish/Kurdish fluency (it was picked for that reason via an
// earlier A/B test) — llama-3.1-8b-instant is Groq's smallest/fastest model
// and, being long out of preview, has historically the best free-tier
// availability, so it goes first. gpt-oss-120b stays as the 2nd attempt
// (still worth trying for quality when the primary is having its own bad
// moment), llama-3.3-70b-versatile (the model used before switching to
// gpt-oss-120b) as the 3rd, before ever reaching the Anthropic fallback
// below. Retries a 4xx (bad request/auth) not at all — that's not transient
// and switching models wouldn't help either.
const GROQ_MODELS = ['llama-3.1-8b-instant', 'openai/gpt-oss-120b', 'llama-3.3-70b-versatile'];
async function callGroqWithRetry(
systemPrompt: string,
userMessage: string,
retriesPerModel = 2
): Promise<string | null> {
for (const model of GROQ_MODELS) {
for (let attempt = 0; attempt <= retriesPerModel; attempt++) {
try {
const gr = await fetch('https://api.groq.com/openai/v1/chat/completions', {
method: 'POST',
headers: { Authorization: 'Bearer ' + GROQ_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
model,
temperature: 0.3,
max_tokens: 900,
messages: [
{ role: 'system', content: systemPrompt },
{ role: 'user', content: userMessage },
],
}),
});
if (gr.ok) {
const gd = await gr.json();
const reply = gd.choices?.[0]?.message?.content || null;
if (reply) return reply;
} else {
console.error('[AI] Groq error:', model, gr.status, await gr.text());
if (gr.status !== 429 && gr.status < 500) break; // non-transient, try next model instead
}
} catch (e) {
console.error('[AI] Groq exception:', model, e);
}
if (attempt < retriesPerModel) await new Promise((r) => setTimeout(r, 400 * (attempt + 1)));
}
}
return null;
}
// ── AI chat handler ──────────────────────────────────────────
// ── Claude AI chat handler ──────────────────────────────────────────
async function handleAIChat(token: string, chatId: number, userMessage: string, userName: string) {
if (!GROQ_API_KEY && !ANTHROPIC_API_KEY) {
if (!ANTHROPIC_API_KEY) {
await sendTelegramRequest(token, 'sendMessage', {
chat_id: chatId,
text: 'AI assistant is being configured. Please try again later.',
@@ -348,7 +290,29 @@ async function handleAIChat(token: string, chatId: number, userMessage: string,
let aiReply: string | null = null;
if (GROQ_API_KEY) {
aiReply = await callGroqWithRetry(CLAUDE_SYSTEM_PROMPT, userMessage);
try {
const gr = await fetch('https://api.groq.com/openai/v1/chat/completions', {
method: 'POST',
headers: { Authorization: 'Bearer ' + GROQ_API_KEY, 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'openai/gpt-oss-120b',
temperature: 0.3,
max_tokens: 900,
messages: [
{ role: 'system', content: CLAUDE_SYSTEM_PROMPT },
{ role: 'user', content: userMessage },
],
}),
});
if (gr.ok) {
const gd = await gr.json();
aiReply = gd.choices?.[0]?.message?.content || null;
} else {
console.error('[AI] Groq error:', gr.status, await gr.text());
}
} catch (e) {
console.error('[AI] Groq exception:', e);
}
}
if (!aiReply && ANTHROPIC_API_KEY) {