-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): implement cli wrapper (#43)
- Loading branch information
1 parent
56db22a
commit 0b19e8f
Showing
37 changed files
with
1,038 additions
and
3,246 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
["API.md", "cache.md"] | ||
["API.md", "cli.md", "cache.md", "model-vendor.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Command Line Tools | ||
|
||
`@midscene/cli` is the command line version of Midscene. It is suitable for executing very simple tasks or experiencing the basics of Midscene. | ||
|
||
## Preparation | ||
|
||
* Install Node.js | ||
|
||
Ensure that you have [Node.js](https://nodejs.org/) installed. | ||
|
||
* Config AI vendor | ||
|
||
```bash | ||
# replace by your own | ||
export OPENAI_API_KEY="sk-abcdefghijklmnopqrstuvwxyz" | ||
``` | ||
|
||
Related Docs: | ||
* [Customize model vendor](./model-vendor.html) | ||
|
||
## Examples | ||
|
||
```bash | ||
# headed mode (i.e. visible browser) to visit bing.com and search for 'weather today' | ||
npx @midscene/cli --headed --url https://wwww.bing.com --action "type 'weather today', hit enter" --sleep 3000 | ||
|
||
# visit github status page and save the status to ./status.json | ||
npx @midscene/cli --url https://www.githubstatus.com/ \ | ||
--query-output status.json \ | ||
--query '{name: string, status: string}[], service status of github page' | ||
``` | ||
|
||
Or you may install @midscene/cli globally before calling | ||
|
||
```bash | ||
# install | ||
npm i -g @midscene/cli | ||
|
||
# call by `midscene` | ||
midscene --url https://wwww.bing.com --action "type 'weather today', hit enter" | ||
``` | ||
|
||
## Usage | ||
|
||
Usage: `midscene [options] [actions]` | ||
|
||
Options: | ||
|
||
```log | ||
Options: | ||
--url <url> The URL to visit, required | ||
--user-agent <ua> The user agent to use, optional | ||
--viewport-width <width> The width of the viewport, optional | ||
--viewport-height <height> The height of the viewport, optional | ||
--viewport-scale <scale> The device scale factor, optional | ||
--headed Run in headed mode, default false | ||
--help Display this help message | ||
--version Display the version | ||
Actions (order matters, can be used multiple times): | ||
--action <action> Perform an action, optional | ||
--assert <assert> Perform an assert, optional | ||
--query-output <path> Save the result of the query to a file, this must be put before --query, optional | ||
--query <query> Perform a query, optional | ||
--sleep <ms> Sleep for a number of milliseconds, optional` | ||
``` | ||
|
||
|
||
## Note | ||
|
||
1. Always put options before any action param | ||
2. The order of action param matters. For example, `--action "some action" --query "some data"` means taking some action first, then querying. | ||
3. If you have some more complex requirements, such as loop operations, using the SDK version (instead of this cli) is an easier way to achieve them. |
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,25 @@ | ||
# Customize model vendor | ||
|
||
Midscene uses the OpenAI SDK as the default AI service. You can customize the configuration using environment variables. | ||
|
||
There are the main configs, in which `OPENAI_API_KEY` is required. | ||
|
||
Required: | ||
|
||
```bash | ||
# replace by your own | ||
export OPENAI_API_KEY="sk-abcdefghijklmnopqrstuvwxyz" | ||
``` | ||
|
||
Optional: | ||
|
||
```bash | ||
# optional, if you want to use a customized endpoint | ||
export OPENAI_BASE_URL="https://..." | ||
|
||
# optional, if you want to specify a model name other than gpt-4o | ||
export MIDSCENE_MODEL_NAME='claude-3-opus-20240229'; | ||
|
||
# optional, if you want to pass customized JSON data to the `init` process of OpenAI SDK | ||
export MIDSCENE_OPENAI_INIT_CONFIG_JSON='{"baseURL":"....","defaultHeaders":{"key": "value"}}' | ||
``` |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
["API.md", "cache.md"] | ||
["API.md", "cli.md", "cache.md", "model-vendor.md"] |
Oops, something went wrong.