Skip to content

Latest commit

 

History

History
233 lines (155 loc) · 6.8 KB

File metadata and controls

233 lines (155 loc) · 6.8 KB

datax - AI-powered pipe filter for your terminal

将自然语言转化为管道命令,让 AI 帮你处理数据流。
忘掉 grepjqawk 的参数,只描述你想要的结果。

理念

传统的命令行数据处理需要记忆大量工具和参数:

cat xxx.txt | grep -oE "pattern" | awk '{print $2}'

datax 将这些步骤浓缩为一个自然语言指令:

cat xxx.txt | datax 从每行中提取第二个字段
netstat -ano | datax 帮我提取外联公网的 IP 和端口

后端接入 AI 模型(云端或本地),理解你的意图,并直接输出处理后的数据。你永远不需要记住 jq 的复杂语法,也不用复制粘贴到另一个对话窗口。

快速开始(概念)

# 安装(待实现)
pip install datax

# 设置 API key(默认使用 OpenAI)
export OPENAI_API_KEY="sk-..."

# 开始使用
ps aux | datax 列出占用内存最高的 5 个进程名字和内存百分比

cat logs.json | datax 过滤出状态码为 500 的请求,只显示时间和路径

使用形式

command | datax "<你的自然语言需求>"
  • datax 从 stdin 读取数据,将原始内容和你的需求一同发送给 AI。
  • AI 只返回处理后的纯数据,不添加解释或 Markdown 格式。
  • 支持 --json--csv 等输出格式约束(规划中)。

进阶功能(路线图)

  • datax --explain:将自然语言需求翻译成等价传统命令,帮助学习:

    datax --explain "提取外联公网 IP" 
    # 输出:grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' ...
  • datax --save 别名:缓存常用意图为快捷指令:

    datax --save ip "提取所有 IPv4 地址"
    cat config.txt | datax @ip
  • datax --local:使用 Ollama 等本地模型,保护敏感数据不上传。

  • datax --stream:对长输出流式处理,边接收边输出(降低延迟)。

技术考虑

延迟优化

  • 优先使用本地缓存模板匹配简单意图(如“提取 IP”直接转正则,无需调用 LLM)。
  • 支持对接高速本地模型(Ollama、llama.cpp)。
  • 流式模式,在首 token 生成后即开始输出。

输出健壮性

  • System prompt 严格约束:“你是命令行过滤器,只输出处理后的数据,不添加额外说明、前缀或格式化字符。”
  • 错误信息通过 stderr 输出,退出码反应真实状态,避免污染下游管道。

隐私保护

  • 默认支持“隐私提示”:当检测到可能敏感数据(如 IP、密钥模式)时,建议用户使用 --local--private
  • 所有可配置的远程模型均需用户自行提供 API key。

原型演示(伪代码)

import sys
import openai

prompt = f"""
你是一个命令行数据处理工具。用户需求:{sys.argv[1]}
原始数据:
{sys.stdin.read()}

请直接输出处理后的结果,不要增加任何额外文字。
"""

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": prompt}],
    temperature=0
)
print(response.choices[0].message.content)

贡献

这个项目目前处于概念阶段,欢迎提出想法、讨论技术方案或直接贡献代码。 你可以在 Issues 中分享你希望 datax 解决的日常痛点。


让终端理解人话,把时间留给真正重要的事。


datax - AI-powered pipe filter for your terminal

Turn natural language into a pipe command. Let AI handle the data stream. Forget the flags for grep, jq, awk — just describe what you want.

Concept

Traditional CLI data processing forces you to memorize countless tools and parameters:

cat xxx.txt | grep -oE "pattern" | awk '{print $2}'

datax condenses these steps into a single natural language instruction:

cat xxx.txt | datax extract the second field from each line
netstat -ano | datax show me external public IPs and ports

It pipes your data to an AI backend (cloud or local) that interprets your intent and outputs the processed result. Never memorize complex jq syntax again, and never copy-paste into a separate chat window.

Quick Start (Concept)

# Installation (to be implemented)
pip install datax

# Set API key (default: OpenAI)
export OPENAI_API_KEY="sk-..."

# Usage
ps aux | datax list the top 5 memory-hungry processes with their names and memory %

cat logs.json | datax filter requests with status 500, show only timestamp and path

Usage Form

command | datax "<your natural language request>"
  • datax reads from stdin and sends both the raw content and your request to the AI.
  • The AI returns only the processed data — no explanations, no markdown.
  • --json, --csv and other output format constraints are planned.

Advanced Features (Roadmap)

  • datax --explain : translates your request to an equivalent traditional command, helping you learn:

    datax --explain "extract external public IPs"
    # Output: grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' ...
  • datax --save alias : cache frequent intents as shortcuts:

    datax --save ip "extract all IPv4 addresses"
    cat config.txt | datax @ip
  • datax --local : use local models (e.g. Ollama) to keep sensitive data on your machine.

  • datax --stream : stream processing for long outputs, reducing perceived latency.

Technical Considerations

Latency Optimization

  • Simple intents (like "extract IP") are matched against a local template cache and translated into regex without calling an LLM.
  • Support for fast local models (Ollama, llama.cpp).
  • Streaming mode: output begins as soon as the first token is generated.

Output Robustness

  • Strict system prompt: “You are a command-line filter. Output only processed data. No explanations, prefixes, or formatting.”
  • Errors go to stderr with meaningful exit codes, never polluting the downstream pipe.

Privacy

  • Built-in privacy hint: if data patterns look sensitive (IPs, key-like strings), suggest using --local or --private.
  • All configurable remote models require the user to supply their own API key.

Prototype (Pseudocode)

import sys
import openai

prompt = f"""
You are a command-line data processing tool. User request: {sys.argv[1]}
Raw data:
{sys.stdin.read()}

Output only the processed result. Do not add any extra text.
"""

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": prompt}],
    temperature=0
)
print(response.choices[0].message.content)

Contributing

This project is currently at the concept stage. Ideas, technical discussions, and code contributions are all welcome. Share the daily pain points you wish datax could solve in the Issues.


Make your terminal understand human language — so you can focus on what truly matters.