Skip to content

Commit

Permalink
update generation doc
Browse files Browse the repository at this point in the history
  • Loading branch information
XuhuiZhou committed Jul 31, 2024
1 parent 7442ae1 commit d9e04cd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 26 deletions.
56 changes: 56 additions & 0 deletions docs/pages/concepts/generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,59 @@ async def agenerate(
) -> OutputType:
input_variables = re.findall(r"(?<!{){([^{}]+)}(?!})", template)
```

The `agenerate` function is versatile by taking the output_parser as an argument and returning the output in the desired format.

Here are a few examples of how to use the `agenerate` function:

### Automatically generate scenarios

```python
async def agenerate_env_profile(
model_name: str,
inspiration_prompt: str = "asking my boyfriend to stop being friends with his ex",
examples: str = "",
temperature: float = 0.7,
) -> tuple[EnvironmentProfile, str]:
"""
Using langchain to generate the background
"""
return await agenerate(
model_name=model_name,
template="""Please generate scenarios and goals based on the examples below as well as the inspirational prompt, when creating the goals, try to find one point that both sides may not agree upon initially and need to collaboratively resolve it.
Examples:
{examples}
Inspirational prompt: {inspiration_prompt}
Please use the following format:
{format_instructions}
""",
input_values=dict(
inspiration_prompt=inspiration_prompt,
examples=examples,
),
output_parser=PydanticOutputParser(pydantic_object=EnvironmentProfile),
temperature=temperature,
)
```
### Other generation functions
Similarly, there are other utility functions that builds upon the `agenerate` function to generate different types of outputs.

```python
@beartype
async def agenerate_relationship_profile(
model_name: str,
agents_profiles: list[str],
) -> tuple[RelationshipProfile, str]
```

```python
async def agenerate_script(
model_name: str,
background: ScriptBackground,
temperature: float = 0.7,
agent_names: list[str] = [],
agent_name: str = "",
history: str = "",
single_step: bool = False,
) -> tuple[ScriptInteractionReturnType, str]
```
26 changes: 0 additions & 26 deletions sotopia/generation_utils/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,32 +555,6 @@ async def agenerate_relationship_profile(
)


@beartype
async def agenerate_enviroment_profile(
model_name: str,
inspiration_prompt: str = "asking my boyfriend to stop being friends with his ex",
examples: str = "",
) -> tuple[EnvironmentProfile, str]:
"""
Using langchain to generate the background
"""
return await agenerate(
model_name=model_name,
template="""Please generate scenarios and goals based on the examples below as well as the inspirational prompt, when creating the goals, try to find one point that both sides may not agree upon initially and need to collaboratively resolve it.
Examples:
{examples}
Inspirational prompt: {inspiration_prompt}
Please use the following format:
{format_instructions}
""",
input_values=dict(
inspiration_prompt=inspiration_prompt,
examples=examples,
),
output_parser=PydanticOutputParser(pydantic_object=EnvironmentProfile),
)


@gin.configurable
@beartype
async def agenerate_action(
Expand Down

0 comments on commit d9e04cd

Please sign in to comment.