API Reference¶
Client¶
The main client interface for interacting with LLMs.
OpenPO
¶
Main client class for interacting with various LLM providers.
This class serves as the primary interface for making completion requests to different language model providers. OpenPO takes optional api_key arguments for initialization.
Source code in openpo/client.py
completion
property
¶
Access the chat completion functionality for LLM response.µ This property provides access to completion interfacce.
Returns:
Name | Type | Description |
---|---|---|
Completion |
An instance of the Completion class that provides method for generatng response from LLM. |
evaluate
property
¶
Access the evaluation functionality for LLM responses. This property provides access to the evaluation interface.
Returns:
Name | Type | Description |
---|---|---|
Evaluation |
An instance of the Evaluation class that provides methods for evaluating and comparing LLM outputs. |
batch
property
¶
Access the batch processing functionality for LLM operations. This property provides access to the batch processing interface
Returns:
Name | Type | Description |
---|---|---|
Batch |
An instance of the Batch class that provides methods for processing multiple LLM requests efficiently. |
Inference¶
VLLM
¶
VLLM provider class for high-performance inference using the vLLM engine.
This class provides an interface to the vLLM engine for running various LLMs locally.
Attributes:
Name | Type | Description |
---|---|---|
model |
An instance of vLLM's LLM class that handles the model operations. |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
The name or path of the model to load (e.g., 'meta-llama/Llama-2-7b-chat-hf'). |
required |
**kwargs
|
Additional keyword arguments passed to vLLM's LLM initialization. These can include parameters like tensor_parallel_size, gpu_memory_utilization, etc. |
{}
|
Raises:
Type | Description |
---|---|
ImportError
|
If the vLLM package is not installed. The error message includes installation instructions. |
Source code in openpo/resources/provider/vllm.py
generate
¶
generate(messages: List, use_tqdm: bool = True, lora_request=None, chat_template=None, chat_template_content_format='auto', add_generation_prompt: bool = True, continue_final_message: bool = False, tools: Optional[List[Dict[str, Any]]] = None, mm_processor_kwargs: Optional[Dict[str, Any]] = None, sampling_params: Optional[Dict] = {}) -> List
Generate responses using the vLLM model.
This method processes input messages and generates responses using the loaded model. It supports various generation parameters and features like chat templates, LoRA adapters, and tool-based interactions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
List
|
List of input messages to process. |
required |
use_tqdm
|
bool
|
Whether to show a progress bar. Defaults to True. |
True
|
lora_request
|
Optional LoRA adapter configuration for on-the-fly model adaptation. |
None
|
|
chat_template
|
Optional template for formatting chat messages. |
None
|
|
chat_template_content_format
|
str
|
Format for the chat template content. Defaults to "auto". |
'auto'
|
add_generation_prompt
|
bool
|
Whether to add generation prompt. Defaults to True. |
True
|
continue_final_message
|
bool
|
Whether to continue from the final message. Defaults to False. |
False
|
tools
|
Optional[List[Dict[str, Any]]]
|
List of tools available for the model. |
None
|
mm_processor_kwargs
|
Optional[Dict[str, Any]]
|
Additional keyword arguments for multimodal processing. |
None
|
sampling_params
|
Optional[dict]
|
Model specific parameters passed to vLLM's SamplingParams. |
{}
|
Returns:
Type | Description |
---|---|
List
|
The generated vLLM output from the model. |
Raises:
Type | Description |
---|---|
ProviderError
|
If generation fails, with details about the error. |
Source code in openpo/resources/provider/vllm.py
Completion
¶
Source code in openpo/resources/completion/completion.py
generate
¶
generate(model: Union[str, List[str]], messages: List[Dict[str, Any]], params: Optional[Dict[str, Any]] = None) -> List[ChatCompletionOutput]
Generate completions using the specified LLM provider.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
(str, List[str])
|
model identifier or list of model identifiers to use for generation. Follows |
required |
messages
|
List[Dict[str, Any]]
|
List of message dictionaries containing the conversation history and prompts. |
required |
params
|
Optional[Dict[str, Any]]
|
Additional model parameters for the request (e.g., temperature, max_tokens). |
None
|
Returns:
Type | Description |
---|---|
List[ChatCompletionOutput]
|
The response from the LLM provider containing the generated completions. |
Raises:
Type | Description |
---|---|
AuthenticationError
|
If required API keys are missing or invalid. |
ProviderError
|
For provider-specific errors during completion generation. |
ValueError
|
If the model format is invalid. |
Source code in openpo/resources/completion/completion.py
Evaluation
¶
Source code in openpo/resources/eval/eval.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
eval
¶
eval(model: Union[str, List[str]], questions: List[str], responses: List[List[str]], prompt: Optional[str] = None) -> List[Dict]
Evaluate responses using either single or multiple LLMs as judges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
(str, List[str])
|
model identifier or list of them to use as a judge. Follows provider/model-identifier format. |
required |
questions
|
List[str]
|
Questions for each response pair. |
required |
responses
|
List[List[str]]
|
Pairwise responses to evaluate. |
required |
prompt
|
str
|
Optional custom prompt for judge model to follow. |
None
|
Returns:
Type | Description |
---|---|
List[Dict]
|
List[Dict]: The evaluation data for responses. Response returns preferred, rejected, confidence_score and reason. |
Raises:
Type | Description |
---|---|
AuthenticationError
|
If required API keys are missing or invalid. |
ProviderError
|
For provider-specific errors during evaluation. |
ValueError
|
If the model format is invalid or required models are missing. |
Source code in openpo/resources/eval/eval.py
get_consensus
¶
Reach consensus between two evaluation results
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eval_A
|
List
|
List of batch results to compare |
required |
eval_B
|
List
|
List of batch results to compare |
required |
Returns:
Name | Type | Description |
---|---|---|
List |
List
|
List of evaluation results where both providers agreed on the rank |
Raises:
Type | Description |
---|---|
Exception
|
If there's an error processing the batch results |
Source code in openpo/resources/eval/eval.py
Batch
¶
Source code in openpo/resources/batch/batch.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
eval
¶
eval(model: Union[str, List[str]], questions: List[str], responses: List[List[str]], prompt: Optional[str] = None)
Use input model as a judge to evaluate responses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
(str, List[str])
|
model identifier or list of them to use as a judge. Follows provider/model-identifier format. |
required |
questions
|
List(str
|
Questions for each response pair. |
required |
responses
|
List[List[str]]
|
Pairwise responses to evaluate. |
required |
prompt
|
str
|
Optional custom prompt for judge model to follow. |
None
|
Returns (Dict): The evaluation data for responses with preferred, rejected, confidence_score and reason.
Raises:
Type | Description |
---|---|
AuthenticationError
|
If required API keys are missing or invalid. |
ProviderError
|
For provider-specific errors during evaluation. |
ValueError
|
If the model format is invalid or provider is not supported. |
Source code in openpo/resources/batch/batch.py
get_consensus
¶
Reach consensus between two batch results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_A
|
List
|
List of batch results to compare |
required |
batch_B
|
List
|
List of batch results to compare |
required |
Returns:
Type | Description |
---|---|
List[Dict]
|
List[Dict]: List of evaluation results where both providers agree on |
Raises:
Type | Description |
---|---|
Exception
|
If there's an error processing the batch results |
Source code in openpo/resources/batch/batch.py
Evaluation Model¶
PairRM
¶
A class that implements the Pairwise Rewards Model (PairRM) for evaluating and ranking LLM responses.
This class uses the llm-blender package to load and utilize the PairRM model, which can rank multiple responses for a given prompt based on their quality.
Source code in openpo/resources/pairrm/pairrm.py
eval
¶
Evaluates and ranks multiple responses for given prompts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
List
|
List of input prompts to evaluate. |
required |
responses
|
List
|
List of response sets to be ranked. Each response set should contain multiple responses for the corresponding prompt. |
required |
Returns:
Type | Description |
---|---|
List[dict]
|
List[dict]: A formatted list of preference data containing the ranking results. See _format_preference method for the structure of the returned data. |
Source code in openpo/resources/pairrm/pairrm.py
Prometheus2
¶
A class that implements the Prometheus2 evaluation model for assessing LLM responses.
This class provides methods for both relative and absolute evaluation of LLM responses using different rubrics such as factual validity, helpfulness, honesty, and reasoning.
Source code in openpo/resources/prometheus2/prometheus2.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
eval_relative
¶
eval_relative(instructions: List[str], responses_A: List[str], responses_B: List[str], rubric: str) -> List[dict]
Performs relative evaluation comparing pairs of responses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instructions
|
List[str]
|
List of instruction prompts. |
required |
responses_A
|
List[str]
|
First set of responses to compare. |
required |
responses_B
|
List[str]
|
Second set of responses to compare. |
required |
rubric
|
str
|
The evaluation rubric to use. Supported rubrics:
|
required |
Returns:
Type | Description |
---|---|
List[dict]
|
List[dict]: A formatted list of evaluation results containing preferences and feedback. |
Raises:
Type | Description |
---|---|
Exception
|
If there's an error during the evaluation process. |
Source code in openpo/resources/prometheus2/prometheus2.py
eval_absolute
¶
Performs absolute evaluation of individual responses.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instructions
|
List[str]
|
List of instruction prompts. |
required |
responses
|
List[str]
|
List of responses to evaluate. |
required |
rubric
|
str
|
The evaluation rubric to use. Supported rubrics:
|
required |
Returns:
Type | Description |
---|---|
List[dict]
|
List[dict]: A formatted list of evaluation results containing scores and feedback. |
Raises:
Type | Description |
---|---|
Exception
|
If there's an error during the evaluation process. |
Source code in openpo/resources/prometheus2/prometheus2.py
Storage¶
HuggingFaceStorage
¶
Storage class for HuggingFace Datasets.
This class provides methods to store and retrieve data from HuggingFace's dataset repositories. It handles the creation of repositories and manages data upload and download operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
str
|
HuggingFace API token with write access. Environment variable can be set instead of passing in the key. |
None
|
Raises:
Type | Description |
---|---|
AuthenticationError
|
If authentication fails |
ProviderError
|
If HuggingFace error is raised |
Source code in openpo/storage/huggingface.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|
push_to_repo
¶
push_to_repo(repo_id: str, data: Union[List[Dict[str, Any]], pd.DataFrame], config_name: str = 'default', set_default: Optional[bool] = None, split: Optional[str] = None, data_dir: Optional[str] = None, commit_message: Optional[str] = None, commit_description: Optional[str] = None, private: Optional[bool] = False, token: Optional[str] = None, revision: Optional[str] = None, create_pr: Optional[bool] = False, max_shard_size: Optional[Union[int, str]] = None, num_shards: Optional[int] = None, embed_external_files: bool = True)
Push data to HuggingFace dataset repository. This is the implementation of HuggingFace Dataset's push_to_hub method. For parameters not listed, check HuggingFace documentation for more detail.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Union[List[Dict[str, Any]], DataFrame]
|
The data to upload.
|
required |
repo_id
|
str
|
Name of the dataset repository. |
required |
Raises:
Type | Description |
---|---|
Exception
|
If pushing to dataset repository fails. |
Source code in openpo/storage/huggingface.py
load_from_repo
¶
load_from_repo(path: str, name: Optional[str] = None, data_dir: Optional[str] = None, data_files: Optional[Union[str, Sequence[str], Mapping[str, Union[str, Sequence[str]]]]] = None, split: Optional[str] = None, cache_dir: Optional[str] = None, features=None, download_config=None, download_mode=None, verification_mode=None, keep_in_memory: Optional[bool] = None, save_infos: bool = False, revision: Optional[str] = None, token: Optional[Union[bool, str]] = None, streaming: bool = False, num_proc: Optional[int] = None, storage_options: Optional[Dict] = None, trust_remote_code: bool = None, **config_kwargs) -> Union[DatasetDict, Dataset, IterableDatasetDict, IterableDataset]
Load data from HuggingFace dataset repository. This is direct implementation of HuggingFace Dataset load_dataset method. For arguments not listed here, check HuggingFace documentation for more detail.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Path or name of the dataset. |
required |
Raises:
Type | Description |
---|---|
Exception
|
If loading data from repository fails. |
Source code in openpo/storage/huggingface.py
S3Storage
¶
Storage adapter for Amazon S3.
This class provides methods to store and retrieve data from Amazon S3 buckets. It handles JSON serialization/deserialization and manages S3 operations through boto3 client.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**kwargs
|
Keyword arguments can be passed to access AWS:
Alternatively, credentials can be configured with aws configure |
{}
|
Raises:
Type | Description |
---|---|
ProviderError
|
If S3 Client error is raised |
Source code in openpo/storage/s3.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
push_to_s3
¶
push_to_s3(data: Union[List[Dict[str, Any]], pd.DataFrame, bytes], bucket: str, key: Optional[str] = None, ext_type: Literal['parquet', 'json'] = 'parquet')
Upload data to an S3 bucket.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Union[List[Dict[str, Any]], DataFrame, bytes]
|
The data to upload.
|
required |
bucket
|
str
|
Name of the S3 bucket |
required |
key
|
str
|
Object key (path) in the bucket |
None
|
ext_type
|
str
|
Type of serialization to use:
|
'parquet'
|
Raises:
Type | Description |
---|---|
ClientError
|
If S3 operation fails |
TypeError
|
If data type is not compatible with chosen serialization type |
ValueError
|
If serialization type is not supported or data cannot be deserialized |
Source code in openpo/storage/s3.py
load_from_s3
¶
Read data from an S3 bucket.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bucket
|
str
|
Name of the S3 bucket. |
required |
key
|
str
|
Object name (path) in the bucket. |
required |
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
List[Dict]: The loaded data as a list of dictionaries. |
Raises:
Type | Description |
---|---|
ClientError
|
If S3 operation fails. |
ValueError
|
If content type is not supported or content cannot be parsed. |