Data Models¶
The classes below validate the experiment configuration. Their attributes are the keys of the configuration, see the Configuration Reference for how to use them.
Questionnaire¶
rupsycho.models.questionnaire
¶
Questionnaire
¶
Represents a questionnaire used in a psychological test.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
The name of the questionnaire.
TYPE:
|
general_instruction |
General instructions provided to the participants.
TYPE:
|
demographic_profiles |
A list of demographic profiles for the participants. This field is optional.
TYPE:
|
default_answer_options |
A dictionary of default answer options for the questionnaire. The keys represent unique identifiers for each option. This field is optional.
TYPE:
|
instruction_items |
A list of instruction items (questions) included in the questionnaire. This field is optional.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
get_number_of_questions |
Returns the number of questions in the questionnaire. |
attributes
¶
attributes: dict = Field(default_factory=dict, description='Additional attributes related to the question, such as its dimension in a multi-dimensional test structure.')
ensure_default_answer_options_is_proper_model
¶
Convert a dictionary to an AnswerOptions model if necessary.
get_number_of_questions
¶
Returns the number of questions in the questionnaire.
InstructionItem
¶
Represents a single question item in a psychological test, along with its answer options and specific attributes.
attributes
¶
attributes: dict = Field(default_factory=dict, description='Additional attributes related to the question, such as its dimension in a multi-dimensional test structure.')
answers
¶
answers: dict[Any, dict[Any, dict[Any, Any]]] | None = Field(default_factory=dict, description='A nested dictionary storing answers indexed by model, profile, and run.')
ensure_answer_options_is_proper_model
¶
Convert a dictionary to an AnswerOptions model if necessary.
update_answer
¶
Store the answer in the appropriate location.
get_answer
¶
Return the stored answer.
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If there is no answer for this model, persona and seed. Reading never modifies the stored answers. |
get_answer_options_as_list
¶
Return the list of answer options' text.
AnswerOptions
¶
Represents a collection of answer options in a psychological test along with a delimiter for joining them.
options
¶
options: dict[str, AnswerOption] = Field(default_factory=dict, description='A dictionary of answer options.')
delimiter
¶
delimiter: str = Field(default=', ', description="The delimiter used to join the answer options when displayed as a string. Default is ', '. Insert a line break '\\n' for a new line.")
prepend_delimiter
¶
prepend_delimiter: bool = Field(default=False, description='If True, the delimiter will be added before the first answer option as well.')
AnswerOption
¶
DemographicProfile
¶
Represents the demographic profile of a participant in a psychological test. This includes attributes like age, title, name, and a template for formatting purposes.
attributes
¶
attributes: DemographicAttributes = Field(..., description='Attributes containing demographic information such as age, title, and name.')
template
¶
template: str = Field(default='{title} {name} is {age} years old.', description="A template string to format the demographic information. Use placeholders for attributes (e.g., '{title}', '{name}', '{age}').")
DemographicAttributes
¶
Represents the demographic attributes of a participant in a psychological test. This model includes default fields such as 'age', 'title', and 'name', but it is extendable to include additional demographic details as needed.
| ATTRIBUTE | DESCRIPTION |
|---|---|
age |
The age of the participant. Default is None.
TYPE:
|
title |
The title of the participant (e.g., Mr, Ms, Dr). Default is None.
TYPE:
|
name |
The name of the participant. Default is None.
TYPE:
|
The model is flexible to accept additional fields beyond the ones specified.
Parameters¶
rupsycho.models.parameters.ExperimentParameters
¶
Parameters of an experiment.
| ATTRIBUTE | DESCRIPTION |
|---|---|
seeds |
Seeds of the repetitions. Every model is asked every question once per seed.
Integers (
TYPE:
|
lazy_load_models |
Load each model only when the run reaches it (default). With
TYPE:
|
Additional keys are kept as they are.
seeds
¶
seeds: Seeds = Field(default_factory=lambda: [str(randint(0, 999999))], description='A list of seeds for random number generation in the experiment.')
lazy_load_models
¶
lazy_load_models: bool = Field(default=True, description='If True, models will be loaded only when they are needed during the experiment.')
Prompt templates¶
rupsycho.models.prompt
¶
NormalPromptTemplateConfig
¶
Configuration for a normal LangChain PromptTemplate. This model defines the template string with placeholders.
template
¶
template: str = Field(..., description="The template string with placeholders (e.g., 'Tell me a {adjective} joke about {content}').")
ChatMessageConfig
¶
ChatPromptTemplateConfig
¶
Configuration for a LangChain ChatPromptTemplate. This model defines the sequence of messages, each associated with a role.
LangchainPromptTemplateConfig
¶
Configuration for a LangChain ChatPromptTemplate. This model defines the sequence of messages, each associated with a role.
Model configurations¶
rupsycho.models.model
¶
Data model: language model configurations.
Each configuration describes how to build one LangChain model and exposes load_model().
Provider SDKs are imported lazily inside load_model so that configurations can be
created, validated and serialised without the corresponding extra installed. Loading a model
whose extra is missing raises an ImportError naming the extra to install.
LangChainModelConfig
¶
Configuration for a serialized LangChain model or any other runnable configuration.
| ATTRIBUTE | DESCRIPTION |
|---|---|
definition |
The serialized model as produced by
TYPE:
|
parameters |
Generation parameters (informational for serialized models).
TYPE:
|
prompt_template |
Optional prompt template of the model.
TYPE:
|
definition
¶
definition: dict[str, Any] = Field(..., description='A dictionary containing the serialized LangChain model or other runnable configuration.')
prompt_template
¶
prompt_template: LangchainPromptTemplateConfig | None = Field(None, description='The prompt template used by the model')
load_model
¶
Deserialize and return the LangChain model.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
The deserialized LangChain model. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the definition cannot be deserialized. |
LocalHuggingFaceModelConfig
¶
Configuration for a Hugging Face model that runs in this process.
Requires the huggingface extra. Pin revision to a commit hash to make the exact
model version part of your experiment configuration.
Example
name_or_path
¶
name_or_path: str = Field(..., description='The path to the local directory or the name of the Hugging Face model.')
revision
¶
revision: str | None = Field(None, description='The specific model version to use (e.g., a branch name, tag, or commit hash).')
tokenizer_name_or_path
¶
tokenizer_name_or_path: str | None = Field(None, description='The name or path to the tokenizer to use. Defaults to `name_or_path` if not specified.')
cache_dir
¶
cache_dir: str | None = Field(None, description='Path to the directory where the downloaded model and tokenizer files will be cached.')
huggingfacehub_api_token
¶
huggingfacehub_api_token: Secret = Field(None, description='The API token for accessing gated or private Hugging Face models.')
device_map
¶
device_map: Any | None = Field('auto', description="The device map to load the model onto ('cpu', 'cuda', or custom device map). See https://huggingface.co/docs/accelerate/concept_guides/big_model_inference#designing-a-device-map")
task
¶
task: str | None = Field('text-generation', description="The type of pipeline to create (e.g., 'text-generation').")
parameters
¶
parameters: dict = Field({}, description='The parameters for text generation (e.g., max_new_tokens, temperature).')
prompt_template
¶
prompt_template: str | BaseModel | None = Field(None, description='The prompt template used by the model, if applicable.')
bitsandbytes_config
¶
bitsandbytes_config: dict | None = Field(None, description='Optional dictionary for bitsandbytes quantization configuration.')
load_model
¶
Load the model, wrap it into a Transformers pipeline and return a chat model.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
A |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the |
ValueError
|
If the model cannot be loaded. |
RemoteHuggingFaceModelConfig
¶
Configuration for a model served by a Hugging Face Inference Endpoint.
Requires the huggingface extra and a Hugging Face token in the environment
(HUGGINGFACEHUB_API_TOKEN).
repo_id
¶
repo_id: str = Field(..., description="The repository ID of the Hugging Face model (e.g., 'HuggingFaceH4/zephyr-7b-beta').")
task
¶
task: str = Field(..., description="The task for the Hugging Face pipeline (e.g., 'text-generation').")
parameters
¶
parameters: dict = Field({}, description='The parameters for text generation (e.g., max_new_tokens, temperature).')
load_model
¶
Create the endpoint client and return it as a chat model.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
A |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the |
ValueError
|
If the endpoint cannot be created. |
OllamaModelConfig
¶
Configuration for a model served by a local or remote Ollama server.
Requires the ollama extra.
model
¶
prompt_template
¶
prompt_template: ChatPromptTemplateConfig | None = Field(None, description='The prompt template used by the model')
load_model
¶
Create the Ollama client.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
An |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the |
ValueError
|
If the client cannot be created. |
OpenAIModelConfig
¶
Configuration for an OpenAI (or OpenAI-compatible) chat model.
Requires the openai extra. The API key is read from api_key or, if unset, from the
OPENAI_API_KEY environment variable. Prefer the environment variable so that keys never
end up in shared configuration files.
name_or_path
¶
base_url
¶
organization
¶
organization: str | None = Field(None, description='The organization ID associated with the OpenAI API key.')
prompt_template
¶
prompt_template: ChatPromptTemplateConfig | None = Field(None, description='The prompt template used by the model')
load_model
¶
Create the OpenAI chat model.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
A |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the |
ValueError
|
If the client cannot be created. |
GoogleModelConfig
¶
Configuration for a Google Gemini chat model.
Requires the google extra. Gemini models cannot be seeded; see
rupsycho.seeding.
name_or_path
¶
name_or_path: str = Field(..., description="The identifier for the Google model (e.g., 'gemini-2.0-flash').")
prompt_template
¶
prompt_template: ChatPromptTemplateConfig | None = Field(None, description='The prompt template used by the model')
load_model
¶
Create the Google chat model.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
A |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the |
ValueError
|
If the client cannot be created. |
DeepSeekModelConfig
¶
Configuration for a DeepSeek chat model.
Requires the deepseek extra. The API key is read from api_key or, if unset, from
the DEEPSEEK_API_KEY environment variable.
name_or_path
¶
name_or_path: str = Field(..., description="The identifier for the DeepSeek model (e.g. 'deepseek-chat').")
prompt_template
¶
prompt_template: ChatPromptTemplateConfig | None = Field(None, description='The prompt template used by the model')
load_model
¶
Create the DeepSeek chat model.
| RETURNS | DESCRIPTION |
|---|---|
Any
|
A |
| RAISES | DESCRIPTION |
|---|---|
ImportError
|
If the |
ValueError
|
If the client cannot be created. |