מדריך גרוק CLI בעברית

תיעוד 21

סקירת Grok Build

Grok Build הוא סוכן קידוד חזק וניתן להרחבה. משתמשים בו דרך TUI אינטראקטיבי, במצב headless בסקריפטים או בבוטים, או דרך Agent Client Protocol (ACP) באפליקציות אחרות.

ה-TUI נותן חוויה עשירה במסך מלא, עם אינטראקציה בעכבר, לקידוד עם סוכנים.

#התקנה

Mac ו-Linux:

curl -fsSL https://x.ai/cli/install.sh | bash

PowerShell:

irm https://x.ai/cli/install.ps1 | iex

#התחלת סשן אינטראקטיבי

cd your-project
grok

בהפעלה הראשונה, Grok פותח דפדפן לאימות. בסביבות בלי דפדפן, משתמשים במפתח API:

export XAI_API_KEY="xai-..."
grok

הנחיות ראשונות שימושיות:

Explain this repo.
@src/main.rs Walk me through this file.

#הרצה במצב headless

grok -p "Explain this codebase"
grok -p "Explain the architecture" --output-format streaming-json

שימוש headless מתאים לסקריפטים, לאוטומציות, או לשילוב באפליקציות אחרות.

#מודלים מותאמים

Grok תומך בכל מודל מותאם. מוסיפים אותו לקובץ ההגדרות ברמת המשתמש, ~/.grok/config.toml (ב-Windows, %USERPROFILE%\.grok\config.toml):

[model.my-model]
model = "model-id"
base_url = "https://api.example.com/v1"
name = "Display Name"
env_key = "API_KEY"

[models]
default = "my-model"

אחרי עדכון ~/.grok/config.toml, משתמשים ב-grok inspect כדי לראות מה Grok גילה בתיקייה הנוכחית, כולל מקורות הגדרות, הוראות, skills, plugins, hooks ושרתי MCP, ואחר כך בוחרים את המודל במצב headless או ב-TUI:

grok inspect
grok -p "Hello" -m my-model

אפשר גם להחליף בתוך ה-TUI עם /model <name>.

#שימוש ב-Grok 4.7 ב-API

grok-4.7, המודל העדכני של SpaceXSI, זמין ישירות ב-API של xAI. אפשר לשלב אותו בלולאת סוכן משלכם, באינטגרציה ל-IDE, או בכלי קידוד.

import { xai } from '@ai-sdk/xai';
import { generateText } from 'ai';

const { text } = await generateText({
  model: xai.responses('grok-4.7'),
  prompt: 'Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}',
});

console.log(text);
from openai import OpenAI

client = OpenAI(
    api_key="<YOUR_XAI_API_KEY_HERE>",
    base_url="https://api.x.ai/v1",
)

response = client.responses.create(
    model="grok-4.7",
    input="Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}",
)

print(response.output_text)
curl https://api.x.ai/v1/responses \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.7",
    "input": "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"
  }'
import os
from xai_sdk import Client
from xai_sdk.chat import user

client = Client(api_key=os.getenv("XAI_API_KEY"))

chat = client.chat.create(model="grok-4.7")
chat.append(user("Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"))

print(chat.sample().content)

#תכונות

#המשך