Basic Custom Prompt
Control how your chatbot responds:
from langchat import LangChat
from langchat.llm import OpenAI
from langchat.vector_db import Pinecone
from langchat.database import Supabase
# Custom system prompt
custom_prompt = """You are a helpful assistant.
Answer questions clearly and concisely.
Always be friendly and professional.
Context: {context}
History: {chat_history}
Question: {question}
Answer:"""
# Setup
llm = OpenAI(api_key="sk-...", model="gpt-4o-mini")
vector_db = Pinecone(api_key="...", index_name="...")
db = Supabase(url="https://...", key="...")
# Create with custom prompt
ai = LangChat(
llm=llm,
vector_db=vector_db,
db=db,
prompt_template=custom_prompt
)
result = await ai.chat(
query="What is Python?",
user_id="user123"
)
Education Example
Specialized education assistant:
EDUCATION_PROMPT = """You are an expert education consultant.
Your expertise:
- University recommendations
- Admission requirements
- Scholarships and funding
- Visa requirements
Be friendly, professional, and concise.
Context: {context}
History: {chat_history}
Question: {question}
Answer:"""
ai = LangChat(
llm=llm,
vector_db=vector_db,
db=db,
prompt_template=EDUCATION_PROMPT
)
Customer Support Example
Professional support agent:
SUPPORT_PROMPT = """You are a customer support agent.
Guidelines:
- Be professional and empathetic
- Provide step-by-step solutions
- Ask clarifying questions when needed
Product Info: {context}
Previous Chat: {chat_history}
Customer Question: {question}
Response:"""
ai = LangChat(
llm=llm,
vector_db=vector_db,
db=db,
prompt_template=SUPPORT_PROMPT
)
Custom prompts let you control your chatbot’s personality, tone, and expertise. Use variables like {context}, {chat_history}, and {question} to include dynamic content.
Prompt Variables
Available variables in your prompt:
{context} - Retrieved documents from your knowledge base
{chat_history} - Previous conversation messages
{question} - Current user question
Next Steps
Built with ❤️ by NeuroBrain