ข้ามไปที่เนื้อหา

เริ่มต้นใช้งานอย่างรวดเร็ว

การรันคำสั่ง jarvis

ตัวอย่าง jarvis ... ทุกตัวอย่างด้านล่างนี้ สมมติว่าคุณเปิดใช้งาน venv ของโปรเจกต์แล้ว (source .venv/bin/activate) หรือใส่ uv run นำหน้าทุกคำสั่ง หากรัน jarvis init --preset ... เปล่าๆ จาก clone ใหม่โดยไม่ทำสองอย่างนี้ก่อน จะล้มเหลวด้วย command not found

สิ่งที่คุณสร้างได้

OpenJarvis คือเฟรมเวิร์กผู้ช่วย AI แบบโมดูลาร์ (modular AI assistant framework) นี่คือตัวอย่างสิ่งที่นักพัฒนาสร้างด้วยมัน:

jarvis ask "Explain quantum entanglement" -m qwen3.5:4b   # use qwen3.5:9b or larger on GPU
jarvis ask --agent orchestrator --tools calculator,web_search "What is the GDP of France in USD?"
jarvis memory index ./docs/
jarvis ask "How do I configure the engine?"

ต้องมี Rust extension

jarvis memory index และ jarvis memory search จะ import openjarvis_rust หากคุณข้ามขั้นตอน uv run maturin develop -m rust/crates/openjarvis-python/Cargo.toml ใน การติดตั้ง คำสั่งเหล่านี้จะล้มเหลวด้วย ModuleNotFoundError: No module named 'openjarvis_rust' ให้ build extension นี้ เพียงครั้งเดียว แล้ว preset ใดๆ (รวมถึง deep-research) ก็จะทำงานได้

from openjarvis import Jarvis
with Jarvis() as j:
    print(j.ask("Hello!"))
jarvis serve --port 8000
# Now use any OpenAI-compatible client
cp configs/openjarvis/examples/morning-digest-mac.toml ~/.openjarvis/config.toml
jarvis connect gdrive       # one OAuth flow for Gmail, Calendar, Tasks
CARTESIA_API_KEY="..." jarvis digest --fresh
# Plays a spoken daily briefing with your email, calendar, health, and news
jarvis init --preset deep-research
jarvis memory index ~/Documents/papers/
jarvis ask "Summarize all documents about transformer architectures"
# Multi-hop search across your indexed docs with citations
jarvis init --preset code-assistant
jarvis ask "Write a Python script that parses CSV files"
# Orchestrator agent with code execution, file I/O, and shell access
jarvis init --preset scheduled-monitor
jarvis memory index ~/Documents/
jarvis scheduler start
jarvis scheduler create \
  --prompt "Check for new emails about Project X" \
  --schedule "0 9 * * 1-5" --agent operative
# Persistent agent that runs on a cron schedule

ดูรูปแบบที่ copy-paste ได้ครบทุกแบบได้ที่ Code Snippets

Starter Configs

คัดลอกไฟล์ใดไฟล์หนึ่งด้านล่างไปไว้ที่ ~/.openjarvis/config.toml เพื่อให้ได้การตั้งค่าที่พร้อมใช้งานทันที:

Config สำหรับ ทำอะไร
chat-simple.toml เครื่องไหนก็ได้ แชทแบบเบา ไม่มี tools -- ตั้งค่าง่ายที่สุด
code-assistant.toml เครื่องไหนก็ได้ เอเจนต์ orchestrator พร้อมรันโค้ด, file I/O, shell
deep-research.toml เครื่องไหนก็ได้ การค้นหาแบบหลายขั้น (multi-hop) ข้ามเอกสารที่ index ไว้ พร้อมอ้างอิงแหล่งที่มา
scheduled-monitor.toml เครื่องไหนก็ได้ เอเจนต์ operative ที่รันต่อเนื่องตามตารางแบบ cron
morning-digest-mac.toml Mac (Apple Silicon) บรีฟประจำวันแบบเสียงพูด จากอีเมล ปฏิทิน สุขภาพ และข่าว
morning-digest-linux.toml Linux / เซิร์ฟเวอร์ GPU เหมือนกัน แต่รองรับ vLLM
morning-digest-minimal.toml เครื่องไหนก็ได้ มีแค่ Gmail + Calendar

