Skip to content

Latest commit

 

History

History
386 lines (280 loc) · 11.3 KB

File metadata and controls

386 lines (280 loc) · 11.3 KB

🧠 AI推理能力改进说明 / AI Reasoning Improvements

问题 / Problem

之前当你问 "Do you think Oliver can fit AI agent developer position?" 时,AI会回答 "I don't know"。

Previously, when asking "Do you think Oliver can fit AI agent developer position?", the AI would reply "I don't know."


解决方案 / Solution

我对 app.py 做了以下改进:

I made the following improvements to app.py:

1️⃣ 增加了系统提示词 (System Prompt)

添加了一个详细的系统提示,告诉AI如何处理问题:

Added a detailed system prompt that tells the AI how to handle questions:

system_template = """You are an intelligent AI assistant analyzing Oliver's professional background and qualifications.

Your job is to:
1. Carefully analyze the provided context from Oliver's documents
2. Make reasonable inferences and connections between different pieces of information
3. Provide thoughtful, evidence-based answers
4. If asked about Oliver's fit for a position, analyze his skills, experience, and projects to give a reasoned opinion
5. Always cite specific examples from the documents when making your points
6. If you genuinely don't have enough information, say so, but try to provide what relevant information you do have
"""

作用:

  • 🎯 让AI知道它的角色是"分析Oliver的专业背景"
  • 🧩 指导AI要进行推理和连接不同信息
  • 📊 要求AI提供基于证据的答案
  • 💡 特别强调:不要只说"I don't know",要尽可能利用现有信息

2️⃣ 增加检索文档数量 (Increased Retrieved Documents)

之前: retriever = vectorstore.as_retriever() (默认k=4)

现在: retriever = vectorstore.as_retriever(search_kwargs={"k": 5})

作用:

  • 📚 从4个文档增加到5个文档
  • 🔍 提供更多上下文给AI
  • 🎯 帮助AI找到更多相关信息来做判断

3️⃣ 添加了自定义提示模板 (Custom Prompt Template)

使用 ChatPromptTemplate 来组织系统提示和用户问题:

messages = [
    SystemMessagePromptTemplate.from_template(system_template),
    HumanMessagePromptTemplate.from_template("{question}")
]
qa_prompt = ChatPromptTemplate.from_messages(messages)

作用:

  • 📝 确保每次对话都包含系统提示
  • 🔄 保持上下文的一致性
  • 💬 让AI始终记得它的角色和任务

4️⃣ 改进了对话链配置 (Improved Chain Configuration)

conversation_chain = ConversationalRetrievalChain.from_llm(
    llm=llm, 
    retriever=retriever, 
    memory=memory,
    return_source_documents=True,  # 新增:返回源文档
    combine_docs_chain_kwargs={"prompt": qa_prompt}  # 新增:使用自定义提示
)

现在的效果 / Current Effect

❌ 之前 (Before):

问题: "Do you think Oliver can fit AI agent developer position?"
回答: "I don't know."

✅ 现在 (Now):

问题: "Do you think Oliver can fit AI agent developer position?"
回答:

"Based on Oliver's background, I believe he would be a strong fit for an AI agent developer position. Here's why:

  1. Technical Skills: His resume shows experience with Python, machine learning, and AI frameworks
  2. Relevant Projects: He has worked on [specific project] which involved...
  3. Experience: His role at [company] required similar skills...

Overall, Oliver has the technical foundation and practical experience needed for this role."


工作原理 / How It Works

用户提问 (User Question)
    ↓
检索相关文档 (Retrieve Relevant Docs) - 现在检索5个文档
    ↓
系统提示 + 文档内容 (System Prompt + Documents)
    ↓
AI分析和推理 (AI Analyzes & Reasons)
    ↓
生成基于证据的回答 (Generate Evidence-Based Answer)
    ↓
返回给用户 (Return to User)

示例问题 / Example Questions

现在AI可以回答这些类型的问题:

The AI can now answer these types of questions:

💼 职位匹配分析 / Position Fit Analysis

  • "Do you think Oliver can fit AI agent developer position?"
  • "Is Oliver qualified for a senior machine learning role?"
  • "Would Oliver be good for a data scientist position?"

🎯 技能评估 / Skills Assessment

  • "What are Oliver's strongest technical skills?"
  • "Does Oliver have experience with Python and AI?"
  • "What programming languages does Oliver know?"

📊 项目分析 / Project Analysis

  • "What AI projects has Oliver worked on?"
  • "Can you summarize Oliver's most impressive projects?"
  • "Has Oliver built any machine learning systems?"

🏢 经验总结 / Experience Summary

  • "What companies has Oliver worked for?"
  • "How many years of experience does Oliver have in AI?"
  • "What was Oliver's most significant role?"

🎓 教育背景 / Education Background

  • "What is Oliver's educational background?"
  • "Does Oliver have relevant degrees for tech roles?"
  • "What certifications does Oliver have?"

高级设置 / Advanced Settings

调整推理能力 / Adjust Reasoning Capability

app.py 中,你可以调整这些参数:

In app.py, you can adjust these parameters:

# 调整温度 (更高 = 更有创意,更低 = 更保守)
# Adjust temperature (higher = more creative, lower = more conservative)
llm = ChatOpenAI(temperature=0.7, model_name=MODEL)  # 可以改成 0.5-0.9

# 调整检索文档数 (更多 = 更多上下文,但可能更慢)
# Adjust number of retrieved documents (more = more context, but slower)
retriever = vectorstore.as_retriever(search_kwargs={"k": 5})  # 可以改成 3-10

