uncloseai.com/public/languages/bash/index.html

166 lines
6.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bash - uncloseai.com API Examples</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/highlight.min.js"></script>
<style>
body { font-family: Arial, sans-serif; max-width: 900px; margin: 40px auto; padding: 0 20px; line-height: 1.6; }
h1 { color: #43a047; }
h2 { color: #333; margin-top: 2em; }
pre { background: #1e1e1e; padding: 15px; border-radius: 5px; overflow-x: auto; }
code { font-family: 'Courier New', monospace; }
.note { background: #fff3cd; padding: 15px; border-left: 4px solid #ffc107; margin: 20px 0; }
</style>
</head>
<body>
<h1>Bash - uncloseai.com API Examples</h1>
<p>This directory contains Bash examples for interacting with uncloseai.com's AI services using curl. Bash is perfect for quick scripts and command-line automation.</p>
<h2>Prerequisites</h2>
<ul>
<li>Bash shell</li>
<li>curl (for HTTP requests)</li>
<li>jq (optional, for JSON parsing)</li>
<li>ca-certificates (for HTTPS)</li>
</ul>
<h2>Files in This Directory</h2>
<ul>
<li><strong>examples.sh</strong> - Main script demonstrating all three APIs</li>
<li><strong>Dockerfile</strong> - Docker container for running examples</li>
<li><strong>index.html</strong> - This documentation file</li>
</ul>
<h2>Running with Docker</h2>
<pre><code class="bash"># Build the Docker image
docker build -t ai-unturf-bash languages/bash/
# Run the examples
docker run --rm ai-unturf-bash</code></pre>
<h2>Running Directly</h2>
<pre><code class="bash"># Make script executable
chmod +x examples.sh
# Run the examples
./examples.sh</code></pre>
<h2>Code Example: Hermes AI Chat</h2>
<p>Using curl to call the Hermes AI endpoint for general purpose conversation:</p>
<pre><code class="bash">#!/bin/bash
# Hermes AI Chat - Non-Streaming
hermes_response=$(curl -s -X POST "https://hermes.ai.unturf.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-key" \
-d '{
"model": "adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic",
"messages": [{"role": "user", "content": "Give a Python Fizzbuzz solution in one line of code?"}],
"temperature": 0.5,
"max_tokens": 150
}')
# Parse response with jq (optional)
echo "$hermes_response" | jq -r '.choices[0].message.content'</code></pre>
<h2>Code Example: Qwen 3 Coder</h2>
<p>Qwen is specialized for coding tasks:</p>
<pre><code class="bash">#!/bin/bash
# Qwen 3 Coder - Specialized for Code
qwen_response=$(curl -s -X POST "https://qwen.ai.unturf.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-key" \
-d '{
"model": "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Q4_K_M",
"messages": [{"role": "user", "content": "Write a bash function to check if a port is open"}],
"temperature": 0.5,
"max_tokens": 200
}')
echo "$qwen_response" | jq -r '.choices[0].message.content'</code></pre>
<h2>Code Example: Text-to-Speech</h2>
<p>Generate speech from text and save to a file:</p>
<pre><code class="bash">#!/bin/bash
# Text-to-Speech - Save to file
curl -s -X POST "https://speech.ai.unturf.com/v1/audio/speech" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOLO" \
-d '{
"model": "tts-1",
"voice": "alloy",
"input": "Hello from Bash! Today is a wonderful day to grow something people love!"
}' \
--output speech.mp3
# Check if file was created
if [ -f speech.mp3 ]; then
echo "[OK] Speech file created successfully"
fi</code></pre>
<h2>Understanding the Code</h2>
<h3>1. Using curl for HTTP Requests</h3>
<p>The curl command makes HTTP POST requests to the API endpoints:</p>
<ul>
<li><code>-s</code> - Silent mode (no progress bar)</li>
<li><code>-X POST</code> - Use POST method</li>
<li><code>-H</code> - Add HTTP headers (Content-Type, Authorization)</li>
<li><code>-d</code> - Send JSON data in request body</li>
<li><code>--output</code> - Save response to file (for TTS)</li>
</ul>
<h3>2. Command Substitution</h3>
<p>The <code>$(command)</code> syntax captures command output into a variable:</p>
<pre><code class="bash">response=$(curl -s "https://api.example.com")
echo "$response"</code></pre>
<h3>3. JSON Parsing with jq</h3>
<p>The jq tool extracts data from JSON responses:</p>
<pre><code class="bash">echo "$response" | jq -r '.choices[0].message.content'
# -r flag removes quotes from string output</code></pre>
<h2>Common Issues</h2>
<div class="note">
<strong>Issue:</strong> "jq: command not found"<br>
<strong>Solution:</strong> Install jq: <code>apk add jq</code> (Alpine) or <code>apt-get install jq</code> (Debian/Ubuntu)
</div>
<div class="note">
<strong>Issue:</strong> "curl: (60) SSL certificate problem"<br>
<strong>Solution:</strong> Install ca-certificates: <code>apk add ca-certificates</code>
</div>
<div class="note">
<strong>Issue:</strong> Empty or error response<br>
<strong>Solution:</strong> Remove <code>-s</code> flag from curl to see error messages
</div>
<h2>API Endpoints</h2>
<ul>
<li><strong>Hermes AI:</strong> https://hermes.ai.unturf.com/v1/chat/completions</li>
<li><strong>Qwen Coder:</strong> https://qwen.ai.unturf.com/v1/chat/completions</li>
<li><strong>TTS Speech:</strong> https://speech.ai.unturf.com/v1/audio/speech</li>
</ul>
<h2>Next Steps</h2>
<p>Try modifying the examples:</p>
<ul>
<li>Change the user message to ask different questions</li>
<li>Adjust temperature (0.0-2.0) to control randomness</li>
<li>Increase max_tokens for longer responses</li>
<li>Try different TTS voices: alloy, echo, fable, onyx, nova, shimmer</li>
</ul>
<p><a href="../../index.html">← Back to Main Page</a></p>
<script>hljs.highlightAll();</script>
</body>
</html>