Skip to content

Commit

Permalink
Apply formatting to docs_src (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaranvpl authored Sep 13, 2024
1 parent 6b632f8 commit 96fee95
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 86 deletions.
6 changes: 3 additions & 3 deletions docs/docs/en/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ Depending on the interface you choose, you'll need to import different modules.

=== "Console"
```python hl_lines="7"
{!> docs_src/getting_started/main_console.py [ln:1-8] !}
{!> docs_src/getting_started/main_console.py [ln:1-7] !}
```

For Console applications, import `ConsoleUI` to handle command-line input and output.

=== "Mesop"
```python hl_lines="7"
{!> docs_src/getting_started/main_mesop.py [ln:1-8] !}
{!> docs_src/getting_started/main_mesop.py [ln:1-7] !}
```

For Mesop applications, import `MesopUI` to integrate with the Mesop web interface.
Expand All @@ -137,7 +137,7 @@ Depending on the interface you choose, you'll need to import different modules.
You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. Here's a simple example of a workflow definition:

```python
{! docs_src/getting_started/main_console.py [ln:10-43] !}
{! docs_src/getting_started/main_console.py [ln:10-45] !}
```

This code snippet sets up a simple learning chat between a student and a teacher. You define the agents and how they should interact, specifying how the conversation should be summarized.
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/en/user-guide/api/openapi/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ pip install "fastagency[autogen,openapi]"
These imports are similar to the imports section we have already covered, with the only difference being the additional imports of the `OpenAPI` Client and `UserProxyAgent`:

```python
{! docs_src/user_guide/external_rest_apis/main.py [ln:1-11] !}
{! docs_src/user_guide/external_rest_apis/main.py [ln:1-9] !}
```

## Define Workflow

In this workflow, the only difference is that we create a Python client for the external REST API by passing the URL of the `openapi.json` to the `Client.create` method. Then, we register the generated client with the agent using the methods `register_for_llm` and `register_for_execution`. Here's a simple example of a workflow definition:

```python
{! docs_src/user_guide/external_rest_apis/main.py [ln:12-60] !}
{! docs_src/user_guide/external_rest_apis/main.py [ln:11-57] !}
```

This code snippet sets up a simple weather agent that calls an external weather API using the registered functions generated from the `openapi.json` URL.
Expand All @@ -39,7 +39,7 @@ This code snippet sets up a simple weather agent that calls an external weather
Next, define your FastAgency application.

```python
{! docs_src/user_guide/external_rest_apis/main.py [ln:61] !}
{! docs_src/user_guide/external_rest_apis/main.py [ln:60] !}
```

## Complete Application Code
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/en/user-guide/api/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pip install "fastagency[autogen,openapi]"
The imports are the same as in the [previous chapter](./index.md){.internal-link}, except here we also import `APIKeyHeader` to set the security value in the header:

```python hl_lines="11"
{! docs_src/user_guide/external_rest_apis/security.py [ln:1-11] !}
{! docs_src/user_guide/external_rest_apis/security.py [ln:1-10] !}
```

## Define Workflow
Expand All @@ -29,13 +29,13 @@ In this workflow, we create a Python client for the external REST API by passing
Additionally, we set the API key for the API using the `set_security_params` method:

```python hl_lines="2"
{! docs_src/user_guide/external_rest_apis/security.py [ln:26,27] !}
{! docs_src/user_guide/external_rest_apis/security.py [ln:25,26] !}
```

Here's a simple example of a workflow definition:

```python hl_lines="15"
{! docs_src/user_guide/external_rest_apis/security.py [ln:13-66] !}
{! docs_src/user_guide/external_rest_apis/security.py [ln:12-69] !}
```

This code snippet sets up a simple weather agent that calls an external weather API with security, using the registered functions generated from the `openapi.json` URL.
Expand All @@ -45,7 +45,7 @@ This code snippet sets up a simple weather agent that calls an external weather
Next, define your FastAgency application.

```python
{! docs_src/user_guide/external_rest_apis/security.py [ln:68] !}
{! docs_src/user_guide/external_rest_apis/security.py [ln:72] !}
```

## Complete Application Code
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/en/user-guide/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Depending on the interface you choose, you'll need to import different modules.

=== "Console"
```python
{!> docs_src/getting_started/main_console.py [ln:1-8] !}
{!> docs_src/getting_started/main_console.py [ln:1-7] !}
```

For Console applications, import `ConsoleUI` to handle command-line input and output.
Expand All @@ -138,7 +138,7 @@ Depending on the interface you choose, you'll need to import different modules.
You need to define the workflow that your application will use. This is where you specify how the agents interact and what they do. Here's a simple example of a workflow definition:

```python
{! docs_src/getting_started/main_console.py [ln:10-43] !}
{! docs_src/getting_started/main_console.py [ln:10-45] !}
```

This code snippet sets up a simple learning chat between a student and a teacher. You define the agents and how they should interact, specifying how the conversation should be summarized.
Expand Down
14 changes: 7 additions & 7 deletions docs/docs/en/user-guide/runtime/autogen/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ This installation includes the AutoGen runtime, allowing you to build multi-agen
The example starts by importing the necessary modules from **AutoGen** and **FastAgency**. These imports lay the foundation for building and running multi-agent workflows.

```python
{! docs_src/user_guide/runtime/autogen/main.py [ln:1-11] !}
{! docs_src/user_guide/runtime/autogen/main.py [ln:1-9] !}
```

#### 2. **Configure the Language Model (LLM)**
Here, the large language model is configured to use the `gpt-4o` model, and the API key is retrieved from the environment. This setup ensures that both the user and weather agents can interact effectively.

```python
{! docs_src/user_guide/runtime/autogen/main.py [ln:12-22] !}
{! docs_src/user_guide/runtime/autogen/main.py [ln:11-19] !}
```

#### 3. **Set Up the Weather API**
We define the OpenAPI specification URL for the weather service. This API will later be used by the weather agent to fetch real-time weather data.

```python
{! docs_src/user_guide/runtime/autogen/main.py [ln:23-26] !}
{! docs_src/user_guide/runtime/autogen/main.py [ln:21-23] !}
```

#### 4. **Define the Workflow and Agents**
Expand All @@ -49,28 +49,28 @@ In this step, we create two agents:
The workflow is registered using **[AutoGenWorkflows](../../../api/fastagency/runtime/autogen/AutoGenWorkflows/)**.

```python
{! docs_src/user_guide/runtime/autogen/main.py [ln:27-45] !}
{! docs_src/user_guide/runtime/autogen/main.py [ln:28-43] !}
```

#### 5. **Register API Functions with the Agents**
In this step, we register the weather API functions to ensure that the weather agent can call the correct functions, such as `get_daily_weather` and `get_daily_weather_weekly_get`, to retrieve the required weather data.

```python
{! docs_src/user_guide/runtime/autogen/main.py [ln:46-60] !}
{! docs_src/user_guide/runtime/autogen/main.py [ln:45-58] !}
```

#### 6. **Enable Agent Interaction and Chat**
Here, the user agent initiates a chat with the weather agent, which queries the API and returns the weather information. The conversation is summarized using a method provided by the LLM.

```python
{! docs_src/user_guide/runtime/autogen/main.py [ln:61-69] !}
{! docs_src/user_guide/runtime/autogen/main.py [ln:60-67] !}
```

#### 7. **Create and Run the Application**
Finally, we create the FastAgency application and launch it using the console interface.

```python
{! docs_src/user_guide/runtime/autogen/main.py [ln:71-72] !}
{! docs_src/user_guide/runtime/autogen/main.py [ln:70] !}
```

## Complete Application Code
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/en/user-guide/runtime/autogen/interactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ Let's define three functions which will be available to the agents:
`TextInput` is suitable for free-form text messages, ideal for open-ended queries and dialogues. This function allows the student to request exam questions from the teacher and provides some suggestions using `TextInput`.

```python
{! docs_src/user_guide/custom_user_interactions/main.py [ln:52.5,53.5,54.5,55.5,56.5,57.5,58.5,59.5,60.5,61.5,62.5,63.5,64.5,66.5,67.5,68.5,69.5,70.5] !}
{! docs_src/user_guide/custom_user_interactions/main.py [ln:50.5,51.5,52.5,53.5,54.5,55.5,56.5,57.5,58.5,59.5,60.5,61.5,62.5,63.5,64.5,66.5,67.5,68.5] !}
```

### System Info Messages

`SystemMessage` is used for operational or system-related instructions, such as logging data, and is not part of the agent dialogue. This function logs the final answers after the student completes the discussion using `SystemMessage` to log the event.

```python
{! docs_src/user_guide/custom_user_interactions/main.py [ln:72.5,73.5,74.5,75.5,76.5,77.5,78.5,79.5,80.5,81.5,82.5,83.5,84.5,85.5] !}
{! docs_src/user_guide/custom_user_interactions/main.py [ln:70.5,71.5,72.5,73.5,74.5,75.5,76.5,77.5,78.5,79.5,80.5,81.5,82.5,83.5] !}
```

### Multiple Choice

`MultipleChoice` is used for structured responses where the user must select one of several predefined options. This function retrieves the final grade for the student's submitted answers using `MultipleChoice`, presenting the user with grading options.

```python
{! docs_src/user_guide/custom_user_interactions/main.py [ln:87.5,88.5,89.5,90.5,91.5,92.5,93.5,94.5,96.5,97.5,98.5,99.5] !}
{! docs_src/user_guide/custom_user_interactions/main.py [ln:85.5,86.5,87.5,88.5,89.5,90.5,91.5,92.5,93.5,94.5,96.5,97.5] !}
```

### Other Types of Messages
Expand All @@ -50,7 +50,7 @@ All supported messages are subclasses of the [IOMessage](../../../../api/fastage
We now register these functions with the workflow, linking the `student_agent` as the caller and the `teacher_agent` as the executor.

```python
{! docs_src/user_guide/custom_user_interactions/main.py [ln:101.5,102.5,103.5,104.5,105.5,106.5,107.5,108.5,109.5,110.5,111.5,112.5,113.5,114.5,115.5,116.5,117.5,118.5,119.5,120.5,121.5,122.5,123.5] !}
{! docs_src/user_guide/custom_user_interactions/main.py [ln:99.5,100.5,101.5,102.5,103.5,104.5,105.5,106.5,107.5,108.5,109.5,110.5,111.5,112.5,113.5,114.5,115.5,116.5,117.5,118.5,119.5,120.5,121.5] !}
```

## Complete Application Code
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/en/user-guide/ui/console/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This example demonstrates how to create a workflow where a student agent interac
We begin by importing the necessary modules from **FastAgency** and **AutoGen**. These imports provide the essential building blocks for creating agents, workflows, and integrating the ConsoleUI.

```python
{! docs_src/getting_started/main_console.py [ln:1-8] !}
{! docs_src/getting_started/main_console.py [ln:1-7] !}
```

- **ConversableAgent**: This class allows the creation of agents that can engage in conversational tasks.
Expand All @@ -35,7 +35,7 @@ Next, we configure the language model that will power the agents. In this case,
Here, we define a simple workflow where the **Student Agent** interacts with the **Teacher Agent**. The student asks questions, and the teacher responds as a math teacher. The workflow is registered using **AutoGenWorkflows**.

```python
{! docs_src/getting_started/main_console.py [ln:20-44] !}
{! docs_src/getting_started/main_console.py [ln:22-44] !}
```

- **Agent Overview**: The **Student Agent** is configured with a system message, "You are a student willing to learn," and will initiate questions during the interaction. The **Teacher Agent**, on the other hand, is set up as a math teacher and will respond to the student's questions.
Expand All @@ -45,7 +45,7 @@ Here, we define a simple workflow where the **Student Agent** interacts with the
Finally, we instantiate **[ConsoleUI](../../../../api/fastagency/ui/console/ConsoleUI/)** to link the workflow to a text-based console interface. This allows the user to interact with the agents via the terminal.

```python
{! docs_src/getting_started/main_console.py [ln:47-48] !}
{! docs_src/getting_started/main_console.py [ln:47] !}
```

- **Explanation**: Here, we set up the **ConsoleUI** as the user interface for the workflow, which will allow the entire agent interaction to take place within the terminal.
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/en/user-guide/ui/mesop/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This example shows how to create a simple learning chat where a student agent in
We begin by importing the necessary modules from **FastAgency** and **AutoGen**. These imports provide the essential building blocks for creating agents, workflows, and integrating MesopUI.

```python
{! docs_src/getting_started/main_mesop.py [ln:1-8] !}
{! docs_src/getting_started/main_mesop.py [ln:1-7] !}
```

- **ConversableAgent**: This class allows the creation of agents that can engage in conversational tasks.
Expand All @@ -43,7 +43,7 @@ Next, we configure the language model that powers the agents. In this case, we'r
Here, we define a simple workflow where the **Student Agent** interacts with the **Teacher Agent**. The student asks questions, and the teacher responds as a math teacher. The workflow is registered using **AutoGenWorkflows**.

```python
{! docs_src/getting_started/main_mesop.py [ln:20-44] !}
{! docs_src/getting_started/main_mesop.py [ln:22-44] !}
```

- **Agent Overview**: The **Student Agent** is configured with a system message, "You are a student willing to learn," and will initiate questions during the interaction. The **Teacher Agent**, on the other hand, is set up as a math teacher and will respond to the student's questions.
Expand Down
10 changes: 5 additions & 5 deletions docs/docs_src/getting_started/main_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from autogen.agentchat import ConversableAgent

from fastagency import FastAgency, Workflows
from fastagency import UI
from fastagency.ui.console import ConsoleUI
from fastagency import UI, FastAgency, Workflows
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
"config_list": [
Expand All @@ -21,7 +20,9 @@


@wf.register(name="simple_learning", description="Student and teacher learning chat")
def simple_workflow(wf: Workflows, ui: UI, initial_message: str, session_id: str) -> str:
def simple_workflow(
wf: Workflows, ui: UI, initial_message: str, session_id: str
) -> str:
student_agent = ConversableAgent(
name="Student_Agent",
system_message="You are a student willing to learn.",
Expand All @@ -43,5 +44,4 @@ def simple_workflow(wf: Workflows, ui: UI, initial_message: str, session_id: str
return chat_result.summary # type: ignore[no-any-return]



app = FastAgency(wf=wf, ui=ConsoleUI())
10 changes: 5 additions & 5 deletions docs/docs_src/getting_started/main_mesop.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

from autogen.agentchat import ConversableAgent

from fastagency import FastAgency, Workflows
from fastagency import UI
from fastagency.ui.mesop import MesopUI
from fastagency import UI, FastAgency, Workflows
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency.ui.mesop import MesopUI

llm_config = {
"config_list": [
Expand All @@ -21,7 +20,9 @@


@wf.register(name="simple_learning", description="Student and teacher learning chat")
def simple_workflow(wf: Workflows, ui: UI, initial_message: str, session_id: str) -> str:
def simple_workflow(
wf: Workflows, ui: UI, initial_message: str, session_id: str
) -> str:
student_agent = ConversableAgent(
name="Student_Agent",
system_message="You are a student willing to learn.",
Expand All @@ -43,5 +44,4 @@ def simple_workflow(wf: Workflows, ui: UI, initial_message: str, session_id: str
return chat_result.summary # type: ignore[no-any-return]



app = FastAgency(wf=wf, ui=MesopUI())
12 changes: 5 additions & 7 deletions docs/docs_src/user_guide/custom_user_interactions/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import os
from typing import Annotated, Any, Dict, Optional
from typing import Annotated, Any, Optional

from autogen import register_function
from autogen.agentchat import ConversableAgent

from fastagency import FastAgency, Workflows
from fastagency import UI
from fastagency import UI, FastAgency, Workflows
from fastagency.base import MultipleChoice, SystemMessage, TextInput
from fastagency.ui.console import ConsoleUI
from fastagency.runtime.autogen.base import AutoGenWorkflows
from fastagency.ui.console import ConsoleUI

llm_config = {
"config_list": [
Expand All @@ -25,7 +24,6 @@

@wf.register(name="exam_practice", description="Student and teacher chat")
def exam_learning(wf: Workflows, ui: UI, initial_message: str, session_id: str) -> str:

def is_termination_msg(msg: dict[str, Any]) -> bool:
return msg["content"] is not None and "TERMINATE" in msg["content"]

Expand All @@ -50,7 +48,7 @@ def is_termination_msg(msg: dict[str, Any]) -> bool:
)

def retrieve_exam_questions(
message: Annotated[str, "Message for examiner"]
message: Annotated[str, "Message for examiner"],
) -> Optional[str]:
try:
msg = TextInput(
Expand Down Expand Up @@ -85,7 +83,7 @@ def write_final_answers(message: Annotated[str, "Message for examiner"]) -> str:
return f"write_final_answers() FAILED! {e}"

def get_final_grade(
message: Annotated[str, "Message for examiner"]
message: Annotated[str, "Message for examiner"],
) -> Optional[str]:
try:
msg = MultipleChoice(
Expand Down
Loading

0 comments on commit 96fee95

Please sign in to comment.