หรือสร้าง config ที่รวม digest มาด้วย:

jarvis init --digest

คู่มือนี้จะพาไปดูเวิร์กโฟลว์หลักของ OpenJarvis ได้แก่ แอปในเบราว์เซอร์, CLI, Python SDK, เอเจนต์ที่ใช้ tools, memory, การวัดประสิทธิภาพ (benchmark) และเซิร์ฟเวอร์ API

สิ่งที่ต้องมีก่อน

ตรวจสอบว่าคุณติดตั้ง OpenJarvisแล้ว และมี inference backend อย่างน้อยหนึ่งตัวกำลังรันอยู่ (เช่น ollama serve)

แอปในเบราว์เซอร์

วิธีที่เร็วที่สุดในการทดลองใช้ OpenJarvis คือ UI แชทแบบเต็มรูปแบบที่รันอยู่ในเบราว์เซอร์:

git clone https://github.com/open-jarvis/OpenJarvis.git
cd OpenJarvis
./scripts/quickstart.sh

คำสั่งนี้จะเปิดเซิร์ฟเวอร์ API ฝั่ง backend และ frontend แบบ React ที่ http://localhost:5173 คุณจะได้อินเทอร์เฟซแบบ ChatGPT ที่มีการตอบกลับแบบสตรีมมิง (streaming), การใช้ tool, การมอนิเตอร์พลังงาน และแดชบอร์ดเทเลเมทรี (telemetry) — ทั้งหมดรันอยู่บนฮาร์ดแวร์ของคุณเองในเครื่อง

การค้นหาเว็บใช้งานได้ผ่าน DuckDuckGo fallback ที่มีมาในตัว หากต้องการใช้ Tavily ให้เพิ่ม TAVILY_API_KEY ที่ Settings → Tools → Web Search (การตั้งค่า → เครื่องมือ → ค้นหาเว็บ) หลังจากแอปเริ่มทำงานแล้ว หรือ export ค่านี้ไว้ก่อนเริ่ม quickstart:

export TAVILY_API_KEY="tvly-..."
./scripts/quickstart.sh

สคริปต์นี้จะไม่ source ไฟล์ .env ให้อัตโนมัติ ให้รัน source .env ก่อน หากคุณเก็บ key ไว้ที่นั่น หยุดเซิร์ฟเวอร์ OpenJarvis ที่รันอยู่เดิม ก่อนรันใหม่ เพื่อให้รับ environment ที่อัปเดตแล้ว

หากต้องการหยุดทุกบริการ ให้กด Ctrl+C ในเทอร์มินัล

ตัวแปร Environment

ตั้งค่า OPENJARVIS_MODEL เพื่อเปลี่ยนโมเดลเริ่มต้น: OPENJARVIS_MODEL=deepseek-r1:14b ./scripts/quickstart.sh

ตั้งค่าคอนฟิกเริ่มต้น

เริ่มต้นด้วยการตรวจจับฮาร์ดแวร์และสร้างไฟล์คอนฟิก:

jarvis init

คำสั่งนี้จะรันการตรวจจับฮาร์ดแวร์อัตโนมัติ (ยี่ห้อ GPU, VRAM, CPU, RAM) และเขียนไฟล์คอนฟิกไปที่ ~/.openjarvis/config.toml พร้อมค่าเริ่มต้นที่เหมาะสมกับระบบของคุณ รวมถึงเลือก inference engine ที่แนะนำให้ด้วย

Detecting hardware...
  Platform : linux
  CPU      : AMD EPYC 7763 (128 cores)
  RAM      : 512.0 GB
  GPU      : NVIDIA A100 (80.0 GB VRAM, x8)

Config written successfully.

หากต้องการเขียนทับ config ที่มีอยู่แล้ว:

jarvis init --force

ดู Configuration สำหรับ config reference แบบเต็ม

คำถามแรกของคุณ

ผ่าน CLI

วิธีที่ง่ายที่สุดในการโต้ตอบกับ OpenJarvis คือคำสั่ง ask:

jarvis ask "What is the capital of France?"

