camel.personas package#

Submodules#

camel.personas.persona module#

class camel.personas.persona.Persona(*, name: str | None = None, description: str | None = None, text_to_persona_prompt: TextPrompt | str = None, persona_to_persona_prompt: TextPrompt | str = None)[source]#

Bases: BaseModel

A persona is a character in the society.

name#

Name of the persona.

Type:

Optional[str]

description#

Description of the persona.

Type:

Optional[str]

text_to_persona_prompt#

The prompt to convert text into a persona.

Type:

Union[TextPrompt, str]

persona_to_persona_prompt#

Persona-to-Persona interaction prompt.

Type:

Union[TextPrompt, str]

id#

The unique identifier for the persona, automatically generated.

Type:

uuid.UUID

_id#

Internal unique identifier for the persona, generated lazily using uuid.uuid4.

Type:

uuid.UUID

model_config#

Configuration for the Pydantic model. Allows arbitrary types and includes custom JSON schema settings.

Type:

ClassVar[ConfigDict]

description: str | None#
dict(*args, **kwargs)[source]#
property id: UUID#
json(*args, **kwargs)[source]#
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, 'json_schema_extra': {'properties': {'persona_to_persona_prompt': {'type': 'string'}, 'text_to_persona_prompt': {'type': 'string'}}}}#

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

model_fields: ClassVar[Dict[str, FieldInfo]] = {'description': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'name': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'persona_to_persona_prompt': FieldInfo(annotation=Union[TextPrompt, str], required=False, default_factory=<lambda>, description='Persona to Persona Prompt'), 'text_to_persona_prompt': FieldInfo(annotation=Union[TextPrompt, str], required=False, default_factory=<lambda>, description='Text to Persona Prompt')}#

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

This replaces Model.__fields__ from Pydantic V1.

classmethod model_json_schema()[source]#

Generates a JSON schema for a model class.

Parameters:
  • by_alias – Whether to use attribute aliases or not.

  • ref_template – The reference template.

  • schema_generator – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications

  • mode – The mode in which to generate the schema.

Returns:

The JSON schema for the given model class.

model_post_init(context: Any, /) None#

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

name: str | None#
persona_to_persona_prompt: TextPrompt | str#
text_to_persona_prompt: TextPrompt | str#

camel.personas.persona_hub module#

class camel.personas.persona_hub.PersonaHub(model: BaseModelBackend | None = None)[source]#

Bases: object

The PersonaHub adapted from “Scaling Synthetic Data Creation with 1, 000,000,000 Personas”.

PersonaHub proposes a novel persona-driven data synthesis methodology that leverages various perspectives within a large language model (LLM) to create diverse synthetic data. By showcasing PersonaHub’s use cases in synthesizing high-quality mathematical and logical reasoning problems, instructions (i.e., user prompts), knowledge-rich texts, game NPCs and tools (functions) at scale, the authors demonstrate persona-driven data synthesis is versatile, scalable, flexible, and easy to use, potentially driving a paradigm shift in synthetic data creation and applications in practice, which may have a profound impact on LLM research and development. Please refer to the paper for more details: https://arxiv.org/pdf/2406.20094.

Parameters:

model (BaseModelBackend, optional) – The model to use for persona generation and manipulation. (default: None)

deduplicate(embedding_model: BaseEmbedding | None = None, similarity_threshold: float = 0.85) None[source]#

Remove similar personas from the group.

Parameters:
  • embedding_model (BaseEmbedding) – The embedding model for similarity compairsion. (default is None).

  • similarity_threshold (float) – The similarity threshold for deduplication (default is 0.85).

get_all_personas() List[Persona][source]#

Return a list of all personas.

persona_to_persona(persona: Persona) Dict[UUID, Persona][source]#

Derives additional personas based on interpersonal relationships from this persona.

Parameters:

persona (Persona) – The persona from which to derive related personas.

Returns:

A dictionary of related personas.

Return type:

Dict[uuid.UUID, Persona]

text_to_persona(text: str, action: Literal['read', 'write', 'like', 'dislike'] = 'read') Persona[source]#

Infers a specific persona who is likely to [read|write|like|dislike |…] the given text.

Parameters:
  • text (str) – The input text for which to infer a persona.

  • action (str) – The action associated with the persona (default is “read”).

Returns:

The inferred persona.

Return type:

Persona

class camel.personas.persona_hub.PersonaResponse(*, persona_name: str, persona_description: str)[source]#

Bases: BaseModel

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]] = {'persona_description': FieldInfo(annotation=str, required=True, description='The description of the persona.'), 'persona_name': FieldInfo(annotation=str, required=True, description='The name of the persona')}#

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

This replaces Model.__fields__ from Pydantic V1.

persona_description: str#
persona_name: str#

Module contents#

class camel.personas.Persona(*, name: str | None = None, description: str | None = None, text_to_persona_prompt: TextPrompt | str = None, persona_to_persona_prompt: TextPrompt | str = None)[source]#

Bases: BaseModel

A persona is a character in the society.

name#

Name of the persona.

Type:

Optional[str]

description#

Description of the persona.

Type:

Optional[str]

text_to_persona_prompt#

The prompt to convert text into a persona.

Type:

Union[TextPrompt, str]

persona_to_persona_prompt#

Persona-to-Persona interaction prompt.

Type:

Union[TextPrompt, str]

id#

The unique identifier for the persona, automatically generated.

Type:

uuid.UUID

_id#

Internal unique identifier for the persona, generated lazily using uuid.uuid4.

Type:

uuid.UUID

model_config#

Configuration for the Pydantic model. Allows arbitrary types and includes custom JSON schema settings.

Type:

ClassVar[ConfigDict]

description: str | None#
dict(*args, **kwargs)[source]#
property id: UUID#
json(*args, **kwargs)[source]#
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, 'json_schema_extra': {'properties': {'persona_to_persona_prompt': {'type': 'string'}, 'text_to_persona_prompt': {'type': 'string'}}}}#

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

model_fields: ClassVar[Dict[str, FieldInfo]] = {'description': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'name': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'persona_to_persona_prompt': FieldInfo(annotation=Union[TextPrompt, str], required=False, default_factory=<lambda>, description='Persona to Persona Prompt'), 'text_to_persona_prompt': FieldInfo(annotation=Union[TextPrompt, str], required=False, default_factory=<lambda>, description='Text to Persona Prompt')}#

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

This replaces Model.__fields__ from Pydantic V1.

classmethod model_json_schema()[source]#

Generates a JSON schema for a model class.

Parameters:
  • by_alias – Whether to use attribute aliases or not.

  • ref_template – The reference template.

  • schema_generator – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications

  • mode – The mode in which to generate the schema.

Returns:

The JSON schema for the given model class.

model_post_init(context: Any, /) None#

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

name: str | None#
persona_to_persona_prompt: TextPrompt | str#
text_to_persona_prompt: TextPrompt | str#
class camel.personas.PersonaHub(model: BaseModelBackend | None = None)[source]#

Bases: object

The PersonaHub adapted from “Scaling Synthetic Data Creation with 1, 000,000,000 Personas”.

PersonaHub proposes a novel persona-driven data synthesis methodology that leverages various perspectives within a large language model (LLM) to create diverse synthetic data. By showcasing PersonaHub’s use cases in synthesizing high-quality mathematical and logical reasoning problems, instructions (i.e., user prompts), knowledge-rich texts, game NPCs and tools (functions) at scale, the authors demonstrate persona-driven data synthesis is versatile, scalable, flexible, and easy to use, potentially driving a paradigm shift in synthetic data creation and applications in practice, which may have a profound impact on LLM research and development. Please refer to the paper for more details: https://arxiv.org/pdf/2406.20094.

Parameters:

model (BaseModelBackend, optional) – The model to use for persona generation and manipulation. (default: None)

deduplicate(embedding_model: BaseEmbedding | None = None, similarity_threshold: float = 0.85) None[source]#

Remove similar personas from the group.

Parameters:
  • embedding_model (BaseEmbedding) – The embedding model for similarity compairsion. (default is None).

  • similarity_threshold (float) – The similarity threshold for deduplication (default is 0.85).

get_all_personas() List[Persona][source]#

Return a list of all personas.

persona_to_persona(persona: Persona) Dict[UUID, Persona][source]#

Derives additional personas based on interpersonal relationships from this persona.

Parameters:

persona (Persona) – The persona from which to derive related personas.

Returns:

A dictionary of related personas.

Return type:

Dict[uuid.UUID, Persona]

text_to_persona(text: str, action: Literal['read', 'write', 'like', 'dislike'] = 'read') Persona[source]#

Infers a specific persona who is likely to [read|write|like|dislike |…] the given text.

Parameters:
  • text (str) – The input text for which to infer a persona.

  • action (str) – The action associated with the persona (default is “read”).

Returns:

The inferred persona.

Return type:

Persona