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 (int | None)

  • title (str | None)

  • name (str | 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: int | None
title: str | None
name: str | 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[int, NoneType], required=False, default=None), 'name': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'title': FieldInfo(annotation=Union[str, 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
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

The text of the answer option. This should describe the option in a way that is clear to the participant.

Type:

str

ignored_for_scale

Indicates whether this answer option should be ignored when calculating scores on a scale. This can be useful for neutral options or non-applicable responses.

Type:

bool

weight

The numerical weight assigned to this answer option. This is typically used in scoring the test, where different options have different point values.

Type:

int

The default values are set to represent a common scenario in psychological testing. Adjust as necessary for specific test requirements.

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.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 (Dict[str, AnswerOption] | None)

  • attributes (Dict)

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

question

The text of the question presented to the participant.

Type:

str

reversed

A flag indicating whether the scoring for this question should be reversed. In some psychological tests, certain questions are scored in the opposite direction for certain scales.

Type:

bool

answer_options

A list of possible answer options that a participant can choose from in response to the question. This field is optional and can be None if the question does not have predefined answer options.

Type:

Optional[List[AnswerOption]]

attributes

Additional attributes related to the question, such as its dimension in a multi-dimensional test structure.

Type:

InstructionItemAttribute

The default values and structure are designed to be flexible and can be adjusted to suit different types of psychological tests.

question: str
reversed: bool
answer_options: Dict[str, AnswerOption] | None
attributes: Dict
answers: Dict[int, Dict[int, Dict[int, str]]] | None
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[Dict[str, AnswerOption], NoneType], required=False, default=None), 'answers': FieldInfo(annotation=Union[Dict[int, Dict[int, Dict[int, 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: Dict[str, AnswerOption] | None
instruction_items: List[InstructionItem] | None
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[Dict[str, AnswerOption], NoneType], required=False, default=None), '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

class rupsycho.models.profile.DemographicProfile(*, attributes, template, **extra_data)[source]

Bases: BaseModel

Parameters:
  • attributes (Dict[str, Any])

  • template (str)

  • extra_data (Any)

attributes: Dict[str, Any]
template: str
class Config[source]

Bases: object

Pydantic model configuration.

arbitrary_types_allowed = True
extra = 'allow'
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, '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=Dict[str, Any], required=True), 'template': 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.

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(*, name_or_path, revision=None, tokenizer_name_or_path=None, cache_dir=None, use_auth_token=False, device=-1, task='text-generation', parameters={}, prompt_template=None)[source]

Bases: BaseModel

Configuration for a local Hugging Face model.

Parameters:
  • name_or_path (str)

  • revision (str | None)

  • tokenizer_name_or_path (str | None)

  • cache_dir (str | None)

  • use_auth_token (bool | None)

  • device (int | None)

  • task (str | None)

  • parameters (Dict)

  • prompt_template (str | BaseModel | None)

name_or_path: str
revision: str | None
tokenizer_name_or_path: str | None
cache_dir: str | None
use_auth_token: bool | None
device: int | None
task: str | None
parameters: Dict
prompt_template: str | BaseModel | None
class Config[source]

Bases: object

Pydantic model configuration.

arbitrary_types_allowed = True
load_model()[source]

Loads and returns a Hugging Face model pipeline 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]] = {'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': FieldInfo(annotation=Union[int, NoneType], required=False, default=-1, description="The device to load the model onto ('cpu' or 'cuda')."), '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.'), 'use_auth_token': FieldInfo(annotation=Union[bool, NoneType], required=False, default=False, description='Whether to use the token generated when running `huggingface-cli login` for private models.')}

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, huggingfacehub_api_token, parameters={})[source]

Bases: BaseModel

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

Parameters:
  • type (str)

  • repo_id (str)

  • task (str)

  • huggingfacehub_api_token (str)

  • parameters (Dict)

type: str
repo_id: str
task: str
huggingfacehub_api_token: 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]] = {'huggingfacehub_api_token': FieldInfo(annotation=str, required=True, description='The API token for accessing Hugging Face endpoints.'), '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.