MultiUnify
__init__
Initialize the Multi LLM Unify client.
Arguments:
endpoints
- A single endpoint name or a list of endpoint names, with each namesystem_message
- An optional string containing the system message. Thismessages
- A list of messages comprising the conversation so far. This willfrequency_penalty
- Number between -2.0 and 2.0. Positive values penalize newlogit_bias
- Modify the likelihood of specified tokens appearing in thelogprobs
- Whether to return log probabilities of the output tokens or not.top_logprobs
- An integer between 0 and 20 specifying the number of mostmax_completion_tokens
- The maximum number of tokens that can be generated inn
- How many chat completion choices to generate for each input message. Notepresence_penalty
- Number between -2.0 and 2.0. Positive values penalize newresponse_format
- An object specifying the format that the model must output.seed
- If specified, a best effort attempt is made to samplestop
- Up to 4 sequences where the API will stop generating further tokens.temperature
- What sampling temperature to use, between 0 and 2.top_p
- An alternative to sampling with temperature, called nucleus sampling,tools
- A list of tools the model may call. Currently, only functions aretool_choice
- Controls which (if any) tool is called by theparallel_tool_calls
- Whether to enable parallel function calling during tooluse_custom_keys
- Whether to use custom API keys or our unified API keystags
- Arbitrary number of tags to classify this API query as needed. Helpfuldrop_params
- Whether or not to drop unsupported OpenAI params by theregion
- A string used to represent the region where the endpoint islog_query_body
- Whether to log the contents of the query json body.log_response_body
- Whether to log the contents of the response json body.stateful
- Whether the conversation history is preserved within the messagesreturn_full_completion
- If False, only return the message contenttraced
- Whether to trace the generate method.cache
- If True, then the arguments will be stored in a local cache file, andextra_headers
- Additional “passthrough” headers for the request which areextra_query
- Additional “passthrough” query parameters for the request whichkwargs
- Additional “passthrough” JSON properties for the body of the
Raises:
UnifyError
: If the API key is missing.
properties
cache
Get default the cache bool.
Returns:
The default cache bool.
clients
Get the current dictionary of clients, with endpoint names as keys and Unify or AsyncUnify instances as values.
Returns:
The dictionary of clients.
default_prompt
Get the default prompt, if set.
Returns:
The default prompt.
drop_params
Get the default drop_params bool, if set.
Returns:
The default drop_params bool.
endpoints
Get the current tuple of endpoints.
Returns:
The tuple of endpoints.
extra_body
Get the default extra body, if set.
Returns:
The default extra body.
extra_headers
Get the default extra headers, if set.
Returns:
The default extra headers.
extra_query
Get the default extra query, if set.
Returns:
The default extra query.
frequency_penalty
Get the default frequency penalty, if set.
Returns:
The default frequency penalty.
input_cost
itl
log_query_body
Get the default log query body bool, if set.
Returns:
The default log query body bool.
log_response_body
Get the default log response body bool, if set.
Returns:
The default log response body bool.
logit_bias
Get the default logit bias, if set.
Returns:
The default logit bias.
logprobs
Get the default logprobs, if set.
Returns:
The default logprobs.
max_completion_tokens
Get the default max tokens, if set.
Returns:
The default max tokens.
messages
Get the default messages, if set.
Returns:
The default messages.
n
Get the default n, if set.
Returns:
The default n value.
output_cost
parallel_tool_calls
Get the default parallel tool calls bool, if set.
Returns:
The default parallel tool calls bool.
presence_penalty
Get the default presence penalty, if set.
Returns:
The default presence penalty.
region
Get the default region, if set.
Returns:
The default region.
response_format
Get the default response format, if set.
Returns:
The default response format.
return_full_completion
Get the default return full completion bool.
Returns:
The default return full completion bool.
seed
Get the default seed value, if set.
Returns:
The default seed value.
stateful
Get the default stateful bool, if set.
Returns:
The default stateful bool.
stop
Get the default stop value, if set.
Returns:
The default stop value.
stream
Get the default stream bool, if set.
Returns:
The default stream bool.
stream_options
Get the default stream options, if set.
Returns:
The default stream options.
system_message
Get the default system message, if set.
Returns:
The default system message.
tags
Get the default tags, if set.
Returns:
The default tags.
temperature
Get the default temperature, if set.
Returns:
The default temperature.
tool_choice
Get the default tool choice, if set.
Returns:
The default tool choice.
tools
Get the default tools, if set.
Returns:
The default tools.
top_logprobs
Get the default top logprobs, if set.
Returns:
The default top logprobs.
top_p
Get the default top p value, if set.
Returns:
The default top p value.
traced
Get the default traced bool.
Returns:
The default traced bool.
ttft
use_custom_keys
Get the default use custom keys bool, if set.
Returns:
The default use custom keys bool.
setters
set_cache
Set the default cache bool.
Arguments:
value
- The default cache bool.
Returns:
This client, useful for chaining inplace calls.
set_default_prompt
Set the default prompt.
Returns:
This client, useful for chaining inplace calls.
set_drop_params
Set the default drop params bool.
Arguments:
value
- The default drop params bool.
Returns:
This client, useful for chaining inplace calls.
set_extra_body
Set the default extra body.
Arguments:
value
- The default extra body.
Returns:
This client, useful for chaining inplace calls.
set_extra_headers
Set the default extra headers.
Arguments:
value
- The default extra headers.
Returns:
This client, useful for chaining inplace calls.
set_extra_query
Set the default extra query.
Arguments:
value
- The default extra query.
Returns:
This client, useful for chaining inplace calls.
set_frequency_penalty
Set the default frequency penalty.
Arguments:
value
- The default frequency penalty.
Returns:
This client, useful for chaining inplace calls.
set_log_query_body
Set the default log query body bool.
Arguments:
value
- The default log query body bool.
Returns:
This client, useful for chaining inplace calls.
set_log_response_body
Set the default log response body bool.
Arguments:
value
- The default log response body bool.
Returns:
This client, useful for chaining inplace calls.
set_logit_bias
Set the default logit bias.
Arguments:
value
- The default logit bias.
Returns:
This client, useful for chaining inplace calls.
set_logprobs
Set the default logprobs.
Arguments:
value
- The default logprobs.
Returns:
This client, useful for chaining inplace calls.
set_max_completion_tokens
Set the default max tokens.
Arguments:
value
- The default max tokens.
Returns:
This client, useful for chaining inplace calls.
set_messages
Set the default messages.
Arguments:
value
- The default messages.
Returns:
This client, useful for chaining inplace calls.
set_n
Set the default n value.
Arguments:
value
- The default n value.
Returns:
This client, useful for chaining inplace calls.
set_parallel_tool_calls
Set the default parallel tool calls bool.
Arguments:
value
- The default parallel tool calls bool.
Returns:
This client, useful for chaining inplace calls.
set_presence_penalty
Set the default presence penalty.
Arguments:
value
- The default presence penalty.
Returns:
This client, useful for chaining inplace calls.
set_region
Set the default region.
Arguments:
value
- The default region.
Returns:
This client, useful for chaining inplace calls.
set_response_format
Set the default response format.
Arguments:
value
- The default response format.
Returns:
This client, useful for chaining inplace calls.
set_return_full_completion
Set the default return full completion bool.
Arguments:
value
- The default return full completion bool.
Returns:
This client, useful for chaining inplace calls.
set_seed
Set the default seed value.
Arguments:
value
- The default seed value.
Returns:
This client, useful for chaining inplace calls.
set_stateful
Set the default stateful bool.
Arguments:
value
- The default stateful bool.
Returns:
This client, useful for chaining inplace calls.
set_stop
Set the default stop value.
Arguments:
value
- The default stop value.
Returns:
This client, useful for chaining inplace calls.
set_stream
Set the default stream bool.
Arguments:
value
- The default stream bool.
Returns:
This client, useful for chaining inplace calls.
set_stream_options
Set the default stream options.
Arguments:
value
- The default stream options.
Returns:
This client, useful for chaining inplace calls.
set_system_message
Set the default system message.
Arguments:
value
- The default system message.
Returns:
This client, useful for chaining inplace calls.
set_tags
Set the default tags.
Arguments:
value
- The default tags.
Returns:
This client, useful for chaining inplace calls.
set_temperature
Set the default temperature.
Arguments:
value
- The default temperature.
Returns:
This client, useful for chaining inplace calls.
set_tool_choice
Set the default tool choice.
Arguments:
value
- The default tool choice.
Returns:
This client, useful for chaining inplace calls.
set_tools
Set the default tools.
Arguments:
value
- The default tools.
Returns:
This client, useful for chaining inplace calls.
set_top_logprobs
Set the default top logprobs.
Arguments:
value
- The default top logprobs.
Returns:
This client, useful for chaining inplace calls.
set_top_p
Set the default top p value.
Arguments:
value
- The default top p value.
Returns:
This client, useful for chaining inplace calls.
set_traced
Set the default traced bool.
Arguments:
value
- The default traced bool.
Returns:
This client, useful for chaining inplace calls.
set_use_custom_keys
Set the default use custom keys bool.
Arguments:
value
- The default use custom keys bool.
Returns:
This client, useful for chaining inplace calls.
methods
add_endpoints
Add extra endpoints to be queried for each call to generate.
Arguments:
endpoints
- The extra endpoints to add.ignore_duplicates
- Whether or not to ignore duplicate endpoints passed.
Returns:
This client, useful for chaining inplace calls.
append_messages
Append to the default messages.
Arguments:
value
- The messages to append to the default.
Returns:
This client, useful for chaining inplace calls.
generate
Generate a ChatCompletion response for the specified endpoint, from the provided query parameters.
Arguments:
arg0
- A string containing the user message, or a list containing the inputssystem_message
- An optional string containing the system message. Thismessages
- A list of messages comprising the conversation so far, orfrequency_penalty
- Number between -2.0 and 2.0. Positive values penalize newlogit_bias
- Modify the likelihood of specified tokens appearing in thelogprobs
- Whether to return log probabilities of the output tokens or not.top_logprobs
- An integer between 0 and 20 specifying the number of mostmax_completion_tokens
- The maximum number of tokens that can be generated inn
- How many chat completion choices to generate for each input message. Notepresence_penalty
- Number between -2.0 and 2.0. Positive values penalize newresponse_format
- An object specifying the format that the model must output.seed
- If specified, a best effort attempt is made to samplestop
- Up to 4 sequences where the API will stop generating further tokens.stream
- If True, generates content as a stream. If False, generates contentstream_options
- Options for streaming response. Only set this when you setstream
- true.temperature
- What sampling temperature to use, between 0 and 2.top_p
- An alternative to sampling with temperature, called nucleus sampling,tools
- A list of tools the model may call. Currently, only functions aretool_choice
- Controls which (if any) tool is called by theparallel_tool_calls
- Whether to enable parallel function calling during toolstateful
- Whether the conversation history is preserved within the messagesuse_custom_keys
- Whether to use custom API keys or our unified API keystags
- Arbitrary number of tags to classify this API query as needed. Helpfuldrop_params
- Whether or not to drop unsupported OpenAI params by theregion
- A string used to represent the region where the endpoint islog_query_body
- Whether to log the contents of the query json body.log_response_body
- Whether to log the contents of the response json body.stateful
- Whether the conversation history is preserved within the messagesreturn_full_completion
- If False, only return the message contentcache
- If True, then the arguments will be stored in a local cache file, andextra_headers
- Additional “passthrough” headers for the request which areextra_query
- Additional “passthrough” query parameters for the request whichkwargs
- Additional “passthrough” JSON properties for the body of the
Returns:
If stream is True, returns a generator yielding chunks of content. If stream is False, returns a single string response.
Raises:
UnifyError
: If an error occurs during content generation.
get_credit_balance
Get the remaining credits left on your account.
Returns:
The remaining credits on the account if successful, otherwise None. Raises: BadRequestError: If there was an HTTP error. ValueError: If there was an error parsing the JSON response.
BadRequestError
- If there was an HTTP error.ValueError
- If there was an error parsing the JSON response.
remove_endpoints
Remove endpoints from the current list, which are queried for each call to generate.
Arguments:
endpoints
- The extra endpoints to add.ignore_missing
- Whether or not to ignore endpoints passed which are not
Returns:
This client, useful for chaining inplace calls.
to_async_client
Return an asynchronous version of the client (AsyncMultiUnify
instance), with
the exact same configuration as this synchronous (MultiUnify
) client.
Returns:
An AsyncMultiUnify
instance with the same configuration as this MultiUnify
instance.