Skip to content

armgit / camel

Public Imported from GitHub
0

🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org

4.2 KB
Raw Blame
<a id="camel.datasets.self_instruct_generator"></a>

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

## SelfInstructGenerator

```python
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__"></a>

### __init__

```python
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"></a>

### default_instruction_agent

```python
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"></a>

### default_rationale_agent

```python
def default_rationale_agent(self):
```

**Returns:**

  ChatAgent: An agent with the rationale prompt

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

### format_support_block

```python
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"></a>

### generate_new_instruction

```python
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"></a>

### generate_rationale

```python
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"></a>

## QuestionSchema

```python
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"></a>

## RationaleSchema

```python
class RationaleSchema(BaseModel):
```

Schema for the generated rationale code.

**Parameters:**

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