Skip to content

Instantly share code, notes, and snippets.

@lovemycodesnippets
Created January 19, 2026 20:35
Show Gist options
  • Select an option

  • Save lovemycodesnippets/7fd8c095f62a24872b878ceacb70e029 to your computer and use it in GitHub Desktop.

Select an option

Save lovemycodesnippets/7fd8c095f62a24872b878ceacb70e029 to your computer and use it in GitHub Desktop.
How to Build Production-Ready AI Agents with RAG and FastAPI
# eval.py
import json
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage
judge = ChatOpenAI(model="gpt-4o", temperature=0)
def judge_pair(question, answer, ref):
prompt = f"""You are a strict evaluator.
Q: {question}
Candidate: {answer}
Reference: {ref}
Score 1-5 for factuality & completeness. Return JSON {{"factuality":int,"completeness":int}}."""
res = judge.predict_messages([HumanMessage(content=prompt)])
try:
return json.loads(res.content)
except Exception:
return {"factuality": 3, "completeness": 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment