> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.datasets.self instruct generator

<a id="camel.datasets.self_instruct_generator" />

<a id="camel.datasets.self_instruct_generator.SelfInstructGenerator" />

## SelfInstructGenerator

```python theme={"system"}
class SelfInstructGenerator(BaseGenerator):
```

A generator for creating synthetic datapoints using self-instruct.

It utilizes both a human-provided dataset (seed\_dataset) and generated
machine instructions (machine\_instructions) to produce new, synthetic
datapoints that include a question, a computed rationale (code), and a
final answer (from a verifier).

<a id="camel.datasets.self_instruct_generator.SelfInstructGenerator.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    seed_dataset: StaticDataset,
    verifier: BaseVerifier,
    instruction_agent: Optional[ChatAgent] = None,
    rationale_agent: Optional[ChatAgent] = None,
    seed: int = 42,
    **kwargs
):
```

Initialize the self-instruct generator.

**Parameters:**

* **seed\_dataset** (StaticDataset): Dataset containing seed instructions.
* **verifier** (BaseVerifier): Verifier instance to validate generated solutions.
* **instruction\_agent** (Optional\[ChatAgent]): Agent for generating instructions. If not provided, a default agent will be created.
* **rationale\_agent** (Optional\[ChatAgent]): Agent for generating rationales. If not provided, a default agent will be created.
* **seed** (int): Random seed for reproducibility. (default: :obj:`42`) \*\*kwargs: Additional keyword arguments passed to the BaseGenerator. (default: 42)

<a id="camel.datasets.self_instruct_generator.SelfInstructGenerator.default_instruction_agent" />

### default\_instruction\_agent

```python theme={"system"}
def default_instruction_agent(self):
```

**Returns:**

ChatAgent: An agent with the default instruction prompt.

<a id="camel.datasets.self_instruct_generator.SelfInstructGenerator.default_rationale_agent" />

### default\_rationale\_agent

```python theme={"system"}
def default_rationale_agent(self):
```

**Returns:**

ChatAgent: An agent with the rationale prompt

<a id="camel.datasets.self_instruct_generator.SelfInstructGenerator.format_support_block" />

### format\_support\_block

```python theme={"system"}
def format_support_block(dp: DataPoint):
```

Format a DataPoint into a few-shot example block.

**Parameters:**

* **dp** (DataPoint): A data point.

**Returns:**

str: A formatted string containing the question and its
corresponding code block in Markdown-style Python format.

<a id="camel.datasets.self_instruct_generator.SelfInstructGenerator.generate_new_instruction" />

### generate\_new\_instruction

```python theme={"system"}
def generate_new_instruction(
    self,
    agent: ChatAgent,
    support_human_dps: list[DataPoint],
    support_machine_dps: list[DataPoint]
):
```

Generate a new instruction using self-instruct prompting.

**Parameters:**

* **agent** (ChatAgent): The agent to use for generating the instruction.
* **support\_human\_dps** (list\[DataPoint]): List of human examples to sample.
* **support\_machine\_dps** (list\[DataPoint]): List of machine examples to sample.

**Returns:**

str: The newly generated question.

<a id="camel.datasets.self_instruct_generator.SelfInstructGenerator.generate_rationale" />

### generate\_rationale

```python theme={"system"}
def generate_rationale(
    self,
    question: str,
    agent: Optional[ChatAgent] = None,
    support_human_dps: Optional[list[DataPoint]] = None
):
```

Generate rationale code (solution) for the given question.

**Parameters:**

* **question** (str): The question to be solved.
* **agent** (Optional\[ChatAgent]): The agent to use for generating the rationale. If None is provided, the default rationale agent will be used. (default: :obj:`None`)
* **support\_human\_dps** (Optional\[list\[DataPoint]]): List of human examples to sample. (default: :obj:`None`)

**Returns:**

str: The generated code solution as a string.

<a id="camel.datasets.self_instruct_generator.QuestionSchema" />

## QuestionSchema

```python theme={"system"}
class QuestionSchema(BaseModel):
```

Schema for the generated question.

**Parameters:**

* **question** (str): The question generated by the model.

<a id="camel.datasets.self_instruct_generator.RationaleSchema" />

## RationaleSchema

```python theme={"system"}
class RationaleSchema(BaseModel):
```

Schema for the generated rationale code.

**Parameters:**

* **code** (str): The generated code without any formatting.
