配置任務的資料來源
Configures data sources for LLM training tasks including databases, APIs, web scraping, LLM generation, and file imports.
/plugin marketplace add p988744/nlp-skills/plugin install p988744-nlp-skills@p988744/nlp-skillstask-namesonnet配置 LLM 訓練任務的資料來源,支援資料庫、API、爬取、LLM 生成等多種來源。
$1: 任務名稱(如果未提供,掃描現有任務供選擇)如果沒有提供 $1:
*/task.yaml 檔案使用 AskUserQuestion 詢問資料來源:
資料從哪裡來?
□ database - 資料庫查詢(PostgreSQL, MySQL, SQLite)
□ api - API 串接(REST, GraphQL)
□ web_scrape - 網頁爬取
□ llm_generated - LLM 生成合成資料
□ file_import - 匯入現有檔案(CSV, JSON, JSONL)
可選擇多個來源。
詢問:
生成配置:
- name: db_annotations
type: database
enabled: true
config:
driver: postgresql
host: ${DB_HOST}
port: 5432
database: ${DB_NAME}
username: ${DB_USER}
password: ${DB_PASSWORD}
query: |
SELECT text, label FROM annotations
WHERE status = 'approved'
output:
format: jsonl
path: data/raw/db_data.jsonl
詢問:
生成配置:
- name: api_data
type: api
enabled: true
config:
base_url: https://api.example.com
auth:
type: bearer
token: ${API_TOKEN}
requests:
- endpoint: /data
method: GET
params:
limit: 1000
詢問:
生成配置:
- name: web_data
type: web_scrape
enabled: true
config:
method: playwright
urls:
- https://example.com/page1
keywords:
- 金融
- 股票
rate_limit: 1
詢問:
生成配置:
- name: synthetic_data
type: llm_generated
enabled: true
config:
model: gpt-4o
temperature: 0.7
api_key: ${OPENAI_API_KEY}
generation:
prompt_template: |
生成 {count} 筆訓練資料...
variations:
- label: 正面
count: 100
validation:
require_review: true
詢問:
生成配置:
- name: imported_data
type: file_import
enabled: true
config:
source_path: /path/to/data.csv
format: csv
mapping:
text: content_column
label: sentiment_column
詢問是否需要合併多個來源:
確認分割比例:
將所有配置寫入 {task_name}/data_source.yaml
自動生成 scripts/01_regenerate_data.py,包含從各來源取得資料的邏輯。
列出需要設定的環境變數:
需要設定的環境變數:
- DB_HOST: 資料庫主機
- DB_USER: 資料庫使用者
- DB_PASSWORD: 資料庫密碼
- API_TOKEN: API 認證 Token
- OPENAI_API_KEY: OpenAI API Key
建議使用 .env 檔案管理,並加入 .gitignore
資料來源配置完成!
配置檔案: {task_name}/data_source.yaml
重新生成腳本: {task_name}/scripts/01_regenerate_data.py
下一步:
1. 設定環境變數
2. 執行 python scripts/01_regenerate_data.py 生成資料
3. 執行 python scripts/02_validate_data.py 驗證資料