Client
px.connect() configures a default global client. If you need multiple independent
clients with different configurations, use px.Client() directly.
Simple Config
import proxai as px
client = px.Client(
experiment_path='translation/en-to-fr/experiment_1',
feature_mapping_strategy=px.types.FeatureMappingStrategy.STRICT)
response = client.generate_text(prompt="Hello, world!")More Customized Config
import proxai as px
client = px.Client(
experiment_path='translation/en-to-fr/experiment_1',
logging_options=px.LoggingOptions(
logging_path='~/proxai-logs',
stdout=True,
hide_sensitive_content=True),
cache_options=px.CacheOptions(
cache_path='~/proxai-cache',
unique_response_limit=3,
retry_if_error_cached=True,
clear_query_cache_on_connect=True,
clear_model_cache_on_connect=True,
model_cache_duration=1200),
proxdash_options=px.ProxDashOptions(
stdout=True,
hide_sensitive_content=True,
api_key='your-proxdash-api-key'),
feature_mapping_strategy=px.types.FeatureMappingStrategy.STRICT,
model_test_timeout=60,
allow_multiprocessing=False,
suppress_provider_errors=True)
client.set_model(('openai', 'gpt-4'))
response = client.generate_text(prompt="Hello, world!")Difference Between px.connect() and px.Client()
px.connect() is simply an alias that configures the default global client.
When you call px.generate_text(), it uses this global client internally.
Use px.Client() when you need multiple clients with different configurations
running simultaneously.
import proxai as px
# Configure default global client
px.connect()
px.set_model(('openai', 'gpt-4'))
# Create a separate client instance
client = px.Client()
client.set_model(('anthropic', 'claude-sonnet'))
# Use both clients
response1 = px.generate_text(prompt="Hello!", extensive_return=True)
response2 = client.generate_text(prompt="Hello!", extensive_return=True)
print(response1.query_record.provider_model)
print(response2.query_record.provider_model)(openai, gpt-4)
(anthropic, claude-sonnet)Parameters
px.Client() accepts the same parameters as px.connect():
| Option | Type | Default Value | Description |
|---|---|---|---|
experiment_path | str | None | Path of the experiment for this client. |
cache_options | px.types.CacheOptions | None | Cache options for this client. |
logging_options | px.types.LoggingOptions | None | Logging options for this client. |
proxdash_options | px.types.ProxDashOptions | None | ProxDash options for this client. |
feature_mapping_strategy | FeatureMappingStrategy | BEST_EFFORT | Strategy for handling feature compatibility. |
model_test_timeout | int | 25 | Timeout for the model test in seconds. |
allow_multiprocessing | bool | True | Enable multiprocessing for this client. |
suppress_provider_errors | bool | False | If |