Yoon-gu Hwang Claude commited on
Commit
3b42a60
·
1 Parent(s): c6a59e0

LangSmith observability 추가 및 UI 개선

Browse files

- LangSmith 추적 기능 추가 (observability)
- .env에 LANGCHAIN_TRACING_V2, LANGCHAIN_API_KEY 설정
- .env.example 템플릿 파일 생성
- pyproject.toml에 langsmith 의존성 추가
- README에 설정 방법 상세 문서화

- Chatbot UI 기능 개선
- Like/Dislike 버튼 추가 (gr.Blocks로 구조 변경)
- Copy, Copy All, Share 버튼 추가
- Clear 버튼 기본 포함

- ML Pipeline 예제 확장
- 전체 파이프라인 예제 (4단계)
- 조합 예제 추가 (2-3단계 조합)
- 단일 기능 예제 유지
- 다양한 시나리오 테스트 가능

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (4) hide show
  1. .env.example +8 -0
  2. README.md +20 -4
  3. app.py +65 -30
  4. pyproject.toml +1 -0
.env.example ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ # OpenAI API Key
2
+ OPENAI_API_KEY=your-openai-api-key-here
3
+
4
+ # LangSmith Observability (Optional)
5
+ # Get your API key from https://smith.langchain.com/
6
+ LANGCHAIN_TRACING_V2=true
7
+ LANGCHAIN_API_KEY=your-langsmith-api-key-here
8
+ LANGCHAIN_PROJECT=langgraph-ui
README.md CHANGED
@@ -40,11 +40,22 @@ uv sync
40
  ```
41
 
42
  2. Set up environment variables:
43
- Create a `.env` file in the root directory:
44
- ```
 
45
  OPENAI_API_KEY=your-openai-api-key-here
 
 
 
 
 
46
  ```
47
 
 
 
 
 
 
48
  3. Run the application:
49
  ```bash
50
  uv run python app.py
@@ -54,13 +65,17 @@ The application will start on `http://localhost:7860`
54
 
55
  ### HuggingFace Spaces Deployment
56
 
57
- To deploy on HuggingFace Spaces, you need to set the `OPENAI_API_KEY` as a secret:
58
 
59
  1. Go to your Space settings
60
  2. Navigate to "Repository secrets"
61
- 3. Add a new secret:
62
  - Name: `OPENAI_API_KEY`
63
  - Value: your OpenAI API key
 
 
 
 
64
 
65
  ## Project Structure
66
 
