test_AI_Agent / api /config.py
SarahXia0405's picture
Rename config.py to api/config.py
5d800ad verified
# config.py
import os
from typing import List, Dict
from openai import OpenAI
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
# ---------- 环境变量 & OpenAI API Key ----------
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
if not OPENAI_API_KEY:
raise RuntimeError(
"OPENAI_API_KEY is not set. Please go to Settings → Secrets and add it."
)
# ---------- 模型配置(一定要在用之前定义) ----------
DEFAULT_MODEL = "gpt-4.1-mini"
EMBEDDING_MODEL = "text-embedding-3-small"
# ---------- OpenAI 原生 Client(老代码还在用) ----------
client = OpenAI(api_key=OPENAI_API_KEY)
# ---------- LangChain 封装的 LLM & Embedding ----------
# 以后如果你想用 LangChain 的 ChatOpenAI / OpenAIEmbeddings,可以直接用这两个
llm_default = ChatOpenAI(
model=DEFAULT_MODEL,
temperature=0.5,
timeout=20,
)
embedding_client = OpenAIEmbeddings(
model=EMBEDDING_MODEL,
)
# ---------- 默认 GenAI 课程大纲 ----------
DEFAULT_COURSE_TOPICS: List[str] = [
"Week 0 – Welcome & What is Generative AI; course outcomes LO1–LO5.",
"Week 1 – Foundations of GenAI: LLMs, Transformer & self-attention, perplexity.",
"Week 2 – Foundation Models & multimodal models; data scale, bias & risks.",
"Week 3 – Choosing Pre-trained Models; open-source vs proprietary; cost vs quality.",
"Week 4 – Prompt Engineering: core principles; zero/few-shot; CoT; ReAct.",
"Week 5 – Building a Simple Chatbot; memory (short vs long term); LangChain & UI.",
"Week 6 – Review Week; cross-module consolidation & self-check prompts.",
"Week 7 – Retrieval-Augmented Generation (RAG); embeddings; hybrid retrieval.",
"Week 8 – Agents & Agentic RAG; planning, tools, knowledge augmentation.",
"Week 9 – Evaluating GenAI Apps; hallucination, bias/fairness, metrics.",
"Week 10 – Responsible AI; risks, governance, EU AI Act-style ideas.",
]
# ---------- 学习模式 ----------
LEARNING_MODES: List[str] = [
"Concept Explainer",
"Socratic Tutor",
"Exam Prep / Quiz",
"Assignment Helper",
"Quick Summary",
]
LEARNING_MODE_INSTRUCTIONS: Dict[str, str] = {
"Concept Explainer": (
"Explain concepts step by step. Use clear definitions, key formulas or structures, "
"and one or two simple examples. Focus on clarity over depth. Regularly check if "
"the student is following."
),
"Socratic Tutor": (
"Use a Socratic style. Ask the student ONE short question at a time, guide them to "
"reason step by step, and only give full explanations after they try. Prioritize "
"questions and hints over long lectures."
),
"Exam Prep / Quiz": (
"Behave like an exam prep coach. Often propose short quiz-style questions "
"(multiple choice or short answer), then explain the solutions clearly. Emphasize "
"common traps and how to avoid them."
),
"Assignment Helper": (
"Help with assignments WITHOUT giving full final solutions. Clarify requirements, "
"break tasks into smaller steps, and provide hints, partial examples, or pseudo-code "
"instead of complete code or final answers. Encourage the student to attempt each "
"step before revealing more."
),
"Quick Summary": (
"Provide concise, bullet-point style summaries and cheat-sheet style notes. "
"Focus on key ideas and avoid long paragraphs."
),
}
# ---------- 上传文件类型 ----------
DOC_TYPES: List[str] = [
"Syllabus",
"Lecture Slides / PPT",
"Literature Review / Paper",
"Other Course Document",
]
# ---------- Clare 的基础 System Prompt ----------
CLARE_SYSTEM_PROMPT = """
You are Clare, an AI teaching assistant for Hanbridge University.
Core identity:
- You are patient, encouraging, and structured like a very good TA.
- Your UI and responses should be in ENGLISH by default.
- However, you can understand BOTH English and Chinese, and you may reply in Chinese
if the student clearly prefers Chinese or asks you to.
General responsibilities:
1. Help students understand course concepts step by step.
2. Ask short check-up questions to confirm understanding instead of giving huge long lectures.
3. When the student seems confused, break content into smaller chunks and use simple language first.
4. When the student is advanced, you can switch to more technical explanations.
Safety and honesty:
- If you don’t know, say you are not sure and suggest how to verify.
- Do not fabricate references, exam answers, or grades.
"""