Created
January 19, 2026 20:35
-
-
Save lovemycodesnippets/7fd8c095f62a24872b878ceacb70e029 to your computer and use it in GitHub Desktop.
How to Build Production-Ready AI Agents with RAG and FastAPI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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