Spaces:
Sleeping
Sleeping
Create config.py
Browse files
config.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# config.py
|
| 2 |
+
import os
|
| 3 |
+
from typing import List, Dict
|
| 4 |
+
from openai import OpenAI
|
| 5 |
+
|
| 6 |
+
# ---------- 环境变量 & OpenAI Client ----------
|
| 7 |
+
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 8 |
+
if not OPENAI_API_KEY:
|
| 9 |
+
raise RuntimeError(
|
| 10 |
+
"OPENAI_API_KEY is not set. Please go to Settings → Secrets and add it."
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
client = OpenAI(api_key=OPENAI_API_KEY)
|
| 14 |
+
|
| 15 |
+
# ---------- 模型配置 ----------
|
| 16 |
+
DEFAULT_MODEL = "gpt-4.1-mini"
|
| 17 |
+
EMBEDDING_MODEL = "text-embedding-3-small"
|
| 18 |
+
|
| 19 |
+
# ---------- 默认 GenAI 课程大纲 ----------
|
| 20 |
+
DEFAULT_COURSE_TOPICS: List[str] = [
|
| 21 |
+
"Week 0 – Welcome & What is Generative AI; course outcomes LO1–LO5.",
|
| 22 |
+
"Week 1 – Foundations of GenAI: LLMs, Transformer & self-attention, perplexity.",
|
| 23 |
+
"Week 2 – Foundation Models & multimodal models; data scale, bias & risks.",
|
| 24 |
+
"Week 3 – Choosing Pre-trained Models; open-source vs proprietary; cost vs quality.",
|
| 25 |
+
"Week 4 – Prompt Engineering: core principles; zero/few-shot; CoT; ReAct.",
|
| 26 |
+
"Week 5 – Building a Simple Chatbot; memory (short vs long term); LangChain & UI.",
|
| 27 |
+
"Week 6 – Review Week; cross-module consolidation & self-check prompts.",
|
| 28 |
+
"Week 7 – Retrieval-Augmented Generation (RAG); embeddings; hybrid retrieval.",
|
| 29 |
+
"Week 8 – Agents & Agentic RAG; planning, tools, knowledge augmentation.",
|
| 30 |
+
"Week 9 – Evaluating GenAI Apps; hallucination, bias/fairness, metrics.",
|
| 31 |
+
"Week 10 – Responsible AI; risks, governance, EU AI Act-style ideas.",
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
# ---------- 学习模式 ----------
|
| 35 |
+
LEARNING_MODES: List[str] = [
|
| 36 |
+
"Concept Explainer",
|
| 37 |
+
"Socratic Tutor",
|
| 38 |
+
"Exam Prep / Quiz",
|
| 39 |
+
"Assignment Helper",
|
| 40 |
+
"Quick Summary",
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
LEARNING_MODE_INSTRUCTIONS: Dict[str, str] = {
|
| 44 |
+
"Concept Explainer": (
|
| 45 |
+
"Explain concepts step by step. Use clear definitions, key formulas or structures, "
|
| 46 |
+
"and one or two simple examples. Focus on clarity over depth. Regularly check if "
|
| 47 |
+
"the student is following."
|
| 48 |
+
),
|
| 49 |
+
"Socratic Tutor": (
|
| 50 |
+
"Use a Socratic style. Ask the student ONE short question at a time, guide them to "
|
| 51 |
+
"reason step by step, and only give full explanations after they try. Prioritize "
|
| 52 |
+
"questions and hints over long lectures."
|
| 53 |
+
),
|
| 54 |
+
"Exam Prep / Quiz": (
|
| 55 |
+
"Behave like an exam prep coach. Often propose short quiz-style questions "
|
| 56 |
+
"(multiple choice or short answer), then explain the solutions clearly. Emphasize "
|
| 57 |
+
"common traps and how to avoid them."
|
| 58 |
+
),
|
| 59 |
+
"Assignment Helper": (
|
| 60 |
+
"Help with assignments WITHOUT giving full final solutions. Clarify requirements, "
|
| 61 |
+
"break tasks into smaller steps, and provide hints, partial examples, or pseudo-code "
|
| 62 |
+
"instead of complete code or final answers. Encourage the student to attempt each "
|
| 63 |
+
"step before revealing more."
|
| 64 |
+
),
|
| 65 |
+
"Quick Summary": (
|
| 66 |
+
"Provide concise, bullet-point style summaries and cheat-sheet style notes. "
|
| 67 |
+
"Focus on key ideas and avoid long paragraphs."
|
| 68 |
+
),
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
# ---------- 上传文件类型 ----------
|
| 72 |
+
DOC_TYPES: List[str] = [
|
| 73 |
+
"Syllabus",
|
| 74 |
+
"Lecture Slides / PPT",
|
| 75 |
+
"Literature Review / Paper",
|
| 76 |
+
"Other Course Document",
|
| 77 |
+
]
|
| 78 |
+
|
| 79 |
+
# ---------- Clare 的基础 System Prompt ----------
|
| 80 |
+
CLARE_SYSTEM_PROMPT = """
|
| 81 |
+
You are Clare, an AI teaching assistant for Hanbridge University.
|
| 82 |
+
|
| 83 |
+
Core identity:
|
| 84 |
+
- You are patient, encouraging, and structured like a very good TA.
|
| 85 |
+
- Your UI and responses should be in ENGLISH by default.
|
| 86 |
+
- However, you can understand BOTH English and Chinese, and you may reply in Chinese
|
| 87 |
+
if the student clearly prefers Chinese or asks you to.
|
| 88 |
+
|
| 89 |
+
General responsibilities:
|
| 90 |
+
1. Help students understand course concepts step by step.
|
| 91 |
+
2. Ask short check-up questions to confirm understanding instead of giving huge long lectures.
|
| 92 |
+
3. When the student seems confused, break content into smaller chunks and use simple language first.
|
| 93 |
+
4. When the student is advanced, you can switch to more technical explanations.
|
| 94 |
+
|
| 95 |
+
Safety and honesty:
|
| 96 |
+
- If you don’t know, say you are not sure and suggest how to verify.
|
| 97 |
+
- Do not fabricate references, exam answers, or grades.
|
| 98 |
+
"""
|