-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
21484af
commit b932d99
Showing
3 changed files
with
83 additions
and
23 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
docs/introduction/foundations/components/actions/processing.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
--- | ||
title: "🛠️ Enhancing Action Inputs & Outputs" | ||
sidebarTitle: "Processing Actions" | ||
icon: "wand-magic-sparkles" | ||
description: "Master the art of preprocessing and postprocessing actions for optimal results." | ||
--- | ||
|
||
## Refining Action Inputs & Outputs | ||
|
||
In many scenarios, the raw inputs or outputs of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are two key use cases: | ||
|
||
- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM). | ||
- **Preprocessing**: Generate or modify inputs dynamically at runtime, handling scenarios that may be challenging for the LLM to produce directly. | ||
|
||
Composio empowers you with the ability to define **custom Python functions** as preprocessors or postprocessors. | ||
|
||
These can be applied at two levels: | ||
|
||
1. **Tool-level**: Affects all actions within a specific tool. | ||
2. **Action-level**: Tailored processing for individual actions. | ||
|
||
Here's how you can implement these processors: | ||
<Steps> | ||
<Step title="Define the Preprocessor or Postprocessor Functions"> | ||
<CodeGroup> | ||
```python Define the Preprocessor or Postprocessor Functions | ||
def tool_preprocessor(input_data): | ||
# Modify input_data as needed | ||
return modified_input_data | ||
|
||
def tool_postprocessor(output_data): | ||
# Process output_data as needed | ||
return processed_output_data | ||
|
||
def action_preprocessor(input_data): | ||
# Modify input_data as needed | ||
return modified_input_data | ||
|
||
def action_postprocessor(output_data): | ||
# Process output_data as needed | ||
return processed_output_data | ||
``` | ||
</CodeGroup> | ||
</Step> | ||
<Step title="Use them while creating the toolset"> | ||
<CodeGroup> | ||
```python Set the pre and post processors while creating the toolset | ||
# while defining the toolset, you can define the pre and post processors | ||
composio_toolset = ComposioToolSet( | ||
processors={ | ||
"pre": { | ||
App.GITHUB: tool_preprocessor, | ||
Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_preprocessor, | ||
}, | ||
"post": { | ||
App.GITHUB: tool_postprocessor, | ||
Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_postprocessor, | ||
}, | ||
}, | ||
) | ||
|
||
tools = composio_toolset.get_tools(apps=[App.GITHUB]) | ||
``` | ||
</CodeGroup> | ||
</Step> | ||
</Steps> | ||
|
||
|
||
<Warning> | ||
Ensure that your preprocessing and postprocessing functions are efficient and don't introduce significant latency. | ||
</Warning> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters