Data Models

Questionnaire

class rupsycho.models.questionnaire.DemographicAttributes(*, age=None, title=None, name=None, **extra_data)[source]

Bases: BaseModel

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.

Parameters:
  • age (Any | None)

  • title (Any | None)

  • name (Any | None)

  • extra_data (Any)

age

The age of the participant. Default is None.

Type:

Optional[int]

title

The title of the participant (e.g., Mr, Ms, Dr). Default is None.

Type:

Optional[str]

name

The name of the participant. Default is None.

Type:

Optional[str]

The model is flexible to accept additional fields beyond the ones specified.

age: Any | None
title: Any | None
name: Any | None
class Config[source]

Bases: object

extra = 'allow'
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'age': FieldInfo(annotation=Union[Any, NoneType], required=False, default=None), 'name': FieldInfo(annotation=Union[Any, NoneType], required=False, default=None), 'title': FieldInfo(annotation=Union[Any, NoneType], required=False, default=None)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.questionnaire.DemographicProfile(*, attributes, template='{title} {name} is {age} years old.', **extra_data)[source]

Bases: BaseModel

Represents the demographic profile of a participant in a psychological test. This includes attributes like age, title, name, and a template for formatting purposes.

Parameters:
attributes: DemographicAttributes
template: str
get_profile_desc()[source]

Returns a string representation of the profile.

class Config[source]

Bases: object

extra = 'allow'
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'extra': 'allow'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'attributes': FieldInfo(annotation=DemographicAttributes, required=True, description='Attributes containing demographic information such as age, title, and name.'), 'template': FieldInfo(annotation=str, required=False, 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}').")}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.questionnaire.AnswerOption(*, text='Choose an option', ignored_for_scale=False, weight=0)[source]

Bases: BaseModel

Represents an answer option in a psychological test.

Parameters:
  • text (str)

  • ignored_for_scale (bool)

  • weight (int)

text: str
ignored_for_scale: bool
weight: int
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'ignored_for_scale': FieldInfo(annotation=bool, required=False, default=False), 'text': FieldInfo(annotation=str, required=False, default='Choose an option'), 'weight': FieldInfo(annotation=int, required=False, default=0)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.questionnaire.AnswerOptions(*, options=None, delimiter=', ', prepend_delimiter=False)[source]

Bases: BaseModel

Represents a collection of answer options in a psychological test along with a delimiter for joining them.

Parameters:
  • options (Dict[str, AnswerOption])

  • delimiter (str)

  • prepend_delimiter (bool)

options: Dict[str, AnswerOption]
delimiter: str
prepend_delimiter: bool
join_options()[source]

Join the answer options’ text using the specified delimiter.

Return type:

str

get_options_as_list()[source]

Return the list of answer options’ text.

Return type:

List[str]

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'delimiter': FieldInfo(annotation=str, required=False, 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."), 'options': FieldInfo(annotation=Dict[str, AnswerOption], required=False, default_factory=dict, description='A dictionary of answer options.'), 'prepend_delimiter': FieldInfo(annotation=bool, required=False, default=False, description='If True, the delimiter will be added before the first answer option as well.')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.questionnaire.InstructionItem(*, question='Enter question text here', reversed=False, answer_options=None, attributes=None, answers=None)[source]

Bases: BaseModel

Represents a single question item in a psychological test, along with its answer options and specific attributes.

Parameters:
  • question (str)

  • reversed (bool)

  • answer_options (AnswerOptions | None)

  • attributes (Dict)

  • answers (Dict[Any, Dict[Any, Dict[Any, str]]] | None)

question: str
reversed: bool
answer_options: AnswerOptions | None
attributes: Dict
answers: Dict[Any, Dict[Any, Dict[Any, str]]] | None
classmethod ensure_answer_options_is_proper_model(v)[source]

Convert a dictionary to an AnswerOptions model if necessary.

update_answer(model_key, profile_key, run_idx, answer)[source]

Store the answer in the appropriate location.

Parameters:
  • model_key (str)

  • profile_key (str)

  • run_idx (int)

  • answer (Any)

Return type:

None

get_answer(model_key, profile_key, run_idx)[source]

Retrieve the answer from the appropriate location.

Parameters:
  • model_key (str)

  • profile_key (str)

  • run_idx (int)

Return type:

Any

get_all_answers()[source]

Retrieve all answers.

Return type:

Dict[str, Dict[str, Dict[int, Any]]]

get_answer_options_as_list()[source]

Return the list of answer options’ text.

Return type:

List[str]

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'answer_options': FieldInfo(annotation=Union[AnswerOptions, NoneType], required=False, default=None, validate_default=True), 'answers': FieldInfo(annotation=Union[Dict[Any, Dict[Any, Dict[Any, str]]], NoneType], required=False, default_factory=<lambda>, description='A nested dictionary storing answers indexed by model, profile, and run.'), 'attributes': FieldInfo(annotation=Dict, required=False, default_factory=dict, description='Additional attributes related to the question, such as its dimension in a multi-dimensional test structure.'), 'question': FieldInfo(annotation=str, required=False, default='Enter question text here'), 'reversed': FieldInfo(annotation=bool, required=False, default=False)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.questionnaire.Questionnaire(*, name, general_instruction, demographic_profiles=None, attributes=None, default_answer_options=None, instruction_items=None)[source]

Bases: BaseModel

Represents a questionnaire used in a psychological test.

Parameters:
name

The name of the questionnaire.

Type:

str

general_instruction

General instructions provided to the participants.

Type:

str

demographic_profiles

A list of demographic profiles for the participants. This field is optional.

Type:

Optional[List[DemographicProfile]]

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:

Optional[Dict[str, AnswerOption]]

instruction_items

A list of instruction items (questions) included in the questionnaire. This field is optional.

Type:

Optional[List[InstructionItem]]

get_number_of_questions()[source]

Returns the number of questions in the questionnaire.

Return type:

int

name: str
general_instruction: str
demographic_profiles: List[DemographicProfile] | None
attributes: Dict
default_answer_options: AnswerOptions | None
instruction_items: List[InstructionItem] | None
classmethod ensure_default_answer_options_is_proper_model(v)[source]

Convert a dictionary to an AnswerOptions model if necessary.

get_number_of_questions()[source]

Returns the number of questions in the questionnaire.

Return type:

int

print_questionnaire()[source]

Prints the questionnaire in a human-readable format.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'attributes': FieldInfo(annotation=Dict, required=False, default_factory=dict, description='Additional attributes related to the question, such as its dimension in a multi-dimensional test structure.'), 'default_answer_options': FieldInfo(annotation=Union[AnswerOptions, NoneType], required=False, default=None, validate_default=True), 'demographic_profiles': FieldInfo(annotation=Union[List[DemographicProfile], NoneType], required=False, default=None), 'general_instruction': FieldInfo(annotation=str, required=True), 'instruction_items': FieldInfo(annotation=Union[List[InstructionItem], NoneType], required=False, default=None), 'name': FieldInfo(annotation=str, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

Instruction

class rupsycho.models.instruction.AnswerOption(*, text, weight, reversed, ignored_for_scale=False)[source]

Bases: BaseModel

Parameters:
  • text (str)

  • weight (int)

  • reversed (bool)

  • ignored_for_scale (bool)

text: str
weight: int
reversed: bool
ignored_for_scale: bool
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'ignored_for_scale': FieldInfo(annotation=bool, required=False, default=False), 'reversed': FieldInfo(annotation=bool, required=True), 'text': FieldInfo(annotation=str, required=True), 'weight': FieldInfo(annotation=int, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.instruction.InstructionItem(*, question, answer_options)[source]

Bases: BaseModel

Parameters:
question: str
answer_options: Dict[str, AnswerOption]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'answer_options': FieldInfo(annotation=Dict[str, AnswerOption], required=True), 'question': FieldInfo(annotation=str, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

Profile

Model

class rupsycho.models.model.LangChainModelConfig(*, type='langchain', definition, parameters={}, prompt_template=None)[source]

Bases: BaseModel

Configuration for a serialized LangChain model or any other runnable configuration.

Parameters:
  • type (str)

  • definition (Dict[str, Any])

  • parameters (Dict)

  • prompt_template (LangchainPromptTemplateConfig)

type: str
definition: Dict[str, Any]
parameters: Dict
prompt_template: LangchainPromptTemplateConfig
load_model()[source]

Loads and returns a LangChain model based on the provided serialized configuration.

Parameters:

config (LangChainModelConfig) – The configuration object containing the serialized LangChain model definition.

Returns:

The deserialized LangChain model ready for use, or None if loading fails.

Return type:

Any

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'definition': FieldInfo(annotation=Dict[str, Any], required=True, description='A dictionary containing the serialized LangChain model or other runnable configuration.'), 'parameters': FieldInfo(annotation=Dict, required=False, default={}, description='The parameters for text generation'), 'prompt_template': FieldInfo(annotation=LangchainPromptTemplateConfig, required=False, default=None, description='The prompt template used by the model'), 'type': FieldInfo(annotation=str, required=False, default='langchain', description='The type of the model configuration.')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.model.LocalHuggingFaceModelConfig(*, type='local_huggingface', name_or_path, revision=None, tokenizer_name_or_path=None, cache_dir=None, huggingfacehub_api_token=None, device_map='auto', task='text-generation', parameters={}, prompt_template=None, bitsandbytes_config=None)[source]

Bases: BaseModel

Configuration for a local Hugging Face model.

Parameters:
  • type (str)

  • name_or_path (str)

  • revision (str | None)

  • tokenizer_name_or_path (str | None)

  • cache_dir (str | None)

  • huggingfacehub_api_token (str | None)

  • device_map (Any | None)

  • task (str | None)

  • parameters (Dict)

  • prompt_template (str | BaseModel | None)

  • bitsandbytes_config (Dict | None)

type: str
name_or_path: str
revision: str | None
tokenizer_name_or_path: str | None
cache_dir: str | None
huggingfacehub_api_token: str | None
device_map: Any | None
task: str | None
parameters: Dict
prompt_template: str | BaseModel | None
bitsandbytes_config: Dict | None
class Config[source]

Bases: object

Pydantic model configuration.

arbitrary_types_allowed = True
load_model()[source]

Loads and returns a quantized Hugging Face model pipeline wrapped in a LangChain HuggingFacePipeline.

Parameters:

None

Returns:

The LangChain HuggingFacePipeline ready for integration into LangChain workflows.

Return type:

HuggingFacePipeline

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'bitsandbytes_config': FieldInfo(annotation=Union[Dict, NoneType], required=False, default=None, description='Optional dictionary for bitsandbytes quantization configuration.'), 'cache_dir': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description='Path to the directory where the downloaded model and tokenizer files will be cached.'), 'device_map': FieldInfo(annotation=Union[Any, NoneType], required=False, default='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"), 'huggingfacehub_api_token': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description='The API token for accessing Hugging Face endpoints.'), 'name_or_path': FieldInfo(annotation=str, required=True, description='The path to the local directory or the name of the Hugging Face model.'), 'parameters': FieldInfo(annotation=Dict, required=False, default={}, description='The parameters for text generation (e.g., max_length, temperature, etc.).'), 'prompt_template': FieldInfo(annotation=Union[str, BaseModel, NoneType], required=False, default=None, description='The prompt template used by the model, if applicable.'), 'revision': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description='The specific model version to use (e.g., a branch name, tag, or commit hash).'), 'task': FieldInfo(annotation=Union[str, NoneType], required=False, default='text-generation', description="The type of pipeline to create (e.g., 'text-generation', 'text-classification', etc.)."), 'tokenizer_name_or_path': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description='The name or path to the tokenizer to use. Defaults to `model_name_or_path` if not specified.'), 'type': FieldInfo(annotation=str, required=False, default='local_huggingface', description='The type of the model configuration.')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.model.RemoteHuggingFaceModelConfig(*, type='remote_huggingface', repo_id, task, parameters={})[source]

Bases: BaseModel

Configuration for a remote Hugging Face model using the Inference Endpoint API.

Parameters:
  • type (str)

  • repo_id (str)

  • task (str)

  • parameters (Dict)

type: str
repo_id: str
task: str
parameters: Dict
class Config[source]

Bases: object

Pydantic model configuration.

arbitrary_types_allowed = True
load_model()[source]

Loads and returns a Hugging Face model pipeline from a remote inference endpoint, wrapped in a LangChain HuggingFacePipeline.

Returns:

The LangChain HuggingFacePipeline ready for integration into LangChain workflows.

Return type:

HuggingFacePipeline

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'parameters': FieldInfo(annotation=Dict, required=False, default={}, description='The parameters for text generation (e.g., max_length, temperature, etc.).'), 'repo_id': FieldInfo(annotation=str, required=True, description="The repository ID of the Hugging Face model (e.g., 'HuggingFaceH4/zephyr-7b-beta')."), 'task': FieldInfo(annotation=str, required=True, description="The task for the Hugging Face pipeline (e.g., 'text-generation', 'text-classification')."), 'type': FieldInfo(annotation=str, required=False, default='remote_huggingface', description='The type of the model configuration.')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.model.OllamaModelConfig(*, type='ollama', model, base_url='http://localhost:11434', parameters={}, prompt_template=None)[source]

Bases: BaseModel

Configuration for loading an Ollama model. This class holds all the necessary information for configuring and loading an OllamaLLM model.

Parameters:
  • type (str)

  • model (str)

  • base_url (str)

  • parameters (Dict)

  • prompt_template (ChatPromptTemplateConfig)

type: str
model: str
base_url: str

Base url the model is hosted under.

parameters: Dict
prompt_template: ChatPromptTemplateConfig
class Config[source]

Bases: object

Pydantic model configuration.

arbitrary_types_allowed = True
load_model()[source]

Loads and returns an Ollama model based on the provided configuration.

Returns:

The instantiated Ollama model ready for use.

Return type:

OllamaLLM

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'base_url': FieldInfo(annotation=str, required=False, default='http://localhost:11434'), 'model': FieldInfo(annotation=str, required=True, description="The identifier for the Ollama model (e.g., 'gemma2:2b')."), 'parameters': FieldInfo(annotation=Dict, required=False, default={}, description='The parameters for text generation'), 'prompt_template': FieldInfo(annotation=ChatPromptTemplateConfig, required=False, default=None, description='The prompt template used by the model'), 'type': FieldInfo(annotation=str, required=False, default='ollama', description='The type of the model configuration.')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

class rupsycho.models.model.OpenAIModelConfig(*, type='openai', model, api_key=None, base_url=None, organization=None, parameters={}, prompt_template=None)[source]

Bases: BaseModel

Configuration for an OpenAI model.

Parameters:
  • type (str)

  • model (str)

  • api_key (str | None)

  • base_url (str | None)

  • organization (str | None)

  • parameters (Dict)

  • prompt_template (ChatPromptTemplateConfig)

type: str
model: str
api_key: str | None
base_url: str | None
organization: str | None
parameters: Dict
prompt_template: ChatPromptTemplateConfig
class Config[source]

Bases: object

arbitrary_types_allowed = True
load_model()[source]

Loads and returns an OpenAI model based on the provided configuration.

Parameters:

config (OpenAIModelConfig) – The configuration object containing the details for loading the OpenAI model.

Returns:

The instantiated OpenAI model ready for use.

Return type:

ChatOpenAI

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'api_key': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description="The API key for accessing OpenAI's models."), 'base_url': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description='The base URL for the OpenAI API endpoint.'), 'model': FieldInfo(annotation=str, required=True, description="The identifier for the OpenAI model (e.g., 'gpt-4')."), 'organization': FieldInfo(annotation=Union[str, NoneType], required=False, default=None, description='The organization ID associated with the OpenAI API key.'), 'parameters': FieldInfo(annotation=Dict, required=False, default={}, description='The parameters for text generation'), 'prompt_template': FieldInfo(annotation=ChatPromptTemplateConfig, required=False, default=None, description='The prompt template used by the model'), 'type': FieldInfo(annotation=str, required=False, default='openai', description='The type of the model configuration.')}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.