OpenJarvis จะตรวจจับ engine ที่กำลังรันอยู่โดยอัตโนมัติ เลือกโมเดลตามนโยบายจัดเส้นทาง (router policy) ที่ตั้งค่าไว้ แล้วส่งคืนคำตอบ

ตัวเลือกของ CLI

ตัวเลือก คำอธิบาย ตัวอย่าง
-m, --model เปลี่ยนโมเดลที่เลือกไว้ jarvis ask -m qwen3:8b "Hello"
-e, --engine บังคับใช้ engine ที่ระบุ jarvis ask -e ollama "Hello"
-t, --temperature อุณหภูมิของ sampling (ค่าเริ่มต้น: 0.7) jarvis ask -t 0.2 "Hello"
--max-tokens จำนวน token สูงสุดที่จะสร้าง (ค่าเริ่มต้น: 1024) jarvis ask --max-tokens 2048 "Hello"
--json แสดงผลลัพธ์เป็น JSON ดิบ jarvis ask --json "Hello"
--no-stream ปิดการสตรีมมิง jarvis ask --no-stream "Hello"
--no-context ปิดการแทรกบริบทจาก memory jarvis ask --no-context "Hello"
-a, --agent ใช้เอเจนต์ jarvis ask -a orchestrator "Hello"
--tools ระบุ tools คั่นด้วยคอมมา jarvis ask --tools calculator,think "2+2"
--router นโยบาย router สำหรับเลือกโมเดล jarvis ask --router heuristic "Hello"

ผ่าน Python SDK

คลาส Jarvis มี interface ระดับสูงสำหรับ Python:

from openjarvis import Jarvis

j = Jarvis()
response = j.ask("What is the capital of France?")
print(response)
j.close()

สำหรับผลลัพธ์แบบละเอียด รวมถึงการใช้ token และข้อมูลโมเดล:

result = j.ask_full("What is the capital of France?")
print(result["content"])  # The response text
print(result["model"])    # Model that handled the query
print(result["engine"])   # Engine that ran inference
print(result["usage"])    # Token usage statistics

ตัวเลือกของ SDK Constructor

# Use default config (auto-detected hardware, ~/.openjarvis/config.toml)
j = Jarvis()

# Override the model
j = Jarvis(model="qwen3:8b")

# Override the engine
j = Jarvis(engine_key="ollama")

# Use a custom config file
j = Jarvis(config_path="/path/to/config.toml")

ต้องเรียก close() เสมอ

instance ของ Jarvis เก็บ reference ไปยัง telemetry store และ memory backend ไว้ เรียก j.close() เมื่อใช้งานเสร็จเพื่อคืนทรัพยากร

ใช้เอเจนต์ร่วมกับ Tools

เอเจนต์เพิ่มความสามารถในการให้เหตุผลแบบหลายรอบ (multi-turn) และการเรียกใช้ tool เอเจนต์ orchestrator จะรันลูปการเรียกใช้เครื่องมือ (tool-calling loop) โดยเรียก tools ตามความจำเป็นเพื่อตอบคำถาม

เอเจนต์ที่มีให้ใช้งาน

เอเจนต์ คำอธิบาย
simple รอบเดียว (single-turn) ไม่มี tools ส่งคำถามตรงไปยังโมเดล
orchestrator ลูปการเรียกใช้เครื่องมือแบบหลายรอบ เรียก tools ซ้ำจนกว่าจะได้คำตอบ
custom Template สำหรับ logic ของเอเจนต์ที่ผู้ใช้กำหนดเอง
operative เอเจนต์เชิงงาน (task-oriented) ที่มีการวางแผนและดำเนินการอย่างเป็นโครงสร้าง

Tools มาตรฐานที่มีให้ใช้งาน

Tool คำอธิบาย
calculator การประเมินนิพจน์ทางคณิตศาสตร์อย่างปลอดภัย (ast-based)
think พื้นที่ร่างความคิด (scratchpad) สำหรับ chain-of-thought
retrieval ค้นหา memory store เพื่อหาบริบทที่เกี่ยวข้อง
llm ส่งคำถามย่อยไปยังโมเดลอื่น
file_read อ่านไฟล์พร้อมตรวจสอบ path
web_search ค้นหาเว็บผ่าน Tavily API (ต้องมี extra tools-search)

