pip install v0studio
poetry add v0studio
conda install -c conda-forge v0studio
pip install v0studio[dev]
Includes development dependencies like numpy, pandas, and scikit-learn
import v0studio as v0s
# Initialize the client
client = v0s.V0Studio(
server_url="http://localhost:1234",
api_key="your-api-key" # Optional for local usage
)
# Simple text completion
def basic_completion():
try:
response = client.completions.create(
model="llama-3-8b-instruct",
prompt="Explain machine learning in simple terms:",
max_tokens=200,
temperature=0.7
)
print(response.choices[0].text)
except v0s.V0StudioError as e:
print(f"Error: {e}")
if __name__ == "__main__":
basic_completion()
import v0studio as v0s
# Initialize the client
client = v0s.V0Studio(
server_url="http://localhost:1234",
api_key="your-api-key" # Optional for local usage
)
# Simple text completion
def basic_completion():
try:
response = client.completions.create(
model="llama-3-8b-instruct",
prompt="Explain machine learning in simple terms:",
max_tokens=200,
temperature=0.7
)
print(response.choices[0].text)
except v0s.V0StudioError as e:
print(f"Error: {e}")
if __name__ == "__main__":
basic_completion()
Main synchronous client
Async client for concurrent operations
Generate text completions
model: str,
prompt: str,
max_tokens: Optional[int] = None,
temperature: Optional[float] = None,
stream: bool = False
Create chat completions
model: str,
messages: List[Dict[str, str]],
max_tokens: Optional[int] = None,
temperature: Optional[float] = None,
stream: bool = False
Generate text embeddings
model: str,
input: Union[str, List[str]],
encoding_format: str = "float"
The v0studio-python SDK provides full async support for high-performance applications that need to handle multiple AI requests concurrently.
import asyncio
import v0studio as v0s
# Async client for concurrent operations
async_client = v0s.AsyncV0Studio()
async def async_completion():
try:
response = await async_client.completions.create(
model="llama-3-8b-instruct",
prompt="Explain async programming in Python:",
max_tokens=300,
temperature=0.6
)
return response.choices[0].text
except v0s.V0StudioError as e:
print(f"Async error: {e}")
return None
async def multiple_completions():
prompts = [
"What is Python?",
"Explain list comprehensions",
"How do decorators work?",
"What are generators?"
]
# Run multiple completions concurrently
tasks = [
async_client.completions.create(
model="llama-3-8b-instruct",
prompt=prompt,
max_tokens=150
) for prompt in prompts
]
responses = await asyncio.gather(*tasks)
for prompt, response in zip(prompts, responses):
print(f"Q: {prompt}")
print(f"A: {response.choices[0].text}\n")
# Run async functions
asyncio.run(multiple_completions())
import v0studio as v0s
import os
# Basic configuration
client = v0s.V0Studio(
server_url="http://localhost:1234", # v0studio server URL
api_key="your-api-key", # Optional API key
timeout=30.0, # Request timeout (seconds)
max_retries=3, # Number of retry attempts
headers={ # Additional headers
"User-Agent": "my-app/1.0.0"
}
)
# Advanced configuration
client = v0s.V0Studio(
server_url=os.getenv("V0STUDIO_SERVER_URL", "http://localhost:1234"),
api_key=os.getenv("V0STUDIO_API_KEY"),
timeout=60.0,
max_retries=5,
backoff_factor=2.0, # Exponential backoff multiplier
verify_ssl=True, # SSL certificate verification
proxy={ # Proxy settings
"http": "http://proxy.example.com:8080",
"https": "https://proxy.example.com:8080"
}
)
# Environment variables
# V0STUDIO_SERVER_URL
# V0STUDIO_API_KEY
# V0STUDIO_TIMEOUT
# V0STUDIO_MAX_RETRIES
If you encounter import errors:
pip show v0studio
pip uninstall v0studio && pip install v0studio
For connection problems:
curl http://localhost:1234/v1/models
v0s.set_debug(True)
To optimize performance:
Enable detailed logging:
import logging
import v0studio as v0s
# Enable debug logging
logging.basicConfig(level=logging.DEBUG)
v0s.set_debug(True)
# The SDK will now log detailed request/response information