reorganize Python with openai-client and requests subdirs, pin to python:3.13-alpine, add Docker image consistency standards
This commit is contained in:
parent
39502bcac3
commit
4941cce333
8 changed files with 150 additions and 14 deletions
22
CLAUDE.md
22
CLAUDE.md
|
|
@ -197,6 +197,28 @@ openai==2.3.0
|
|||
❌ openai~=1.0 (lazy, not latest)
|
||||
```
|
||||
|
||||
## Docker Base Image Standards
|
||||
**CRITICAL: Use consistent, pinned base images within each language**
|
||||
|
||||
1. **All examples for a language MUST use the same base image**
|
||||
- ✅ All Python examples use `python:3.13-alpine`
|
||||
- ✅ All Node.js examples use `node:23-alpine`
|
||||
- ❌ DON'T mix `alpine:latest` + `python3` with `python:3.13-alpine`
|
||||
|
||||
2. **Pin to specific versions, document check date**
|
||||
```dockerfile
|
||||
# Pin to specific Python version (checked 2025-10-12: python:3.13-alpine is latest stable)
|
||||
FROM python:3.13-alpine
|
||||
```
|
||||
|
||||
3. **Prefer official language images over generic + manual install**
|
||||
- ✅ `FROM python:3.13-alpine` (official, clean)
|
||||
- ❌ `FROM alpine:latest` + `RUN apk add python3` (messy, inconsistent)
|
||||
|
||||
4. **Use alpine variants for smaller images**
|
||||
- `python:3.13-alpine` not `python:3.13`
|
||||
- `node:23-alpine` not `node:23`
|
||||
|
||||
## Makefile Commands for Language Examples
|
||||
- `make languages-list` - List all language directories
|
||||
- `make languages-build-{lang}` - Build Docker image for specific language
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
FROM alpine:latest
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt /app/requirements.txt
|
||||
COPY examples.py /app/examples.py
|
||||
|
||||
RUN chmod +x /app/examples.py
|
||||
|
||||
RUN apk --no-cache add python3 py3-pip ca-certificates \
|
||||
&& pip3 install --break-system-packages -r /app/requirements.txt \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
CMD ["python3", "/app/examples.py"]
|
||||
13
languages/python/openai-client/Dockerfile
Normal file
13
languages/python/openai-client/Dockerfile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Pin to specific Python version (checked 2025-10-12: python:3.13-alpine is latest stable)
|
||||
FROM python:3.13-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt /app/requirements.txt
|
||||
COPY examples.py /app/examples.py
|
||||
|
||||
RUN chmod +x /app/examples.py
|
||||
|
||||
RUN pip3 install --no-cache-dir -r /app/requirements.txt
|
||||
|
||||
CMD ["python3", "/app/examples.py"]
|
||||
13
languages/python/requests/Dockerfile
Normal file
13
languages/python/requests/Dockerfile
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Pin to specific Python version (checked 2025-10-12: python:3.13-alpine is latest stable)
|
||||
FROM python:3.13-alpine
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt /app/requirements.txt
|
||||
COPY examples.py /app/examples.py
|
||||
|
||||
RUN chmod +x /app/examples.py
|
||||
|
||||
RUN pip3 install --no-cache-dir -r /app/requirements.txt
|
||||
|
||||
CMD ["python3", "/app/examples.py"]
|
||||
100
languages/python/requests/examples.py
Normal file
100
languages/python/requests/examples.py
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env python3
|
||||
"""
|
||||
uncloseai.com API Examples in Python using requests library
|
||||
Demonstrates direct HTTP calls to Hermes AI, Qwen Coder, and TTS endpoints
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
print("=== uncloseai.com Python (requests) Examples ===")
|
||||
print()
|
||||
|
||||
# Example 1: Hermes AI Chat using requests
|
||||
print("1. Hermes AI - General Purpose Chat (using requests)")
|
||||
print(" Asking: 'Give a Python Fizzbuzz solution in one line of code?'")
|
||||
print()
|
||||
|
||||
hermes_response = requests.post(
|
||||
"https://hermes.ai.unturf.com/v1/chat/completions",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer dummy-key"
|
||||
},
|
||||
json={
|
||||
"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
|
||||
}
|
||||
)
|
||||
|
||||
if hermes_response.status_code == 200:
|
||||
print("Response:")
|
||||
print(hermes_response.json()["choices"][0]["message"]["content"])
|
||||
else:
|
||||
print(f"Error: {hermes_response.status_code} - {hermes_response.text}")
|
||||
|
||||
print()
|
||||
print("---")
|
||||
print()
|
||||
|
||||
# Example 2: Qwen 3 Coder using requests
|
||||
print("2. Qwen 3 Coder - Specialized for Code (using requests)")
|
||||
print(" Asking: 'Write a Python function to validate an email address'")
|
||||
print()
|
||||
|
||||
qwen_response = requests.post(
|
||||
"https://qwen.ai.unturf.com/v1/chat/completions",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer dummy-key"
|
||||
},
|
||||
json={
|
||||
"model": "hf.co/unsloth/Qwen3-Coder-30B-A3B-Instruct-GGUF:Q4_K_M",
|
||||
"messages": [{"role": "user", "content": "Write a Python function to validate an email address"}],
|
||||
"temperature": 0.5,
|
||||
"max_tokens": 200
|
||||
}
|
||||
)
|
||||
|
||||
if qwen_response.status_code == 200:
|
||||
print("Response:")
|
||||
print(qwen_response.json()["choices"][0]["message"]["content"])
|
||||
else:
|
||||
print(f"Error: {qwen_response.status_code} - {qwen_response.text}")
|
||||
|
||||
print()
|
||||
print("---")
|
||||
print()
|
||||
|
||||
# Example 3: Text-to-Speech using requests
|
||||
print("3. Text-to-Speech Generation (using requests)")
|
||||
print(" Converting text to speech and saving to speech.mp3")
|
||||
print()
|
||||
|
||||
tts_response = requests.post(
|
||||
"https://speech.ai.unturf.com/v1/audio/speech",
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer YOLO"
|
||||
},
|
||||
json={
|
||||
"model": "tts-1",
|
||||
"voice": "alloy",
|
||||
"input": "Hello from Python using requests! Today is a wonderful day to build something people love!"
|
||||
}
|
||||
)
|
||||
|
||||
if tts_response.status_code == 200:
|
||||
with open("speech.mp3", "wb") as f:
|
||||
f.write(tts_response.content)
|
||||
|
||||
import os
|
||||
file_size = os.path.getsize("speech.mp3")
|
||||
print(f"✓ Speech file created: speech.mp3 ({file_size} bytes)")
|
||||
else:
|
||||
print(f"✗ Failed to create speech file: {tts_response.status_code}")
|
||||
|
||||
print()
|
||||
print("=== Examples Complete ===")
|
||||
2
languages/python/requests/requirements.txt
Normal file
2
languages/python/requests/requirements.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Python HTTP library (checked 2025-10-12)
|
||||
requests==2.32.5
|
||||
Loading…
Add table
Add a link
Reference in a new issue