ตัวอย่างผ่าน CLI

jarvis ask --agent orchestrator --tools calculator,think "What is 137 * 42?"

ตัวอย่างผ่าน SDK

from openjarvis import Jarvis

j = Jarvis()
result = j.ask_full(
    "What is the square root of 144?",
    agent="orchestrator",
    tools=["calculator", "think"],
)
print(result["content"])
print(result["tool_results"])  # List of tool invocations and results
print(result["turns"])         # Number of agent turns
j.close()

Memory: การทำดัชนีและการค้นหา

ระบบ memory ช่วยให้คุณทำดัชนี (index) เอกสาร แล้วแทรกบริบทที่เกี่ยวข้องเข้าไปในคำถามโดยอัตโนมัติ

ทำดัชนีเอกสาร

ทำดัชนีไฟล์หรือไดเรกทอรี OpenJarvis จะแบ่งเนื้อหาเป็นชิ้นๆ (chunk) แล้วเก็บไว้ใน memory backend ที่ตั้งค่าไว้ (ค่าเริ่มต้นคือ SQLite/FTS5)

# Index a directory
jarvis memory index ./docs/

# Index a single file with custom chunk size
jarvis memory index ./paper.txt --chunk-size 256 --chunk-overlap 32
from openjarvis import Jarvis

j = Jarvis()
result = j.memory.index("./docs/", chunk_size=512, chunk_overlap=64)
print(f"Indexed {result['chunks']} chunks")
j.close()

ค้นหา Memory

Query memory store เพื่อหา chunk ที่เกี่ยวข้อง:

jarvis memory search "configuration options"
jarvis memory search -k 10 "how to deploy"
results = j.memory.search("configuration options", top_k=5)
for r in results:
    print(f"[{r['score']:.4f}] {r['source']}: {r['content'][:100]}")

ตรวจสอบสถิติของ Memory

jarvis memory stats
stats = j.memory.stats()
print(f"Backend: {stats['backend']}, Documents: {stats.get('count', 'N/A')}")

การแทรกบริบทอัตโนมัติ

เมื่อคุณ index เอกสารไว้แล้ว OpenJarvis จะแทรกบริบทที่เกี่ยวข้องเข้าไปในคำถามของคุณโดยอัตโนมัติ ระบบ memory จะค้นหา chunk ที่ตรงกับคำถามของคุณ แล้วนำมาต่อไว้เป็นบริบทของระบบ (system context) ก่อนส่งไปยังโมเดล

หากต้องการปิดพฤติกรรมนี้:

jarvis ask --no-context "Hello"
response = j.ask("Hello", context=False)

การแทรกบริบทควบคุมได้ผ่าน agent.context_from_memory ใน config.toml ส่วนพารามิเตอร์การดึงข้อมูล (retrieval) (context_top_k, context_min_score, context_max_tokens) อยู่ใต้ [tools.storage] ดู Configuration สำหรับรายละเอียด

การจัดการโมเดล

รายการโมเดลที่มีให้ใช้งาน

ดูโมเดลทั้งหมดที่มีให้ใช้งานบน engine ที่กำลังรันอยู่:

jarvis model list

คำสั่งนี้จะแสดงตารางของแต่ละโมเดล พร้อม engine, จำนวนพารามิเตอร์, ความยาวบริบท (context length) และความต้องการ VRAM

ดูรายละเอียดของโมเดล

jarvis model info qwen3:8b

ดึงโมเดล (Ollama)

jarvis model pull qwen3:8b

แสดงรายการโมเดลผ่าน SDK

from openjarvis import Jarvis

j = Jarvis()
models = j.list_models()
engines = j.list_engines()
print(f"Models: {models}")
print(f"Engines: {engines}")
j.close()

การรัน Benchmarks

เฟรมเวิร์กการวัดประสิทธิภาพ (benchmark) วัด latency และ throughput ของการอนุมาน (inference) เทียบกับ engine ของคุณ

jarvis bench run
jarvis bench run -b latency
jarvis bench run -b throughput
# 20 samples, JSON output
jarvis bench run -n 20 --json

