Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

데이터 합성 파이프라인 (ChainMaker)

ReAct 방식의 tool calling을 포함한 대화형 데이터 합성 파이프라인입니다.

주요 기능

  • ChainMaker: 체인 생성 및 관리를 위한 통합 클래스
  • 병렬 처리: ThreadPoolExecutor를 사용한 다중 워커 처리
  • 유연한 설정: YAML 기반 설정 파일
  • 다양한 생성 방식: Single/Multiple response 생성 지원
  • 성능 모니터링: 토큰 수, 추론 시간, 처리 속도 추적

프로젝트 구조

simple_ver/
├── config/
│   ├── models.yaml      # 모델 설정
│   └── pipeline.yaml    # 파이프라인 설정
├── src/
│   ├── chain_maker.py   # 메인 체인 생성 클래스
│   ├── data_processor.py # 병렬 처리 클래스
│   └── generator.py     # 응답 생성기
├── prompts/            # 프롬프트 템플릿
├── data/              # 입력 데이터
├── main.py            # 메인 실행 파일
└── test_chain.py      # 테스트 스크립트

설치

# 필요한 패키지 설치
pip install openai pydantic tiktoken transformers pyyaml

사용법

1. 단일 쿼리 처리

python main.py --mode single --query "서울 날씨 어때?" --output result.json

2. 배치 처리

python main.py --mode batch --input data/questions.jsonl --output data/output/results.jsonl --num-workers 4

3. 디렉토리 처리

python main.py --mode directory --input data/ --output data/output/ --pattern "*.jsonl" --num-workers 4

4. Python API 사용

from src.chain_maker import ChainMaker
from src.data_processor import DataProcessor

# 단일 체인 생성
chain_maker = ChainMaker()
result = chain_maker.generate_chain(
    query="서울 날씨 어때?",
    tools=tools,
    method="multiple",
    n_responses=8
)

# 배치 처리
processor = DataProcessor()
stats = processor.process_batch(
    input_file="data/questions.jsonl",
    output_file="data/results.jsonl",
    num_workers=4
)

설정 파일

models.yaml

  • 모델별 설정 (API URL, 키, 생성 파라미터)
  • 역할별 기본 모델 지정
  • 프롬프트 버전 관리

pipeline.yaml

  • 생성 설정 (max_turns, max_tries, n_responses)
  • 처리 설정 (num_workers, batch_size)
  • 입출력 경로 설정
  • 로깅 설정

입력 데이터 형식

JSONL 파일 형식:

{"question": "질문 내용"}
{"query": "또 다른 질문"}

출력 데이터 형식

{
  "original_query": "원본 질문",
  "original_data": {...},
  "result": {
    "chat_history": [...],
    "method": "multiple",
    "total_turns": 3,
    "final_answer": "최종 답변",
    "stats": {
      "total_tokens": 1234,
      "total_inference_time": 5.67,
      "total_calls": 8
    }
  },
  "timestamp": "2024-01-01T12:00:00"
}

성능 정보

각 응답에는 다음 정보가 포함됩니다:

  • tokens: 토큰 수 (think, answer, tool_calls별)
  • inference_time: 추론 시간 (초)
  • tokens_per_sec: 처리 속도 (토큰/초)

테스트

python test_chain.py

주요 개선사항

  1. 통합 클래스 구조: 기존 함수들을 ChainMaker 클래스로 통합
  2. 성능 모니터링: 추론 시간과 토큰 정보 자동 추적
  3. 설정 분리: YAML 파일로 설정 관리
  4. 병렬 처리: ThreadPoolExecutor를 사용한 효율적인 배치 처리
  5. 유연한 실행: CLI와 Python API 모두 지원

About

ReAct-style tool-calling data synthesis pipeline (ChainMaker) — supports parallel batch processing, multi-response generation, and YAML-based configuration

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages