BlackBoxModel provides a standardized interface for interacting with models hosted via APIs like OpenAI, Anthropic, and Together.ai. This class handles authentication, retry logic, and batch processing for efficient model querying.
Constructor
from generalanalysis.boiler_room import BlackBoxModel
model = BlackBoxModel(
model_name="gpt-4o",
system_prompt=None, # Optional
max_retries=5, # Optional
retry_delay=10.0 # Optional
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
model_name | string | (Required) | Name of the model (e.g., “gpt-4o”, “claude-3-7-sonnet-20250219”) |
system_prompt | string | None | Default system prompt to use for all queries |
max_retries | int | 5 | Maximum number of retry attempts for failed queries |
retry_delay | float | 10.0 | Delay in seconds between retry attempts |
Methods
query
Sends a prompt to the model and retrieves the generated response.
response = model.query(
prompt="Explain quantum computing",
system_prompt=None, # Overrides default if provided
temperature=0.7, # Optional
max_tokens=2048 # Optional
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
prompt | string | (Required) | The text prompt to send to the model |
system_prompt | string | None | System prompt for this specific query |
temperature | float | 0 | Controls randomness (0.0 = deterministic, 1.0 = creative) |
max_tokens | int | 2048 | Maximum number of tokens to generate |
message_history | List[Dict] | [] | Message history for chat context |
Returns
A string containing the model’s response.
query_parallel
Sends multiple prompts to the model in parallel for efficiency.
responses = model.query_parallel(
prompts=["Tell me about Mars", "Tell me about Venus"],
max_threads=50, # Optional
show_progress=True, # Optional
system_prompt=None, # Optional
temperature=0.7 # Optional
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
prompts | List[string] | (Required) | List of text prompts to send to the model |
max_threads | int | 50 | Maximum number of parallel threads to use |
show_progress | bool | True | Whether to display a progress bar |
system_prompt | string | None | System prompt for all queries |
temperature | float | 0 | Controls randomness |
max_tokens | int | 2048 | Maximum number of tokens to generate |
message_history | List[Dict] | [] | Message history for chat context |
Returns
A list of strings containing the model’s responses in the same order as the input prompts.
embed
Generates embeddings (vector representations) for text.
embedding = model.embed(
text="Text to embed",
batch_size=100 # Optional
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
text | string or List[string] | (Required) | Text to generate embeddings for |
batch_size | int | 100 | Maximum batch size for processing |
Returns
A list of float values (embedding vector) if a single text is provided, or a list of embedding vectors (list of lists) if multiple texts are provided.
embed_parallel
Generates embeddings for multiple texts in parallel.
embeddings = model.embed_parallel(
texts=["Text one", "Text two"],
batch_size=100, # Optional
max_threads=10, # Optional
show_progress=True # Optional
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
texts | List[string] | (Required) | List of texts to generate embeddings for |
batch_size | int | 100 | Maximum batch size for processing |
max_threads | int | 10 | Maximum number of parallel threads to use |
show_progress | bool | True | Whether to display a progress bar |
Returns
A list of embedding vectors (list of lists of float values), one for each input text.
Supported Models
The BlackBoxModel class automatically determines the appropriate API to use based on the model name:
OpenAI Models
- GPT-4o, GPT-4o-mini, GPT-4-turbo
- GPT-4.5-preview-2025-02-27
- GPT-4-0125-preview, GPT-4-0613
- GPT-3.5-turbo
- o1, o1-mini, o3-mini, o3-mini-2025-01-31
- Embedding models: text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002
Anthropic Models
- claude-3-7-sonnet-20250219
- claude-3-5-sonnet-20241022, claude-3-5-sonnet-20240620
- claude-3-5-haiku-20241022
- claude-3-sonnet-20240229
Together.ai Hosted Models
- meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo
- meta-llama/Llama-3.3-70B-Instruct-Turbo
- meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo
- mistralai/Mistral-Small-24B-Instruct-2501
- mistralai/Mixtral-8x22B-Instruct-v0.1
- deepseek-ai/DeepSeek-R1, deepseek-ai/DeepSeek-R1-Distill-Llama-70B
- databricks/dbrx-instruct
- Qwen/Qwen2.5-7B-Instruct-Turbo
- google/gemma-2-27b-it
Error Handling
The BlackBoxModel implements robust error handling:
- Automatic retries for temporary API failures
- Logging of error details for debugging
- Graceful degradation for rate limiting
Examples
Basic Query
model = BlackBoxModel("claude-3-7-sonnet-20250219")
response = model.query("Summarize the key points of quantum computing")
print(response)Parallel Processing
questions = [
"What is quantum computing?",
"What are qubits?",
"Explain quantum entanglement"
]
model = BlackBoxModel("meta-llama/Llama-3.3-70B-Instruct-Turbo")
answers = model.query_parallel(
prompts=questions,
max_threads=3,
temperature=0.5
)
for question, answer in zip(questions, answers):
print(f"Q: {question}")
print(f"A: {answer}")
print()Semantic Search with Embeddings
model = BlackBoxModel("text-embedding-3-small")
documents = [
"Quantum computing uses quantum bits or qubits.",
"Classical computing uses binary digits or bits.",
"Superposition allows qubits to exist in multiple states simultaneously."
]
query = "How are quantum computers different?"
query_embedding = model.embed(query)
document_embeddings = model.embed_parallel(documents)
# Now you can compare embeddings to find the most relevant documents