-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from djwu563/develop/v0.2.1
Update the device docs to include ProgrammaticClient
- Loading branch information
Showing
6 changed files
with
140 additions
and
25 deletions.
There are no files selected for viewing
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,18 @@ | ||
# AppClient | ||
|
||
## Introduction | ||
`AppClient` is a client tool designed for user interaction within applications. | ||
|
||
## Initialization Parameters | ||
- `interactor`: Optional parameter, workflow used for interaction | ||
- `processor`: Optional parameter, workflow used for image processing | ||
- `config_path`: Optional parameter, path to the worker configuration file | ||
- `workers`: Optional parameter, list of Worker instances | ||
|
||
Note: | ||
1. Either `interactor` or `processor` must be provided | ||
2. At least one of `config_path` or `workers` must be provided, or both can be used | ||
|
||
## Input and Output | ||
- Input: Uses `AppInput` | ||
- Output: Uses `AppCallback` |
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,22 @@ | ||
# DefaultClient | ||
|
||
## Introduction | ||
`DefaultClient` is the default client used for interacting with users via the command line. | ||
|
||
## Initialization Parameters | ||
- `interactor`: Optional parameter, workflow used for interaction | ||
- `processor`: Optional parameter, workflow used for image processing | ||
- `config_path`: Optional parameter, path to the worker configuration file | ||
- `workers`: Optional parameter, list of Worker instances | ||
- `input_prompt`: Optional parameter, prompt message for user input (defaults to None) | ||
|
||
Note: | ||
1. Either `interactor` or `processor` must be provided | ||
2. At least one of `config_path` or `workers` must be provided, or both can be used | ||
3. If you need a prompt message after startup, you can either: | ||
- Pass it through the `input_prompt` parameter | ||
- Set it in the `self.input.read_input()` method of your first worker node | ||
|
||
## Input and Output | ||
- Input: Uses `AppInput` | ||
- Output: Uses `DefaultCallback` |
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,75 @@ | ||
# ProgrammaticClient | ||
|
||
## Introduction | ||
`ProgrammaticClient` is a client tool designed for executing batch tasks. | ||
|
||
## Initialization Parameters | ||
- `processor`: Required parameter, the processor for handling tasks | ||
- `config_path`: Optional parameter, path to the worker configuration file | ||
- `workers`: Optional parameter, list of Worker instances | ||
|
||
Note: Either `config_path` or `workers` must be provided. | ||
|
||
## Execution Methods | ||
ProgrammaticClient provides two methods for executing batch tasks: | ||
|
||
### 1. start_batch_processor | ||
Parallel processing of multiple tasks: | ||
```python | ||
# Usage example | ||
workflow_input_list = [] | ||
for i in range(3): | ||
workflow_input_list.append({ | ||
"id": str(i), | ||
"file_path": f"/path/to/test{i}.png" | ||
}) | ||
programmatic_client.start_batch_processor(workflow_input_list=workflow_input_list) | ||
programmatic_client.stop_processor() | ||
``` | ||
|
||
Features: | ||
- Supports multi-process parallel execution | ||
- Default of 5 processes per worker | ||
- Process count can be adjusted via the `concurrency` parameter in the worker configuration file | ||
|
||
### 2. start_processor_with_input | ||
Serial processing of individual tasks: | ||
```python | ||
# Usage example | ||
for i in range(3): | ||
programmatic_client.start_processor_with_input( | ||
workflow_input={"id": str(i), "file_path": f"/path/to/test{i}.png"} | ||
) | ||
programmatic_client.stop_processor() | ||
``` | ||
|
||
Features: | ||
- Executes one task at a time | ||
- Waits for the current task to complete before executing the next one | ||
|
||
## Parameter Passing | ||
To pass parameters during execution, you need to: | ||
1. Define the corresponding parameters in the worker's `_run` method | ||
2. Specify parameter sources when defining the task | ||
|
||
Example code: | ||
```python | ||
@registry.register_worker() | ||
class SimpleTest(BaseWorker): | ||
def _run(self, id: str, file_path: str): | ||
print("id:", id) | ||
print("file_path:", file_path) | ||
# do something | ||
|
||
# Define task | ||
task1 = simple_task( | ||
task_def_name="SimpleTest", | ||
task_reference_name="simple_test", | ||
inputs={ | ||
"id": workflow.input("id"), | ||
"file_path": workflow.input("file_path") | ||
} | ||
) | ||
|
||
workflow >> task1 | ||
``` |
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,24 @@ | ||
# WebpageClient | ||
|
||
## Introduction | ||
`WebpageClient` is a web-based chat interface implemented with Gradio, designed for interactive communication. | ||
|
||
## Initialization Parameters | ||
- `interactor`: Optional parameter, workflow used for interaction | ||
- `processor`: Optional parameter, workflow used for image processing | ||
- `config_path`: Optional parameter, path to the worker configuration file | ||
- `workers`: Optional parameter, list of Worker instances | ||
|
||
Note: | ||
1. Either `interactor` or `processor` must be provided | ||
2. At least one of `config_path` or `workers` must be provided, or both can be used | ||
3. When using `interactor`: | ||
- Default port: **7860** | ||
- Access URL: `http://127.0.0.1:7860` | ||
4. When using `processor`: | ||
- Default port: **7861** | ||
- Access URL: `http://127.0.0.1:7861` | ||
|
||
## Input and Output | ||
- Input: Uses `AppInput` | ||
- Output: Uses `AppCallback` |
25 changes: 1 addition & 24 deletions
25
docs/concepts/clients/client.md → docs/concepts/clients/input_and_callback.md
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