Models
Bases: ABC
An abstract base class representing a model.
Attributes:
Name | Type | Description |
---|---|---|
model_name |
property
|
A property representing the name of the model. |
support_concurrency |
bool
|
A flag indicating if the model supports concurrency. |
Methods:
Name | Description |
---|---|
model_name |
Abstract method to return the name of the model. |
get_prompt_completion |
str) -> str: Abstract method to generate completion for a given prompt. |
prompt_formatter |
str) -> Union[str, List[Dict]]: Abstract method to format a prompt. |
completion_formatter |
str) -> str: Method to format the model completion. |
generate_completions |
TaskMatchGroup, prefer_concurrency: bool = True, n_workers: int = 4) -> TaskMatchGroup: Method to generate completions for a list of matches, optionally using concurrency. |
Note
This class should be subclassed to implement the abstract methods.
Source code in parsbench/models/base.py
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 |
|
Bases: Model
A model interface for OpenAI-like APIs.
Attributes:
Name | Type | Description |
---|---|---|
api_base_url |
str
|
The base URL for the OpenAI API. |
api_secret_key |
str
|
The secret key for accessing the OpenAI API. |
model |
str
|
The specific model being used for processing. |
instruction_prompt |
str
|
The default instruction prompt for the model. |
model_parameters |
dict
|
Additional parameters specific to the model. |
completion_parameters |
dict
|
Parameters for completion generation. |
retry_on_ratelimit |
bool = False, |
|
cooldown_interval |
int = 10, |
|
max_retries |
int = 1, |
|
client |
OpenAI
|
An instance of the OpenAI client for API interactions. |
Methods:
Name | Description |
---|---|
model_name |
Returns the name of the model. |
prompt_formatter |
Formats a given prompt into a list of messages. Could be overloaded. |
completion_formatter |
Method to format the model completion. Could be overloaded. |
get_prompt_completion |
Generates completion for a given prompt using the OpenAI API. |
generate_completions |
Generates completions for a list of TaskMatch objects using ThreadPoolExecutor. |
Source code in parsbench/models/openai_interface.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 |
|
Bases: Model
A model interface for Anthropic-like APIs.
Attributes:
Name | Type | Description |
---|---|---|
api_base_url |
str
|
The base URL for the Anthropic API. |
api_secret_key |
str
|
The secret key for accessing the Anthropic API. |
model |
str
|
The name of the model. |
instruction_prompt |
str
|
The default instruction prompt for the model. |
model_parameters |
dict
|
Additional parameters specific to the model. |
completion_parameters |
dict
|
Parameters for generating completions. |
retry_on_ratelimit |
bool = False, |
|
cooldown_interval |
int = 10, |
|
max_retries |
int = 1, |
|
client |
Anthropic
|
An instance of the Anthropic client for API interactions. |
Methods:
Name | Description |
---|---|
model_name |
Returns the name of the model. |
prompt_formatter |
str) -> list[dict]: Formats the prompt into a list of messages. |
get_prompt_completion |
str) -> str: Generates completion for a given prompt. |
generate_completions |
TaskMatchGroup, prefer_concurrency: bool = True, n_workers: int = 4) -> TaskMatchGroup: Generates completions for a list of matches. |
Source code in parsbench/models/anthropic_interface.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 |
|
Bases: Model
A model interface for pre-trained transformer models.
Attributes:
Name | Type | Description |
---|---|---|
model |
PreTrainedModel
|
The pre-trained transformer model. |
tokenizer |
PreTrainedTokenizer
|
The tokenizer associated with the model. |
generation_config |
GenerationConfig
|
The generation configuration for text generation. |
instruction_prompt |
str
|
The default instruction prompt for the model. |
custom_prompt_formatter |
Callable[[str], str] | None
|
A custom prompt formatter function. |
Methods:
Name | Description |
---|---|
model_name |
Returns the base model prefix of the transformer model. |
prompt_formatter |
Formats a prompt by combining system instruction and user input. Could be overloaded. |
completion_formatter |
Method to format the model completion. Could be overloaded. |
get_prompt_completion |
Generates a completion for a given prompt using the model and tokenizer. |
Source code in parsbench/models/transformers_interface.py
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 |
|