不同场景的建议设置 / Recommended Settings

场景 Temperature k值 说明
面试准备 0.5 7 保守、详细
职位匹配 0.7 5 平衡推理
创意写作 0.9 3 有创造性
事实查询 0.3 5 精确答案

测试建议 / Testing Recommendations

1. 测试推理能力 / Test Reasoning

问:Do you think Oliver is suitable for a startup environment?
看:AI会分析Oliver的经验并给出推理

2. 测试证据引用 / Test Evidence Citation

问:What makes Oliver a good AI developer?
看:AI应该引用具体的项目、技能或经验

3. 测试边界情况 / Test Edge Cases

问:Can Oliver work as a brain surgeon?
看:AI应该说明信息不足,但仍会分析相关的可转移技能

注意事项 / Important Notes

⚠️ AI仍然依赖于文档质量 / AI Still Depends on Document Quality

AI的推理完全基于你提供的文档

The AI's reasoning is entirely based on the documents you provide:

  • ✅ 文档越详细,AI的推理越准确
  • ✅ 确保你的简历、LinkedIn等文档包含足够信息
  • ✅ 定期更新文档以反映最新经验

📝 如何改进文档 / How to Improve Documents

oliver-knowledge-base/ 中添加详细的 .md 文件:

Add detailed .md files in oliver-knowledge-base/:

简历示例:

# Oliver Hong - Resume

## Skills
- Python (5 years)
- Machine Learning: TensorFlow, PyTorch
- AI/LLM: OpenAI API, LangChain, RAG systems
- Cloud: AWS, Docker

## Projects
### AI Personal Assistant (2024)
- Built a RAG system using LangChain and OpenAI
- Implemented vector search with Chroma DB
- Created user-friendly Gradio interface
- Result: Reduced document search time by 80%

### Machine Learning Pipeline (2023)
- Developed automated ML pipeline for [company]
- Technologies: Python, scikit-learn, MLflow
- Impact: Improved model accuracy by 25%

对比效果 / Before vs After

场景1:职位匹配 / Position Fit

问题: "Should we hire Oliver as an AI developer?"

之前 ❌:

"I don't know."

现在 ✅:

"Based on Oliver's qualifications, yes, he would be an excellent hire as an AI developer. Here's my assessment:

Strong Points:

  • 5 years of Python experience
  • Proven track record with AI projects (built a RAG system, ML pipeline)
  • Familiar with modern AI tools (LangChain, OpenAI API)
  • Experience with production systems

Evidence:

  • His Personal AI Assistant project demonstrates practical LLM implementation skills
  • The ML pipeline project shows he can deploy models to production
  • His technical skills directly match the requirements

Recommendation: Oliver has both theoretical knowledge and practical experience needed for this role."


场景2:技能差距分析 / Skills Gap Analysis

问题: "What skills does Oliver need to improve for a senior AI role?"

之前 ❌:

"I don't know what skills Oliver needs to improve."

现在 ✅:

"Based on Oliver's current profile, here are potential areas for growth toward a senior AI role:

Current Strengths:

  • Solid foundation in ML and Python
  • Hands-on experience with LLM applications

Areas to Potentially Strengthen:

  • Leadership experience: If not mentioned, adding examples of mentoring or leading projects
  • Scale: Experience with large-scale systems (millions of users)
  • Research: Publications or conference presentations (if targeting research-heavy roles)

Note: This assessment is based on typical senior AI role requirements and the information available in the documents."


🚀 下一步 / Next Steps

  1. 测试新功能 / Test New Features

    python app.py

    然后问一些需要推理的问题!

  2. 完善文档 / Improve Documents

    • oliver-knowledge-base/ 中添加更详细的信息
    • 包括具体的项目成果、技能水平、工作经验
  3. 调整参数 / Tune Parameters

    • 根据你的需求调整 temperature 和 k 值
    • 测试不同设置的效果
  4. 更新到GitHub / Update GitHub

    cd "/Users/pppop/Desktop/Personal AI"
    git add app.py IMPROVEMENTS_EXPLAINED.md
    git commit -m "Add AI reasoning capabilities with custom system prompt"
    git push

💡 Tips

获得最佳效果:

  1. 详细的文档 📝

    • 在简历中包含具体数字和成果
    • 描述项目时说明你的具体贡献
    • 列出技能的熟练程度
  2. 清晰的问题

    • 具体的问题会得到更好的答案
    • "Is Oliver good at Python?" 比 "Tell me about Oliver" 更好
  3. 定期更新 🔄

    • 完成新项目后更新文档
    • 学习新技能后添加到简历
    • 保持信息最新

现在你的AI助手能够进行智能推理和分析了! 🎉

Your AI assistant can now perform intelligent reasoning and analysis! 🎉


技术细节 / Technical Details

改动的代码部分 / Code Changes

文件: app.py

添加的导入:

from langchain.prompts import PromptTemplate, SystemMessagePromptTemplate, HumanMessagePromptTemplate, ChatPromptTemplate

修改的部分:

  • Line 103: Memory 配置
  • Line 107: Retriever 配置 (k=5)
  • Line 110-129: 系统提示模板
  • Line 132-136: ChatPromptTemplate 创建
  • Line 139-145: ConversationalRetrievalChain 配置

没有改动的部分:

  • ✅ 文档加载逻辑
  • ✅ Embedding 生成
  • ✅ Vector store 创建
  • ✅ Gradio 界面
  • ✅ 其他所有功能

如有问题,请查看main README.md或创建GitHub Issue!

For questions, check the main README.md or create a GitHub Issue!