This directory contains comprehensive examples and tests for the SVECTOR Python SDK, demonstrating all available features including conversations, chat completions, vision analysis, and more.
examples_vision_comprehensive.py- Complete vision API demonstration with all featuresexamples_exact_format.py- Exact format examples matching Node.js/JSR SDK patternsexamples_vision.py- Basic vision API examplesexamples_vision_file.py- File upload and vision analysis examples
examples_comprehensive.py- Complete SDK demonstration with all APIsexamples.py- Basic usage examples and getting started
test_vision_quick.py- Quick vision API functionality testtest_streaming.py- Streaming functionality testtest_final.py- Comprehensive test suitetest_import.py- Import and basic functionality test
pip install svector-sdk
export SVECTOR_API_KEY="your-api-key-here"# Run comprehensive vision examples
python examples/examples_vision_comprehensive.py
# Run exact format examples (matching Node.js patterns)
python examples/examples_exact_format.py
# Run quick vision test
python examples/test_vision_quick.py
# Run streaming test
python examples/test_streaming.pyfrom svector import SVECTOR
client = SVECTOR()
# Analyze image from URL
response = client.vision.analyze_from_url(
image_url="https://example.com/image.jpg",
prompt="What do you see in this image?",
detail="high"
)
print(response.analysis)# Using responses.create format
response = client.responses.create(
model="spec-3-turbo",
input=[{
"role": "user",
"content": [
{"type": "input_text", "text": "what's in this image?"},
{
"type": "input_image",
"image_url": "https://example.com/image.jpg",
},
],
}],
)
print(response.output_text)import base64
# Function to encode the image
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
# Getting the Base64 string
base64_image = encode_image("path_to_your_image.jpg")
response = client.responses.create(
model="spec-3-turbo",
input=[
{
"role": "user",
"content": [
{ "type": "input_text", "text": "what's in this image?" },
{
"type": "input_image",
"image_url": f"data:image/jpeg;base64,{base64_image}",
},
],
}
],
)
print(response.output_text)# Function to create a file with the Files API
def create_file(file_path):
with open(file_path, "rb") as file_content:
result = client.files.create(
file=file_content,
purpose="vision",
)
return result["file_id"]
# Getting the file ID
file_id = create_file("path_to_your_image.jpg")
response = client.responses.create(
model="spec-3-turbo",
input=[{
"role": "user",
"content": [
{"type": "input_text", "text": "what's in this image?"},
{
"type": "input_image",
"file_id": file_id,
},
],
}],
)
print(response.output_text)response = client.vision.extract_text(
image_url="https://example.com/document.jpg"
)
print(f"Extracted text: {response.analysis}")response = client.vision.detect_objects(
image_url="https://example.com/scene.jpg",
object_types=["cars", "people", "buildings"]
)
print(f"Detected objects: {response.analysis}")images = [
{"url": "https://example.com/image1.jpg"},
{"url": "https://example.com/image2.jpg"}
]
response = client.vision.compare_images(
images=images,
prompt="Compare these images and describe differences"
)
print(response.analysis)result = client.vision.analyze_with_confidence(
image_url="https://example.com/image.jpg",
prompt="Analyze this image"
)
print(f"Analysis: {result['analysis']}")
print(f"Confidence: {result['confidence']}%")images = [
{"image_url": "https://example.com/1.jpg", "prompt": "Describe this"},
{"image_url": "https://example.com/2.jpg", "prompt": "What's here?"}
]
results = client.vision.batch_analyze(images, delay=1.0)
for i, result in enumerate(results):
print(f"Image {i+1}: {result['analysis']}")response = client.conversations.create(
model="spec-3-turbo",
instructions="You are a helpful AI assistant.",
input="Explain quantum computing in simple terms."
)
print(response.output)stream = client.conversations.create_stream(
model="spec-3-turbo",
instructions="You are a creative writer.",
input="Write a short poem about technology."
)
for event in stream:
if not event.done:
print(event.content, end="", flush=True)response = client.chat.create(
model="spec-3-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is machine learning?"}
]
)
print(response["choices"][0]["message"]["content"])with open("document.pdf", "rb") as f:
file_response = client.files.create(
file=f,
purpose="default"
)
print(f"File ID: {file_response['file_id']}")from svector import APIError, AuthenticationError, RateLimitError
try:
response = client.vision.analyze_from_url(
image_url="https://example.com/image.jpg"
)
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Rate limit exceeded")
except APIError as e:
print(f"API error: {e}")from svector import encode_image, create_data_url
# Encode image to base64
base64_data = encode_image("path/to/image.jpg")
# Create data URL
data_url = create_data_url(base64_data, "image/jpeg")- Always handle errors - Wrap API calls in try-catch blocks
- Use appropriate timeouts - Set reasonable timeouts for vision requests
- Optimize image sizes - Smaller images process faster
- Use specific prompts - Better prompts yield better results
- Handle rate limits - Add delays between batch requests
- Choose the right detail level - Use "high" for complex analysis, "low" for speed
- Timeout errors: Reduce image size or set
detail="low" - Authentication errors: Check your API key
- Rate limiting: Add delays between requests
- Large images: Use file upload method instead of base64
Set environment variable for detailed logging:
export SVECTOR_DEBUG=1
python your_script.py- SVECTOR Dashboard - Get your API key
- Python SDK Documentation - Complete documentation
- API Reference - Full API documentation
If you encounter issues:
- Check the examples in this directory
- Review the main README.md
- Contact support at support@svector.co.in