AI-Horizon Developer Cookbooks
Explore these step-by-step code recipes to quickly implement common Generative AI patterns using the AI-Horizon low-code SDK.
Recipe 1: Building a PDF ChatBot with custom system prompts
This recipe initializes a conversational chatbot targeting a PDF file and applies a strict system prompt to control its persona:
import { ChatBot } from '@ai-horizon/sdk';
const financialBot = ChatBot.pdf_chat({
input_files: ["./reports/q2_earnings.pdf"],
system_prompt: "You are a conservative financial analyst. Focus strictly on numbers and cite percentages when possible.",
temperature: 0.1
});
const query = "What is the revenue increase percent?";
const response = await financialBot.chat(query);
console.log("Answer:", response.text);Recipe 2: Stateless Q&A Bot with high similarity thresholds
To prevent hallucinations in customer-facing compliance lookup search engines, use QABot with an custom similarity score threshold:
import { QABot } from '@ai-horizon/sdk';
const policyFinder = QABot.pdf_qa({
input_files: ["./handbooks/security_policy.pdf"],
score_threshold: 0.8, // Only use search matches with >80% confidence
system_prompt: "If the context doesn't contain the answer, reply: 'I cannot verify this information.'"
});
const result = await policyFinder.query("What is our policy on visitor badge expiration?");
console.log("Answer:", result.answer);Recipe 3: Integrating Voice Bot for transcribing and responding to client calls
This python recipe demonstrates how to pass local audio inputs, query the core RAG database, and output organic synthesized audio response files:
from aih import VoiceBot
# Create Voice Bot Client
client = VoiceBot(
api_key="your_workspace_api_key",
system_prompt="Greet the user, answer their question, and keep replies under 2 sentences."
)
# Process the audio conversation turn
result = client.process_audio(
audio_file_path="./queries/incoming_call_01.wav",
output_audio_path="./responses/reply_call_01.wav"
)
print("Transcription:", result.transcription)
print("Synthesized Audio Saved to:", result.output_audio_path)