Skip to content

ArmoredStone/grok-3-api-request-wrapper

Repository files navigation

grok-3-api-request-wrapper

Usage: ./grok-3-api-request-wrapper.sh [options]
Options:
  -c, --content      User content to send in the request (required)
  -s, --system       System content to include (optional)
  -a, --auth         Authorization token/API key (optional, may be supplied with .env file)
  -u, --url          API URL (defaults to https://api.x.ai/v1/chat/completions)
  -m, --model        Model to use (defaults to grok-3-latest)
  -h, --help         Show this help message
  -o, --output       Output file to save the response (optional)

Example:

./grok-3-api-request-wrapper.sh -c "What is the weather?" -s "You are a helpful assistant" -o "outputfile.md"

Output file example below the line:


AI Response

The tee command in Linux and Unix-like operating systems is used to read from standard input and write to both standard output and one or more files simultaneously. Essentially, it "tees off" the input stream, sending it in two directions: to the terminal (or another output stream) and to a file (or multiple files).

Syntax:

tee [options] [file(s)]

How it works:

  • tee takes input from a pipe or standard input.
  • It duplicates the input and sends it to:
    • The standard output (usually the terminal).
    • One or more specified files.

Common Use Cases:

  1. Save output to a file while displaying it on the terminal: When you run a command and want to see the output on the screen while also saving it to a file, tee is very handy.

    ls -l | tee output.txt

    In this example:

    • The output of ls -l is displayed on the terminal.
    • The same output is also written to output.txt.
  2. Write to multiple files: You can specify multiple files to write the output to.

    echo "Hello, World!" | tee file1.txt file2.txt

    Here, "Hello, World!" is written to both file1.txt and file2.txt, and also displayed on the terminal.

  3. Append to a file instead of overwriting: By default, tee overwrites the specified file(s). Use the -a (append) option to append the output to the file(s) instead.

    echo "New line" | tee -a output.txt

Common Options:

  • -a: Append to the specified file(s) instead of overwriting.
  • -i: Ignore interrupt signals (e.g., Ctrl+C).

Example with a Pipeline:

If you're processing data in a pipeline and want to save intermediate results, tee can help:

cat input.txt | grep "error" | tee errors.txt | wc -l

In this example:

  • cat input.txt reads the file.
  • grep "error" filters lines containing "error".
  • tee errors.txt saves the filtered output to errors.txt and also passes it to the next command.
  • wc -l counts the number of matching lines.

Summary:

The tee command is a powerful tool for duplicating output streams, allowing you to both display and save command output simultaneously. It’s especially useful for debugging, logging, or when you need to process data in a pipeline while keeping a copy of intermediate results.


Metadata

Property Value
Response ID aa99ba62-xxxx-xxxx-xxxx-912262a3907b
Model grok-3-beta
Created 2025-04-11 12:32:19
Finish Reason stop
System Fingerprint xxxx

Token Usage

Category Count
Prompt Tokens 12
Completion Tokens 563
Total Tokens 575

Detailed Token Usage

Category Count
Prompt: Text Tokens 12
Prompt: Audio Tokens 0
Prompt: Image Tokens 0
Prompt: Cached Tokens 0
Completion: Reasoning Tokens 0
Completion: Audio Tokens 0
Completion: Accepted Prediction Tokens 0
Completion: Rejected Prediction Tokens 0

{"id":"aa99ba62-xxxx-xxxx-xxxx-912262a3907b","object":"chat.completion","created":1744389139,"model":"grok-3-beta","choices":[{"index":0,"message":{"role":"assistant","content":"The tee command in Linux and Unix-like operating systems is used to read from standard input and write to both standard output and one or more files simultaneously. Essentially, it "tees off" the input stream, sending it in two directions: to the terminal (or another output stream) and to a file (or multiple files).\n\n### Syntax:\nbash\ntee [options] [file(s)]\n\n\n### How it works:\n- tee takes input from a pipe or standard input.\n- It duplicates the input and sends it to:\n - The standard output (usually the terminal).\n - One or more specified files.\n\n### Common Use Cases:\n1. Save output to a file while displaying it on the terminal:\n When you run a command and want to see the output on the screen while also saving it to a file, tee is very handy.\n bash\n ls -l | tee output.txt\n \n In this example:\n - The output of ls -l is displayed on the terminal.\n - The same output is also written to output.txt.\n\n2. Write to multiple files:\n You can specify multiple files to write the output to.\n bash\n echo \"Hello, World!\" | tee file1.txt file2.txt\n \n Here, "Hello, World!" is written to both file1.txt and file2.txt, and also displayed on the terminal.\n\n3. Append to a file instead of overwriting:\n By default, tee overwrites the specified file(s). Use the -a (append) option to append the output to the file(s) instead.\n bash\n echo \"New line\" | tee -a output.txt\n \n\n### Common Options:\n- -a: Append to the specified file(s) instead of overwriting.\n- -i: Ignore interrupt signals (e.g., Ctrl+C).\n\n### Example with a Pipeline:\nIf you're processing data in a pipeline and want to save intermediate results, tee can help:\nbash\ncat input.txt | grep \"error\" | tee errors.txt | wc -l\n\nIn this example:\n- cat input.txt reads the file.\n- grep \"error\" filters lines containing "error".\n- tee errors.txt saves the filtered output to errors.txt and also passes it to the next command.\n- wc -l counts the number of matching lines.\n\n### Summary:\nThe tee command is a powerful tool for duplicating output streams, allowing you to both display and save command output simultaneously. It’s especially useful for debugging, logging, or when you need to process data in a pipeline while keeping a copy of intermediate results.","refusal":null},"finish_reason":"stop"}],"usage":{"prompt_tokens":12,"completion_tokens":563,"total_tokens":575,"prompt_tokens_details":{"text_tokens":12,"audio_tokens":0,"image_tokens":0,"cached_tokens":0},"completion_tokens_details":{"reasoning_tokens":0,"audio_tokens":0,"accepted_prediction_tokens":0,"rejected_prediction_tokens":0}},"system_fingerprint":"xxxx"}


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published