Skip to content

Feature/be 018 ai assistant - #323

Open
spartan124 wants to merge 3 commits into
DigiNodes:mainfrom
spartan124:feature/be-018-ai-assistant
Open

Feature/be 018 ai assistant#323
spartan124 wants to merge 3 commits into
DigiNodes:mainfrom
spartan124:feature/be-018-ai-assistant

Conversation

@spartan124

@spartan124 spartan124 commented Jul 28, 2026

Copy link
Copy Markdown

📚 Overview

This PR introduces the server-side infrastructure that powers TruthBounty's intelligent AI
Assistant. The API acts as the core orchestration layer between verified protocol state and
external Large Language Models (LLMs), allowing contributors to safely interact with the
protocol via natural language.

By using Retrieval-Augmented Generation (RAG) and maintaining strict read-only execution
constraints, we ensure the assistant remains a helpful guide without ever becoming a source of
unverified truth.

🚀 What Changed

  • Conversation Management: Added Conversation and Message tables to the Prisma schema,
    paired with standard CRUD endpoints (AiAssistantController) for chat history retention.
  • RAG Integration: Introduced RagService which retrieves and sanitizes verified
    protocol state (claims, reputation, governance) into the LLM context payload.
  • LLM Provider Abstraction: Implemented LlmProviderService to support routing requests
    to multiple providers (e.g. OpenAI gpt-4o-mini, Anthropic claude-3-haiku).
  • Security & Scoping: Applied JwtAuthGuard ensuring users can only interact with and
    view their own private conversation sessions.
  • Usage & Metrics Tracking: Added AiUsageMetric model to track token consumption
    (prompt/completion) and request latency for cost monitoring.
  • Documentation: Created comprehensive developer references:
    • docs/AI_ARCHITECTURE.md (System design & flow)
    • docs/PROMPT_ENGINEERING_GUIDE.md (System prompt tuning guidelines)
  • Bug Fixes:
    • Resolved PrismaClientInitializationError in schema.prisma by standardizing the
      provider dialect for v7.
    • Fixed pre-existing syntax errors in src/jobs/jobs.service.ts.

🛠 Testing

  • ✅ Wrote dedicated unit tests for the core orchestration logic (src/ai-assistant/ai- assistant.service.spec.ts).
  • ✅ Verified Prisma generation and local SQLite runtime compatibility.
  • ✅ Successfully resolved conflicts with main and verified integration with recent
    Admin/Profiler modules.

🔗 Closes

@dDevAhmed

Copy link
Copy Markdown
Contributor

Resolve conflicts; edit issue reference @spartan124

# Conflicts:
#	PR_MESSAGE.md
#	package-lock.json
#	package.json
#	prisma/schema.prisma
#	src/ai-assistant/ai-assistant.module.ts
#	src/app.module.ts
#	src/generated/client/browser.ts
#	src/generated/client/client.ts
#	src/generated/client/commonInputTypes.ts
#	src/generated/client/internal/class.ts
#	src/generated/client/internal/prismaNamespace.ts
#	src/generated/client/internal/prismaNamespaceBrowser.ts
#	src/generated/client/models.ts
#	src/generated/client/models/SybilExplanation.ts
#	src/generated/client/models/User.ts
#	src/generated/client/models/WorldIdVerification.ts
#	src/jobs/jobs.service.spec.ts
#	src/jobs/jobs.service.ts
@spartan124

Copy link
Copy Markdown
Author

@dDevAhmed conflicts resolved and PR description updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BE-018 — Implement AI Assistant Backend API

2 participants