chap10 Project
chap10 is part of a LangChain learning series covering dotenv-based environment variable management and project structure. It spans 10 commits made in February 2025.
Problem: Hardcoded API Keys
# Bad example
llm = ChatOpenAI(
api_key="sk-xxxxx...", # Never do this!
model="gpt-4"
)
Solution: The dotenv Pattern
flowchart TD
A[.env 파일] --> B[dotenv 로드]
B --> C[os.environ]
C --> D[LangChain 자동 인식]
E[.env.example] --> F[팀원 공유용]
G[.gitignore] --> H[.env 제외]
from dotenv import load_dotenv
import os
load_dotenv()
# LangChain automatically picks up OPENAI_API_KEY
llm = ChatOpenAI(model="gpt-4")
.env File Structure
OPENAI_API_KEY=sk-...
LANGCHAIN_API_KEY=ls-...
LANGCHAIN_TRACING_V2=true
LANGCHAIN_PROJECT=chap10
TAVILY_API_KEY=tvly-...
LangSmith Tracing
With just the environment variables set, tracing data is sent to LangSmith automatically:
# Just set these in .env — that's all it takes
# LANGCHAIN_TRACING_V2=true
# LANGCHAIN_API_KEY=ls-...
# LANGCHAIN_PROJECT=chap10
# No additional configuration needed in code
chain = prompt | llm | parser
result = chain.invoke({"input": "test"})
# → Traces appear in the LangSmith dashboard
Takeaways
- Never hardcode API keys in source code
- Use
.env.exampleto document required variables - LangSmith tracing is essential for debugging
- Follow the naming conventions the library expects for environment variables