@@ -78,6 +93,7 @@ To deploy on HuggingFace Spaces, you need to set the `OPENAI_API_KEY` as a secre
78
  - [LangGraph](https://langchain-ai.github.io/langgraph/) - Agent orchestration
79
  - [LangChain](https://langchain.com/) - LLM framework
80
  - [OpenAI](https://openai.com/) - LLM provider
 
81
  - [uv](https://github.com/astral-sh/uv) - Python package manager
82
 
83
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
40
  ```
41
 
42
  2. Set up environment variables:
43
+ Create a `.env` file in the root directory (or copy from `.env.example`):
44
+ ```bash
45
+ # Required
46
  OPENAI_API_KEY=your-openai-api-key-here
47
+
48
+ # Optional: LangSmith Observability
49
+ LANGCHAIN_TRACING_V2=true
50
+ LANGCHAIN_API_KEY=your-langsmith-api-key-here
51
+ LANGCHAIN_PROJECT=langgraph-ui
52
  ```
53
 
54
+ To get a LangSmith API key:
55
+ - Sign up at [LangSmith](https://smith.langchain.com/)
56
+ - Create an API key in your settings
57
+ - LangSmith provides observability for all agent executions, traces, and performance metrics
58
+
59
  3. Run the application:
60
  ```bash
61
  uv run python app.py
 
65
 
66
  ### HuggingFace Spaces Deployment
67
 
68
+ To deploy on HuggingFace Spaces, set these secrets:
69
 
70
  1. Go to your Space settings
71
  2. Navigate to "Repository secrets"
72
+ 3. Add required secret:
73
  - Name: `OPENAI_API_KEY`
74
  - Value: your OpenAI API key
75
+ 4. (Optional) Add LangSmith secrets for observability:
76
+ - `LANGCHAIN_TRACING_V2=true`
77
+ - `LANGCHAIN_API_KEY=your-langsmith-api-key`
78
+ - `LANGCHAIN_PROJECT=langgraph-ui`
79
 
80
  ## Project Structure
81
 
 
93
  - [LangGraph](https://langchain-ai.github.io/langgraph/) - Agent orchestration
94
  - [LangChain](https://langchain.com/) - LLM framework
95
  - [OpenAI](https://openai.com/) - LLM provider
96
+ - [LangSmith](https://smith.langchain.com/) - Observability and monitoring (optional)
97
  - [uv](https://github.com/astral-sh/uv) - Python package manager
98
 
99
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -187,6 +187,14 @@ def generate_response_basic_chatbot(message, history):
187
  yield response
188
 
189
 
 
 
 
 
 
 
 
 
190
  def generate_response_ml_pipeline(message, history):
191
  """ML Pipeline 워크플로우에 대한 nested thought 응답 생성"""
192
  inputs = {
@@ -367,36 +375,63 @@ def generate_response_ml_pipeline(message, history):
367
  yield response
368
 
369
 
370
- # Create Basic Chatbot interface
371
- basic_chatbot_demo = gr.ChatInterface(
372
- generate_response_basic_chatbot,
373
- type="messages",
374
- title="🤖 Multi-Agent Chatbot",
375
- description="Research와 Math 에이전트가 협력하여 작업을 수행합니다. 각 에이전트의 사고 과정을 실시간으로 확인할 수 있습니다.",
376
- examples=[
377
- "2024년의 FAANG companies 총 근로자규모에 대한 분석을 한국어로 부탁해!",
378
- "123과 456을 곱하고 그 결과에 789를 더해줘",
379
- "구글의 직원 수를 찾아서 애플의 직원 수와 비교해줘"
380
- ],
381
- cache_examples=False
382
- )
383
-
384
- # Create ML Pipeline interface
385
- ml_pipeline_demo = gr.ChatInterface(
386
- generate_response_ml_pipeline,
387
- type="messages",
388
- title="🔬 ML Pipeline Automation",
389
- description="데이터 추출, 사전학습, 파인튜닝, 평가 단계를 거치는 완전한 ML 파이프라인입니다. 각 전문가 에이전트의 작업 과정을 단계별로 확인할 수 있습니다.",
390
- examples=[
391
- "user_events 테이블에서 2024-01-01부터 2024-12-31까지 이벤트 데이터를 추출하고, 모델을 사전학습한 후 5개 클래스 분류 모델을 학습하고 평가해줘",
392
- "customer_logs 테이블에서 2024년 1분기 데이터를 추출하고, GPT2 모델로 사전학습 후 감성분석용 3클래스 분류 모델 만들어줘",
393
- "transaction_data 테이블에서 최근 6개월 데이터로 이상거래 탐지 모델 학습하고 성능 평가 부탁해",
394
- "준비된 데이터(/data/pretraining/corpus.txt) GPT-2 모델을 3 에포크 사전학습만 해줘",
395
- "사전학습된 모델(/models/pretrained/checkpoint)으로 감성분석 3클래스 분류 파인튜닝만 진행해줘",
396
- "학습된 모델(/models/finetuned/model)을 테스트 데이터(/data/test.jsonl)로 평가만 해줘"
397
- ],
398
- cache_examples=False
399
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
 
401
  # Create tabbed interface
402
  demo = gr.TabbedInterface(
 
187
  yield response
188
 
189
 
190
+ def handle_like(data: gr.LikeData):
191
+ """Like/dislike 이벤트 핸들러"""
192
+ if data.liked:
193
+ print(f"👍 Upvoted: {data.value}")
194
+ else:
195
+ print(f"👎 Downvoted: {data.value}")
196
+
197
+
198
  def generate_response_ml_pipeline(message, history):
199
  """ML Pipeline 워크플로우에 대한 nested thought 응답 생성"""
200
  inputs = {
 
375
  yield response
376
 
377
 
378
+ # Create interfaces with Blocks for like functionality
379
+ with gr.Blocks() as basic_chatbot_demo:
380
+ basic_chatbot = gr.Chatbot(
381
+ type="messages",
382
+ show_copy_button=True,
383
+ show_copy_all_button=True,
384
+ show_share_button=True
385
+ )
386
+ basic_chatbot.like(handle_like, None, None)
387
+
388
+ gr.ChatInterface(
389
+ generate_response_basic_chatbot,
390
+ type="messages",
391
+ chatbot=basic_chatbot,
392
+ title="🤖 Multi-Agent Chatbot",
393
+ description="Research와 Math 에이전트가 협력하여 작업을 수행합니다. 각 에이전트의 사고 과정을 실시간으로 확인할 수 있습니다.",
394
+ examples=[
395
+ "2024년의 FAANG companies 총 근로자규모에 대한 분석을 한국어로 부탁해!",
396
+ "123과 456을 곱하고 그 결과에 789를 더해줘",
397
+ "구글의 직원 수를 찾아서 애플의 직원 수와 비교해줘"
398
+ ],
399
+ cache_examples=False
400
+ )
401
+
402
+ with gr.Blocks() as ml_pipeline_demo:
403
+ ml_pipeline_chatbot = gr.Chatbot(
404
+ type="messages",
405
+ show_copy_button=True,
406
+ show_copy_all_button=True,
407
+ show_share_button=True
408
+ )
409
+ ml_pipeline_chatbot.like(handle_like, None, None)
410
+
411
+ gr.ChatInterface(
412
+ generate_response_ml_pipeline,
413
+ type="messages",
414
+ chatbot=ml_pipeline_chatbot,
415
+ title="🔬 ML Pipeline Automation",
416
+ description="데이터 추출, 사전학습, 파인튜닝, 평가 단계를 거치는 완전한 ML 파이프라인입니다. 각 전문가 에이전트의 작업 과정을 단계별로 확인할 수 있습니다.",
417
+ examples=[
418
+ # 전체 파이프라인 예제
419
+ "user_events 테이블에서 2024-01-01부터 2024-12-31까지 이벤트 데이터를 추출하고, 모델을 사전학습한 후 5개 클래스 분류 모델을 학습하고 평가해줘",
420
+ "transaction_data 테이블에서 최근 6개월 데이터로 이상거래 탐지 모델을 처음부터 끝까지 만들어줘",
421
+
422
+ # 조합 예제 (2-3단계)
423
+ "customer_logs 테이블에서 2024년 데이터를 추출하고 GPT-2 모델 사전학습까지만 해줘",
424
+ "준비된 데이터(/data/corpus.txt)로 모델을 사전학습하고, 그 모델로 감성분석 3클래스 분류 파인튜닝까지 진행해줘",
425
+ "사전학습된 모델(/models/pretrained/gpt2)로 spam detection 2클래스 분류 모델 학습하고 성능 평가해줘",
426
+ "product_reviews 테이블에서 2024��� 리뷰 데이터 추출하고 바로 별점 예측 5클래스 분류 모델 파인튜닝해줘",
427
+
428
+ # 단일 기능 예제
429
+ "준비된 데이터(/data/pretraining/corpus.txt)로 GPT-2 모델을 3 에포크 사전학습만 해줘",
430
+ "사전학습된 모델(/models/pretrained/checkpoint)으로 감성분석 3클래스 분류 파인튜닝만 진행해줘",
431
+ "학습된 모델(/models/finetuned/model)을 테스트 데이터(/data/test.jsonl)로 평가만 해줘"
432
+ ],
433
+ cache_examples=False
434
+ )
435
 
436
  # Create tabbed interface
437
  demo = gr.TabbedInterface(
pyproject.toml CHANGED
@@ -11,6 +11,7 @@ dependencies = [
11
  "langchain-teddynote",
12
  "gradio>=5.41.0",
13
  "python-dotenv",
 
14
  ]
15
 
16
  [build-system]
 
11
  "langchain-teddynote",
12
  "gradio>=5.41.0",
13
  "python-dotenv",
14
+ "langsmith",
15
  ]
16
 
17
  [build-system]