# Specific model and engine, write to file
jarvis bench run -m qwen3:8b -e ollama -o results.jsonl

ตัวอย่างผลลัพธ์:

Running 2 benchmark(s) on ollama/qwen3:8b (10 samples)...

latency (10 samples, 0 errors)
  mean_ms: 245.3200
  p50_ms: 238.1000
  p95_ms: 312.4500
  min_ms: 201.2000
  max_ms: 345.6000

throughput (10 samples, 0 errors)
  tokens_per_second: 42.1500
  total_tokens: 4215
  total_seconds: 100.0000

เริ่มเซิร์ฟเวอร์ API

OpenJarvis มีเซิร์ฟเวอร์ API แบบเข้ากันได้กับ OpenAI สำหรับเชื่อมต่อกับเครื่องมือและ frontend ที่มีอยู่แล้ว

ต้องมี extra server

uv sync --extra server

เริ่มเซิร์ฟเวอร์

jarvis serve --port 8000

พร้อมตัวเลือกกำหนดเอง:

jarvis serve --host 0.0.0.0 --port 8000 --engine ollama --model qwen3:8b --agent orchestrator

Endpoints ของ API

Endpoint Method คำอธิบาย
/v1/chat/completions POST Chat completions (แบบสตรีมและไม่สตรีม)
/v1/models GET รายการโมเดลที่มีให้ใช้งาน
/health GET ตรวจสอบสถานะ (health check)

ใช้งานร่วมกับ Client ที่เข้ากันได้กับ OpenAI

เมื่อเซิร์ฟเวอร์กำลังรันอยู่ ให้ชี้ client ที่เข้ากันได้กับ OpenAI ไปที่เซิร์ฟเวอร์:

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-needed")
response = client.chat.completions.create(
    model="qwen3:8b",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

หรือใช้ curl:

curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "qwen3:8b",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

Telemetry

OpenJarvis บันทึกเทเลเมทรี (telemetry) สำหรับการเรียก inference ทุกครั้ง (เวลา, token, ต้นทุน) ดูสถิติที่รวบรวมไว้:

jarvis telemetry stats

Export ข้อมูลเทเลเมทรี:

jarvis telemetry export --format json
jarvis telemetry export --format csv -o telemetry.csv

ล้างข้อมูลเทเลเมทรีทั้งหมด:

jarvis telemetry clear --yes

ตัวอย่างการใช้งานแบบครบวงจร

นี่คือตัวอย่าง session แบบ end-to-end ที่รวมหลายฟีเจอร์เข้าด้วยกัน:

from openjarvis import Jarvis

# Initialize with defaults (auto-detect hardware and engine)
j = Jarvis()

# 1. Index some documentation
index_result = j.memory.index("./docs/", chunk_size=512)
print(f"Indexed {index_result['chunks']} chunks from {index_result['path']}")

# 2. Search memory
results = j.memory.search("how to configure engines")
for r in results:
    print(f"  [{r['score']:.3f}] {r['source']}")

# 3. Ask a question (memory context is injected automatically)
answer = j.ask("How do I configure the Ollama engine host?")
print(f"\nAnswer: {answer}")

# 4. Use an agent with tools
calc_result = j.ask_full(
    "Calculate the compound interest on $10,000 at 5% for 10 years",
    agent="orchestrator",
    tools=["calculator", "think"],
)
print(f"\nCalculation: {calc_result['content']}")
print(f"Tools used: {[t['tool_name'] for t in calc_result['tool_results']]}")
print(f"Agent turns: {calc_result['turns']}")

# 5. List available models
models = j.list_models()
print(f"\nAvailable models: {models}")

# 6. Clean up
j.close()

ขั้นตอนถัดไป

  • Configuration — ปรับแต่ง engine host, การจัดเส้นทางโมเดล (model routing), การตั้งค่า memory และอื่นๆ
  • CLI Reference — เอกสารอ้างอิงฉบับเต็มสำหรับคำสั่งและตัวเลือกทั้งหมดของ CLI
  • Python SDK — เอกสาร SDK แบบละเอียด
  • Architecture Overview — ทำความเข้าใจการออกแบบแบบห้าองค์ประกอบหลัก (five-primitive design)