oagi 0.2.1__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of oagi might be problematic. Click here for more details.
- oagi-0.4.0/PKG-INFO +161 -0
- oagi-0.4.0/README.md +127 -0
- oagi-0.4.0/examples/async_google_weather.py +23 -0
- {oagi-0.2.1 → oagi-0.4.0}/examples/execute_task_auto.py +20 -1
- oagi-0.4.0/examples/execute_task_manual.py +98 -0
- oagi-0.4.0/examples/screenshot_with_config.py +94 -0
- {oagi-0.2.1 → oagi-0.4.0}/examples/single_step.py +6 -4
- {oagi-0.2.1 → oagi-0.4.0}/pyproject.toml +2 -1
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/__init__.py +30 -2
- oagi-0.4.0/src/oagi/async_client.py +239 -0
- oagi-0.4.0/src/oagi/async_pyautogui_action_handler.py +44 -0
- oagi-0.4.0/src/oagi/async_screenshot_maker.py +47 -0
- oagi-0.4.0/src/oagi/async_short_task.py +56 -0
- oagi-0.4.0/src/oagi/async_single_step.py +83 -0
- oagi-0.4.0/src/oagi/async_task.py +117 -0
- oagi-0.4.0/src/oagi/pil_image.py +98 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/pyautogui_action_handler.py +82 -51
- oagi-0.4.0/src/oagi/screenshot_maker.py +41 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/short_task.py +8 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/single_step.py +4 -3
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/task.py +7 -2
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/types/__init__.py +14 -2
- oagi-0.4.0/src/oagi/types/async_action_handler.py +30 -0
- oagi-0.4.0/src/oagi/types/async_image_provider.py +37 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/types/models/__init__.py +2 -1
- oagi-0.4.0/src/oagi/types/models/image_config.py +47 -0
- {oagi-0.2.1 → oagi-0.4.0}/tests/conftest.py +13 -0
- oagi-0.4.0/tests/test_async_client.py +193 -0
- oagi-0.4.0/tests/test_async_handlers.py +222 -0
- oagi-0.4.0/tests/test_async_task.py +215 -0
- {oagi-0.2.1 → oagi-0.4.0}/tests/test_logging.py +2 -1
- oagi-0.4.0/tests/test_pil_image.py +236 -0
- oagi-0.4.0/tests/test_pyautogui_action_handler.py +143 -0
- oagi-0.4.0/tests/test_screenshot_maker.py +175 -0
- {oagi-0.2.1 → oagi-0.4.0}/tests/test_short_task.py +14 -0
- {oagi-0.2.1 → oagi-0.4.0}/tests/test_single_step.py +22 -15
- {oagi-0.2.1 → oagi-0.4.0}/tests/test_task.py +8 -0
- {oagi-0.2.1 → oagi-0.4.0}/uv.lock +25 -1
- oagi-0.2.1/PKG-INFO +0 -55
- oagi-0.2.1/README.md +0 -21
- oagi-0.2.1/examples/execute_task_manual.py +0 -48
- oagi-0.2.1/src/oagi/screenshot_maker.py +0 -73
- oagi-0.2.1/tests/test_pyautogui_action_handler.py +0 -147
- oagi-0.2.1/tests/test_screenshot_maker.py +0 -149
- {oagi-0.2.1 → oagi-0.4.0}/.github/workflows/ci.yml +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/.github/workflows/release.yml +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/.gitignore +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/.python-version +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/CONTRIBUTING.md +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/LICENSE +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/Makefile +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/examples/google_weather.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/examples/hotel_booking.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/exceptions.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/logging.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/sync_client.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/types/action_handler.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/types/image.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/types/image_provider.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/types/models/action.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/src/oagi/types/models/step.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/tests/__init__.py +0 -0
- {oagi-0.2.1 → oagi-0.4.0}/tests/test_sync_client.py +0 -0
oagi-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: oagi
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: Official API of OpenAGI Foundation
|
|
5
|
+
Project-URL: Homepage, https://github.com/agiopen-org/oagi
|
|
6
|
+
Author-email: OpenAGI Foundation <contact@agiopen.org>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2025 OpenAGI Foundation
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Requires-Dist: httpx>=0.28.0
|
|
30
|
+
Requires-Dist: pillow>=11.3.0
|
|
31
|
+
Requires-Dist: pyautogui>=0.9.54
|
|
32
|
+
Requires-Dist: pydantic>=2.0.0
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# OAGI Python SDK
|
|
36
|
+
|
|
37
|
+
Python SDK for the OAGI API - vision-based task automation.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install oagi # requires Python >= 3.10
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
Set your API credentials:
|
|
48
|
+
```bash
|
|
49
|
+
export OAGI_API_KEY="your-api-key"
|
|
50
|
+
export OAGI_BASE_URL="https://api.oagi.com" # or your server URL
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Single-Step Analysis
|
|
54
|
+
|
|
55
|
+
Analyze a screenshot and get recommended actions:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from oagi import single_step
|
|
59
|
+
|
|
60
|
+
step = single_step(
|
|
61
|
+
task_description="Click the submit button",
|
|
62
|
+
screenshot="screenshot.png" # or bytes, or Image object
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
print(f"Actions: {step.actions}")
|
|
66
|
+
print(f"Complete: {step.is_complete}")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Automated Task Execution
|
|
70
|
+
|
|
71
|
+
Run tasks automatically with screenshot capture and action execution:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from oagi import ShortTask, ScreenshotMaker, PyautoguiActionHandler
|
|
75
|
+
|
|
76
|
+
task = ShortTask()
|
|
77
|
+
completed = task.auto_mode(
|
|
78
|
+
"Search weather on Google",
|
|
79
|
+
max_steps=10,
|
|
80
|
+
executor=PyautoguiActionHandler(), # Executes mouse/keyboard actions
|
|
81
|
+
image_provider=ScreenshotMaker(), # Captures screenshots
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Configure PyAutoGUI behavior with custom settings:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from oagi import PyautoguiActionHandler, PyautoguiConfig
|
|
89
|
+
|
|
90
|
+
# Customize action behavior
|
|
91
|
+
config = PyautoguiConfig(
|
|
92
|
+
drag_duration=1.0, # Slower drags for precision (default: 0.5)
|
|
93
|
+
scroll_amount=50, # Larger scroll steps (default: 30)
|
|
94
|
+
wait_duration=2.0, # Longer waits (default: 1.0)
|
|
95
|
+
action_pause=0.2, # More pause between actions (default: 0.1)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
executor = PyautoguiActionHandler(config=config)
|
|
99
|
+
task.auto_mode("Complete form", executor=executor, image_provider=ScreenshotMaker())
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Image Processing
|
|
103
|
+
|
|
104
|
+
Process and optimize images before sending to API:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from oagi import PILImage, ImageConfig
|
|
108
|
+
|
|
109
|
+
# Load and compress an image
|
|
110
|
+
image = PILImage.from_file("large_screenshot.png")
|
|
111
|
+
config = ImageConfig(
|
|
112
|
+
format="JPEG",
|
|
113
|
+
quality=85,
|
|
114
|
+
width=1260,
|
|
115
|
+
height=700
|
|
116
|
+
)
|
|
117
|
+
compressed = image.transform(config)
|
|
118
|
+
|
|
119
|
+
# Use with single_step
|
|
120
|
+
step = single_step("Click button", screenshot=compressed)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Async Support
|
|
124
|
+
|
|
125
|
+
Use async client for non-blocking operations and better concurrency:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
import asyncio
|
|
129
|
+
from oagi import async_single_step, AsyncShortTask
|
|
130
|
+
|
|
131
|
+
async def main():
|
|
132
|
+
# Single-step async analysis
|
|
133
|
+
step = await async_single_step(
|
|
134
|
+
"Find the search bar",
|
|
135
|
+
screenshot="screenshot.png"
|
|
136
|
+
)
|
|
137
|
+
print(f"Found {len(step.actions)} actions")
|
|
138
|
+
|
|
139
|
+
# Async task automation
|
|
140
|
+
task = AsyncShortTask()
|
|
141
|
+
async with task:
|
|
142
|
+
await task.init_task("Complete the form")
|
|
143
|
+
# ... continue with async operations
|
|
144
|
+
|
|
145
|
+
asyncio.run(main())
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Examples
|
|
149
|
+
|
|
150
|
+
See the [`examples/`](examples/) directory for more usage patterns:
|
|
151
|
+
- `google_weather.py` - Basic task execution with `ShortTask`
|
|
152
|
+
- `single_step.py` - Basic single-step inference
|
|
153
|
+
- `screenshot_with_config.py` - Image compression and optimization
|
|
154
|
+
- `execute_task_auto.py` - Automated task execution
|
|
155
|
+
|
|
156
|
+
## Documentation
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
## License
|
|
160
|
+
|
|
161
|
+
MIT
|
oagi-0.4.0/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# OAGI Python SDK
|
|
2
|
+
|
|
3
|
+
Python SDK for the OAGI API - vision-based task automation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install oagi # requires Python >= 3.10
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
Set your API credentials:
|
|
14
|
+
```bash
|
|
15
|
+
export OAGI_API_KEY="your-api-key"
|
|
16
|
+
export OAGI_BASE_URL="https://api.oagi.com" # or your server URL
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Single-Step Analysis
|
|
20
|
+
|
|
21
|
+
Analyze a screenshot and get recommended actions:
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from oagi import single_step
|
|
25
|
+
|
|
26
|
+
step = single_step(
|
|
27
|
+
task_description="Click the submit button",
|
|
28
|
+
screenshot="screenshot.png" # or bytes, or Image object
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
print(f"Actions: {step.actions}")
|
|
32
|
+
print(f"Complete: {step.is_complete}")
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Automated Task Execution
|
|
36
|
+
|
|
37
|
+
Run tasks automatically with screenshot capture and action execution:
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from oagi import ShortTask, ScreenshotMaker, PyautoguiActionHandler
|
|
41
|
+
|
|
42
|
+
task = ShortTask()
|
|
43
|
+
completed = task.auto_mode(
|
|
44
|
+
"Search weather on Google",
|
|
45
|
+
max_steps=10,
|
|
46
|
+
executor=PyautoguiActionHandler(), # Executes mouse/keyboard actions
|
|
47
|
+
image_provider=ScreenshotMaker(), # Captures screenshots
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Configure PyAutoGUI behavior with custom settings:
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from oagi import PyautoguiActionHandler, PyautoguiConfig
|
|
55
|
+
|
|
56
|
+
# Customize action behavior
|
|
57
|
+
config = PyautoguiConfig(
|
|
58
|
+
drag_duration=1.0, # Slower drags for precision (default: 0.5)
|
|
59
|
+
scroll_amount=50, # Larger scroll steps (default: 30)
|
|
60
|
+
wait_duration=2.0, # Longer waits (default: 1.0)
|
|
61
|
+
action_pause=0.2, # More pause between actions (default: 0.1)
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
executor = PyautoguiActionHandler(config=config)
|
|
65
|
+
task.auto_mode("Complete form", executor=executor, image_provider=ScreenshotMaker())
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Image Processing
|
|
69
|
+
|
|
70
|
+
Process and optimize images before sending to API:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from oagi import PILImage, ImageConfig
|
|
74
|
+
|
|
75
|
+
# Load and compress an image
|
|
76
|
+
image = PILImage.from_file("large_screenshot.png")
|
|
77
|
+
config = ImageConfig(
|
|
78
|
+
format="JPEG",
|
|
79
|
+
quality=85,
|
|
80
|
+
width=1260,
|
|
81
|
+
height=700
|
|
82
|
+
)
|
|
83
|
+
compressed = image.transform(config)
|
|
84
|
+
|
|
85
|
+
# Use with single_step
|
|
86
|
+
step = single_step("Click button", screenshot=compressed)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Async Support
|
|
90
|
+
|
|
91
|
+
Use async client for non-blocking operations and better concurrency:
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
import asyncio
|
|
95
|
+
from oagi import async_single_step, AsyncShortTask
|
|
96
|
+
|
|
97
|
+
async def main():
|
|
98
|
+
# Single-step async analysis
|
|
99
|
+
step = await async_single_step(
|
|
100
|
+
"Find the search bar",
|
|
101
|
+
screenshot="screenshot.png"
|
|
102
|
+
)
|
|
103
|
+
print(f"Found {len(step.actions)} actions")
|
|
104
|
+
|
|
105
|
+
# Async task automation
|
|
106
|
+
task = AsyncShortTask()
|
|
107
|
+
async with task:
|
|
108
|
+
await task.init_task("Complete the form")
|
|
109
|
+
# ... continue with async operations
|
|
110
|
+
|
|
111
|
+
asyncio.run(main())
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
See the [`examples/`](examples/) directory for more usage patterns:
|
|
117
|
+
- `google_weather.py` - Basic task execution with `ShortTask`
|
|
118
|
+
- `single_step.py` - Basic single-step inference
|
|
119
|
+
- `screenshot_with_config.py` - Image compression and optimization
|
|
120
|
+
- `execute_task_auto.py` - Automated task execution
|
|
121
|
+
|
|
122
|
+
## Documentation
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) OpenAGI Foundation
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# This file is part of the official API project.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# -----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
import asyncio
|
|
10
|
+
|
|
11
|
+
from examples.execute_task_manual import async_execute_task_manual
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def main():
|
|
15
|
+
is_completed, screenshot = await async_execute_task_manual(
|
|
16
|
+
desc := "Search weather with Google", max_steps=5
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
print(f"is_completed: {is_completed}, desc: {desc}")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if __name__ == "__main__":
|
|
23
|
+
asyncio.run(main())
|
|
@@ -5,7 +5,14 @@
|
|
|
5
5
|
# This file is part of the official API project.
|
|
6
6
|
# Licensed under the MIT License.
|
|
7
7
|
# -----------------------------------------------------------------------------
|
|
8
|
-
from oagi import
|
|
8
|
+
from oagi import (
|
|
9
|
+
AsyncPyautoguiActionHandler,
|
|
10
|
+
AsyncScreenshotMaker,
|
|
11
|
+
AsyncShortTask,
|
|
12
|
+
PyautoguiActionHandler,
|
|
13
|
+
ScreenshotMaker,
|
|
14
|
+
ShortTask,
|
|
15
|
+
)
|
|
9
16
|
|
|
10
17
|
|
|
11
18
|
def execute_task_auto(task_desc, max_steps=5):
|
|
@@ -21,3 +28,15 @@ def execute_task_auto(task_desc, max_steps=5):
|
|
|
21
28
|
)
|
|
22
29
|
|
|
23
30
|
return is_completed, sm.last_image()
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async def async_execute_task_auto(task_desc, max_steps=5):
|
|
34
|
+
async with AsyncShortTask() as async_short_task:
|
|
35
|
+
is_completed = await async_short_task.auto_mode(
|
|
36
|
+
task_desc,
|
|
37
|
+
max_steps=max_steps,
|
|
38
|
+
executor=AsyncPyautoguiActionHandler(),
|
|
39
|
+
image_provider=(sm := AsyncScreenshotMaker()),
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
return is_completed, await sm.last_image()
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) OpenAGI Foundation
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# This file is part of the official API project.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# -----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
from oagi import (
|
|
10
|
+
AsyncPyautoguiActionHandler,
|
|
11
|
+
AsyncScreenshotMaker,
|
|
12
|
+
AsyncTask,
|
|
13
|
+
PyautoguiActionHandler,
|
|
14
|
+
ScreenshotMaker,
|
|
15
|
+
Task,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def execute_task_manual(task_desc, max_steps=5):
|
|
20
|
+
# set OAGI_API_KEY and OAGI_BASE_URL
|
|
21
|
+
# or ShortTask(api_key="your_api_key", base_url="your_base_url")
|
|
22
|
+
task = Task()
|
|
23
|
+
task.init_task(task_desc, max_steps=max_steps)
|
|
24
|
+
executor = (
|
|
25
|
+
PyautoguiActionHandler()
|
|
26
|
+
) # executor = lambda actions: print(actions) for debugging
|
|
27
|
+
|
|
28
|
+
# by default, screenshot will be resized to 1260 * 700 and jpeg with quality 85
|
|
29
|
+
# for best image quality, use ScreenshotMaker(config=ImageConfig(format="PNG"))
|
|
30
|
+
image_provider = ScreenshotMaker()
|
|
31
|
+
|
|
32
|
+
for i in range(max_steps):
|
|
33
|
+
# image can also be bytes
|
|
34
|
+
# with open("test_screenshot.png", "rb") as f:
|
|
35
|
+
# image = f.read()
|
|
36
|
+
image = image_provider()
|
|
37
|
+
|
|
38
|
+
# For additional instructions
|
|
39
|
+
# step = task.step(image, instruction="some instruction")
|
|
40
|
+
step = task.step(image)
|
|
41
|
+
|
|
42
|
+
# do something with step, maybe print to debug
|
|
43
|
+
print(f"Step {i}: {step.reason=}")
|
|
44
|
+
|
|
45
|
+
if step.stop:
|
|
46
|
+
print(f"Task completed after {i} steps.")
|
|
47
|
+
is_completed = True
|
|
48
|
+
screenshot = image_provider.last_image()
|
|
49
|
+
break
|
|
50
|
+
|
|
51
|
+
executor(step.actions)
|
|
52
|
+
else:
|
|
53
|
+
# If we didn't break out of the loop, we used up all our steps
|
|
54
|
+
is_completed = False
|
|
55
|
+
screenshot = image_provider()
|
|
56
|
+
|
|
57
|
+
print(f"manual execution completed: {is_completed=}, {task_desc=}\n")
|
|
58
|
+
return is_completed, screenshot
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def async_execute_task_manual(task_desc, max_steps=5):
|
|
62
|
+
# set OAGI_API_KEY and OAGI_BASE_URL
|
|
63
|
+
# or ShortTask(api_key="your_api_key", base_url="your_base_url")
|
|
64
|
+
async with AsyncTask() as task:
|
|
65
|
+
await task.init_task(task_desc, max_steps=max_steps)
|
|
66
|
+
executor = AsyncPyautoguiActionHandler()
|
|
67
|
+
|
|
68
|
+
# by default, screenshot will be resized to 1260 * 700 and jpeg with quality 85
|
|
69
|
+
# for best image quality, use ScreenshotMaker(config=ImageConfig(format="PNG"))
|
|
70
|
+
image_provider = AsyncScreenshotMaker()
|
|
71
|
+
|
|
72
|
+
for i in range(max_steps):
|
|
73
|
+
# image can also be bytes
|
|
74
|
+
# with open("test_screenshot.png", "rb") as f:
|
|
75
|
+
# image = f.read()
|
|
76
|
+
image = await image_provider()
|
|
77
|
+
|
|
78
|
+
# For additional instructions
|
|
79
|
+
# step = task.step(image, instruction="some instruction")
|
|
80
|
+
step = await task.step(image)
|
|
81
|
+
|
|
82
|
+
# do something with step, maybe print to debug
|
|
83
|
+
print(f"Step {i}: {step.reason=}")
|
|
84
|
+
|
|
85
|
+
if step.stop:
|
|
86
|
+
print(f"Task completed after {i} steps.")
|
|
87
|
+
is_completed = True
|
|
88
|
+
screenshot = await image_provider.last_image()
|
|
89
|
+
break
|
|
90
|
+
|
|
91
|
+
await executor(step.actions)
|
|
92
|
+
else:
|
|
93
|
+
# If we didn't break out of the loop, we used up all our steps
|
|
94
|
+
is_completed = False
|
|
95
|
+
screenshot = await image_provider()
|
|
96
|
+
|
|
97
|
+
print(f"manual execution completed: {is_completed=}, {task_desc=}\n")
|
|
98
|
+
return is_completed, screenshot
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# -----------------------------------------------------------------------------
|
|
2
|
+
# Copyright (c) OpenAGI Foundation
|
|
3
|
+
# All rights reserved.
|
|
4
|
+
#
|
|
5
|
+
# This file is part of the official API project.
|
|
6
|
+
# Licensed under the MIT License.
|
|
7
|
+
# -----------------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
from oagi import ImageConfig, PILImage, ScreenshotMaker, single_step
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def example_full_png_screenshot():
|
|
13
|
+
"""Example 1: Full-quality PNG screenshot without resizing."""
|
|
14
|
+
print("Example 1: Full PNG screenshot without resizing")
|
|
15
|
+
|
|
16
|
+
png_config = ImageConfig(
|
|
17
|
+
format="PNG",
|
|
18
|
+
width=None, # No resizing - keep original width
|
|
19
|
+
height=None, # No resizing - keep original height
|
|
20
|
+
optimize=True, # Optimize PNG file size
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
screenshot_maker = ScreenshotMaker(config=png_config)
|
|
24
|
+
full_png_screenshot = screenshot_maker()
|
|
25
|
+
|
|
26
|
+
print(f"PNG screenshot dimensions: {full_png_screenshot.image.size}")
|
|
27
|
+
print(f"PNG screenshot size: {len(full_png_screenshot.read())} bytes")
|
|
28
|
+
return full_png_screenshot
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def example_load_and_compress(file_name):
|
|
32
|
+
"""Example 2: Load image from file and convert to compressed JPEG."""
|
|
33
|
+
print("\nExample 2: Load image from file and convert to JPEG")
|
|
34
|
+
|
|
35
|
+
# Load an existing screenshot
|
|
36
|
+
original_image = PILImage.from_file(file_name)
|
|
37
|
+
print(f"Original image dimensions: {original_image.image.size}")
|
|
38
|
+
|
|
39
|
+
# Create a config for compression
|
|
40
|
+
jpeg_config = ImageConfig(
|
|
41
|
+
format="JPEG",
|
|
42
|
+
quality=70, # Lower quality for smaller size
|
|
43
|
+
width=1260, # Resize to 1260px width
|
|
44
|
+
height=700, # Resize to 700px height
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# Transform the image
|
|
48
|
+
compressed_image = original_image.transform(jpeg_config)
|
|
49
|
+
compressed_bytes = compressed_image.read()
|
|
50
|
+
|
|
51
|
+
print(f"Compressed image dimensions: {compressed_image.image.size}")
|
|
52
|
+
print(f"Compressed JPEG size: {len(compressed_bytes)} bytes")
|
|
53
|
+
return compressed_image
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def example_with_single_step(file_name):
|
|
57
|
+
"""Example 3: Use compressed image with single_step."""
|
|
58
|
+
print("\nExample 3: Use with single_step")
|
|
59
|
+
|
|
60
|
+
# Load and compress image
|
|
61
|
+
image = PILImage.from_file(file_name)
|
|
62
|
+
print(f"Original image dimensions: {image.image.size}")
|
|
63
|
+
|
|
64
|
+
config = ImageConfig(format="JPEG", quality=85, width=1260, height=700)
|
|
65
|
+
compressed = image.transform(config)
|
|
66
|
+
print(f"Compressed image dimensions: {compressed.image.size}")
|
|
67
|
+
|
|
68
|
+
# Use with single_step
|
|
69
|
+
step = single_step(
|
|
70
|
+
task_description="Click the submit button",
|
|
71
|
+
screenshot=compressed,
|
|
72
|
+
api_key="your-api-key-here",
|
|
73
|
+
base_url="http://127.0.0.1:8000",
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
print(f"Task complete: {step.is_complete}")
|
|
77
|
+
return step
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def example_default_config():
|
|
81
|
+
"""Example 4: Default configuration (1260x700 JPEG with 85 quality)."""
|
|
82
|
+
print("\nExample 4: Default configuration")
|
|
83
|
+
|
|
84
|
+
default_maker = ScreenshotMaker() # Uses default ImageConfig
|
|
85
|
+
default_screenshot = default_maker()
|
|
86
|
+
|
|
87
|
+
print(f"Default screenshot dimensions: {default_screenshot.image.size}")
|
|
88
|
+
print(f"Default JPEG size: {len(default_screenshot.read())} bytes")
|
|
89
|
+
return default_screenshot
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
example_full_png_screenshot()
|
|
94
|
+
example_default_config()
|
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
# Licensed under the MIT License.
|
|
7
7
|
# -----------------------------------------------------------------------------
|
|
8
8
|
|
|
9
|
-
from oagi import single_step
|
|
9
|
+
from oagi import ScreenshotMaker, single_step
|
|
10
10
|
|
|
11
|
+
image_provider = ScreenshotMaker()
|
|
12
|
+
image = image_provider()
|
|
11
13
|
step = single_step(
|
|
12
14
|
task_description="Search weather with Google",
|
|
13
|
-
screenshot=
|
|
15
|
+
screenshot=image, # bytes or Path object or Image object
|
|
14
16
|
instruction="The operating system is macos", # optional instruction
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
api_key="sk-50DPDW87GnlNcH_0cAPRFZ4ntweCEdUrLEFIcQFaBhc",
|
|
18
|
+
base_url="http://127.0.0.1:8000",
|
|
17
19
|
)
|
|
18
20
|
|
|
19
21
|
print(step)
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "oagi"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.4.0"
|
|
8
8
|
description = "Official API of OpenAGI Foundation"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
@@ -29,6 +29,7 @@ dev = [
|
|
|
29
29
|
"ruff>=0.12.9",
|
|
30
30
|
"pytest>=8.0.0",
|
|
31
31
|
"pytest-mock>=3.12.0",
|
|
32
|
+
"pytest-asyncio>=0.21.0",
|
|
32
33
|
]
|
|
33
34
|
|
|
34
35
|
[tool.ruff.lint]
|
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
# Licensed under the MIT License.
|
|
7
7
|
# -----------------------------------------------------------------------------
|
|
8
8
|
|
|
9
|
+
from oagi.async_client import AsyncClient
|
|
10
|
+
from oagi.async_pyautogui_action_handler import AsyncPyautoguiActionHandler
|
|
11
|
+
from oagi.async_screenshot_maker import AsyncScreenshotMaker
|
|
12
|
+
from oagi.async_short_task import AsyncShortTask
|
|
13
|
+
from oagi.async_single_step import async_single_step
|
|
14
|
+
from oagi.async_task import AsyncTask
|
|
9
15
|
from oagi.exceptions import (
|
|
10
16
|
APIError,
|
|
11
17
|
AuthenticationError,
|
|
@@ -18,23 +24,45 @@ from oagi.exceptions import (
|
|
|
18
24
|
ServerError,
|
|
19
25
|
ValidationError,
|
|
20
26
|
)
|
|
21
|
-
from oagi.
|
|
27
|
+
from oagi.pil_image import PILImage
|
|
28
|
+
from oagi.pyautogui_action_handler import PyautoguiActionHandler, PyautoguiConfig
|
|
22
29
|
from oagi.screenshot_maker import ScreenshotMaker
|
|
23
30
|
from oagi.short_task import ShortTask
|
|
24
31
|
from oagi.single_step import single_step
|
|
25
32
|
from oagi.sync_client import ErrorDetail, ErrorResponse, LLMResponse, SyncClient
|
|
26
33
|
from oagi.task import Task
|
|
34
|
+
from oagi.types import (
|
|
35
|
+
AsyncActionHandler,
|
|
36
|
+
AsyncImageProvider,
|
|
37
|
+
ImageConfig,
|
|
38
|
+
)
|
|
27
39
|
|
|
28
40
|
__all__ = [
|
|
29
|
-
# Core classes
|
|
41
|
+
# Core sync classes
|
|
30
42
|
"Task",
|
|
31
43
|
"ShortTask",
|
|
32
44
|
"SyncClient",
|
|
45
|
+
# Core async classes
|
|
46
|
+
"AsyncTask",
|
|
47
|
+
"AsyncShortTask",
|
|
48
|
+
"AsyncClient",
|
|
33
49
|
# Functions
|
|
34
50
|
"single_step",
|
|
51
|
+
"async_single_step",
|
|
52
|
+
# Image classes
|
|
53
|
+
"PILImage",
|
|
35
54
|
# Handler classes
|
|
36
55
|
"PyautoguiActionHandler",
|
|
56
|
+
"PyautoguiConfig",
|
|
37
57
|
"ScreenshotMaker",
|
|
58
|
+
# Async handler classes
|
|
59
|
+
"AsyncPyautoguiActionHandler",
|
|
60
|
+
"AsyncScreenshotMaker",
|
|
61
|
+
# Async protocols
|
|
62
|
+
"AsyncActionHandler",
|
|
63
|
+
"AsyncImageProvider",
|
|
64
|
+
# Configuration
|
|
65
|
+
"ImageConfig",
|
|
38
66
|
# Response models
|
|
39
67
|
"LLMResponse",
|
|
40
68
|
"ErrorResponse",
|