optexity 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl

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.
Files changed (77) hide show
  1. optexity/cli.py +1 -1
  2. optexity/examples/__init__.py +0 -0
  3. optexity/examples/add_example.py +88 -0
  4. optexity/examples/download_pdf_url.py +29 -0
  5. optexity/examples/extract_price_stockanalysis.py +44 -0
  6. optexity/examples/file_upload.py +59 -0
  7. optexity/examples/i94.py +126 -0
  8. optexity/examples/i94_travel_history.py +126 -0
  9. optexity/examples/peachstate_medicaid.py +201 -0
  10. optexity/examples/supabase_login.py +75 -0
  11. optexity/inference/__init__.py +0 -0
  12. optexity/inference/agents/__init__.py +0 -0
  13. optexity/inference/agents/error_handler/__init__.py +0 -0
  14. optexity/inference/agents/error_handler/error_handler.py +39 -0
  15. optexity/inference/agents/error_handler/prompt.py +60 -0
  16. optexity/inference/agents/index_prediction/__init__.py +0 -0
  17. optexity/inference/agents/index_prediction/action_prediction_locator_axtree.py +45 -0
  18. optexity/inference/agents/index_prediction/prompt.py +14 -0
  19. optexity/inference/agents/select_value_prediction/__init__.py +0 -0
  20. optexity/inference/agents/select_value_prediction/prompt.py +20 -0
  21. optexity/inference/agents/select_value_prediction/select_value_prediction.py +39 -0
  22. optexity/inference/agents/two_fa_extraction/__init__.py +0 -0
  23. optexity/inference/agents/two_fa_extraction/prompt.py +23 -0
  24. optexity/inference/agents/two_fa_extraction/two_fa_extraction.py +47 -0
  25. optexity/inference/child_process.py +251 -0
  26. optexity/inference/core/__init__.py +0 -0
  27. optexity/inference/core/interaction/__init__.py +0 -0
  28. optexity/inference/core/interaction/handle_agentic_task.py +79 -0
  29. optexity/inference/core/interaction/handle_check.py +57 -0
  30. optexity/inference/core/interaction/handle_click.py +79 -0
  31. optexity/inference/core/interaction/handle_command.py +261 -0
  32. optexity/inference/core/interaction/handle_input.py +76 -0
  33. optexity/inference/core/interaction/handle_keypress.py +16 -0
  34. optexity/inference/core/interaction/handle_select.py +109 -0
  35. optexity/inference/core/interaction/handle_select_utils.py +132 -0
  36. optexity/inference/core/interaction/handle_upload.py +59 -0
  37. optexity/inference/core/interaction/utils.py +81 -0
  38. optexity/inference/core/logging.py +406 -0
  39. optexity/inference/core/run_assertion.py +55 -0
  40. optexity/inference/core/run_automation.py +463 -0
  41. optexity/inference/core/run_extraction.py +240 -0
  42. optexity/inference/core/run_interaction.py +254 -0
  43. optexity/inference/core/run_python_script.py +20 -0
  44. optexity/inference/core/run_two_fa.py +120 -0
  45. optexity/inference/core/two_factor_auth/__init__.py +0 -0
  46. optexity/inference/infra/__init__.py +0 -0
  47. optexity/inference/infra/browser.py +455 -0
  48. optexity/inference/infra/browser_extension.py +20 -0
  49. optexity/inference/models/__init__.py +22 -0
  50. optexity/inference/models/gemini.py +113 -0
  51. optexity/inference/models/human.py +20 -0
  52. optexity/inference/models/llm_model.py +210 -0
  53. optexity/inference/run_local.py +200 -0
  54. optexity/schema/__init__.py +0 -0
  55. optexity/schema/actions/__init__.py +0 -0
  56. optexity/schema/actions/assertion_action.py +66 -0
  57. optexity/schema/actions/extraction_action.py +143 -0
  58. optexity/schema/actions/interaction_action.py +330 -0
  59. optexity/schema/actions/misc_action.py +18 -0
  60. optexity/schema/actions/prompts.py +27 -0
  61. optexity/schema/actions/two_fa_action.py +24 -0
  62. optexity/schema/automation.py +432 -0
  63. optexity/schema/callback.py +16 -0
  64. optexity/schema/inference.py +87 -0
  65. optexity/schema/memory.py +100 -0
  66. optexity/schema/task.py +212 -0
  67. optexity/schema/token_usage.py +48 -0
  68. optexity/utils/__init__.py +0 -0
  69. optexity/utils/settings.py +54 -0
  70. optexity/utils/utils.py +76 -0
  71. {optexity-0.1.2.dist-info → optexity-0.1.4.dist-info}/METADATA +20 -36
  72. optexity-0.1.4.dist-info/RECORD +80 -0
  73. optexity-0.1.2.dist-info/RECORD +0 -11
  74. {optexity-0.1.2.dist-info → optexity-0.1.4.dist-info}/WHEEL +0 -0
  75. {optexity-0.1.2.dist-info → optexity-0.1.4.dist-info}/entry_points.txt +0 -0
  76. {optexity-0.1.2.dist-info → optexity-0.1.4.dist-info}/licenses/LICENSE +0 -0
  77. {optexity-0.1.2.dist-info → optexity-0.1.4.dist-info}/top_level.txt +0 -0
optexity/cli.py CHANGED
@@ -64,7 +64,7 @@ def main() -> None:
64
64
  "inference", help="Run Optexity inference server"
65
65
  )
66
66
  inference_cmd.add_argument("--host", default="0.0.0.0")
67
- inference_cmd.add_argument("--port", type=int, required=True)
67
+ inference_cmd.add_argument("--port", type=int, default=9000)
68
68
  inference_cmd.add_argument(
69
69
  "--child_process_id", "--child-process-id", type=int, default=0
70
70
  )
File without changes
@@ -0,0 +1,88 @@
1
+ import argparse
2
+ import logging
3
+ from urllib.parse import urljoin
4
+
5
+ import httpx
6
+
7
+ from optexity.examples import (
8
+ download_pdf_url,
9
+ file_upload,
10
+ i94,
11
+ i94_travel_history,
12
+ peachstate_medicaid,
13
+ supabase_login,
14
+ )
15
+ from optexity.utils.settings import Settings
16
+
17
+ logger = logging.getLogger(__name__)
18
+ settings = Settings()
19
+
20
+ logger.setLevel(logging.INFO)
21
+
22
+
23
+ def main(args):
24
+ if args.example == "i94":
25
+ example = i94
26
+ elif args.example == "i94_travel_history":
27
+ example = i94_travel_history
28
+ elif args.example == "peachstate_medicaid":
29
+ example = peachstate_medicaid
30
+ elif args.example == "supabase_login":
31
+ example = supabase_login
32
+ elif args.example == "download_pdf_url":
33
+ example = download_pdf_url
34
+ elif args.example == "file_upload":
35
+ example = file_upload
36
+ else:
37
+ raise ValueError(f"Invalid example: {args.example}")
38
+ try:
39
+ logger.info(f"➕ Adding example: {args.example}")
40
+ headers = {"x-api-key": settings.API_KEY}
41
+ with httpx.Client() as client:
42
+ response = client.post(
43
+ urljoin(
44
+ settings.SERVER_URL,
45
+ (
46
+ settings.ADD_EXAMPLE_ENDPOINT
47
+ if not args.update
48
+ else settings.UPDATE_EXAMPLE_ENDPOINT
49
+ ),
50
+ ),
51
+ headers=headers,
52
+ json={
53
+ "automation": example.automation.model_dump(
54
+ exclude_none=True, exclude_defaults=True
55
+ ),
56
+ "description": example.description,
57
+ "endpoint_name": example.endpoint_name,
58
+ },
59
+ )
60
+ response.raise_for_status()
61
+ logger.info(f"✓ Example added successfully: {response.json()}")
62
+ except Exception as e:
63
+ logger.error(f"❌ Error adding example: {response.json()}")
64
+
65
+
66
+ if __name__ == "__main__":
67
+ parser = argparse.ArgumentParser()
68
+ parser.add_argument(
69
+ "--example",
70
+ type=str,
71
+ choices=[
72
+ "i94",
73
+ "i94_travel_history",
74
+ "peachstate_medicaid",
75
+ "supabase_login",
76
+ "download_pdf_url",
77
+ "file_upload",
78
+ ],
79
+ required=True,
80
+ )
81
+ parser.add_argument(
82
+ "--update",
83
+ action="store_true",
84
+ default=False,
85
+ )
86
+ args = parser.parse_args()
87
+
88
+ main(args)
@@ -0,0 +1,29 @@
1
+ from optexity.schema.automation import Automation
2
+
3
+ description = "Download PDF URL Example"
4
+ endpoint_name = "download_pdf_url"
5
+ automation_json = {
6
+ "url": "about:blank",
7
+ "parameters": {
8
+ "input_parameters": {
9
+ "pdf_url": ["https://s24.q4cdn.com/216390268/files/doc_downloads/test.pdf"]
10
+ },
11
+ "generated_parameters": {},
12
+ },
13
+ "nodes": [
14
+ {
15
+ "type": "action_node",
16
+ "interaction_action": {"go_to_url": {"url": "{pdf_url[0]}"}},
17
+ "end_sleep_time": 1.0,
18
+ },
19
+ {
20
+ "type": "action_node",
21
+ "interaction_action": {
22
+ "download_url_as_pdf": {"download_filename": "example.pdf"}
23
+ },
24
+ "end_sleep_time": 1.0,
25
+ },
26
+ ],
27
+ }
28
+
29
+ automation = Automation.model_validate(automation_json)
@@ -0,0 +1,44 @@
1
+ from optexity.schema.automation import Automation
2
+
3
+ description = "Extract stock price from StockAnalysis"
4
+ endpoint_name = "extract_price_stockanalysis"
5
+ automation_json = {
6
+ "url": "https://stockanalysis.com/",
7
+ "parameters": {
8
+ "input_parameters": {"stock_ticker": ["AAPL"]},
9
+ "generated_parameters": {},
10
+ },
11
+ "nodes": [
12
+ {
13
+ "interaction_action": {
14
+ "input_text": {
15
+ "command": 'locator("#search-header")',
16
+ "prompt_instructions": "Fill the input field with ID 'search-header' with the value of the 'stock_ticker' variable.",
17
+ "input_text": "{stock_ticker[0]}",
18
+ }
19
+ }
20
+ },
21
+ {
22
+ "interaction_action": {
23
+ "click_element": {
24
+ "prompt_instructions": "Click on the link with the name of the stock equivalent for {stock_ticker[0]}."
25
+ }
26
+ }
27
+ },
28
+ {
29
+ "extraction_action": {
30
+ "llm": {
31
+ "source": ["screenshot"],
32
+ "extraction_format": {
33
+ "stock_name": "str",
34
+ "stock_price": "str",
35
+ "stock_symbol": "str",
36
+ },
37
+ "extraction_instructions": "Extract the stock price, stock name, and stock symbol from the webpage.",
38
+ }
39
+ }
40
+ },
41
+ ],
42
+ }
43
+
44
+ automation = Automation.model_validate(automation_json)
@@ -0,0 +1,59 @@
1
+ from optexity.schema.automation import Automation
2
+
3
+ description = "File Upload Example"
4
+ endpoint_name = "file_upload"
5
+ automation_json = {
6
+ "url": "https://www.azurespeed.com/Azure/UploadLargeFile",
7
+ "parameters": {
8
+ "input_parameters": {
9
+ "target_region_option": ["test_region"],
10
+ "file_path": ["/path/to/test/file.txt"],
11
+ },
12
+ "generated_parameters": {},
13
+ },
14
+ "nodes": [
15
+ {
16
+ "type": "action_node",
17
+ "interaction_action": {
18
+ "select_option": {
19
+ "command": 'get_by_label("Target region")',
20
+ "prompt_instructions": "Select an option from the field labeled 'Target region' with the value from the 'target_region_option' variable.",
21
+ "select_values": ["{target_region_option[0]}"],
22
+ }
23
+ },
24
+ "end_sleep_time": 1.0,
25
+ },
26
+ {
27
+ "type": "action_node",
28
+ "interaction_action": {
29
+ "upload_file": {
30
+ "command": 'get_by_role("button", name="Test file")',
31
+ "prompt_instructions": "Click on the 'Test file' button.",
32
+ "file_path": "{file_path[0]}",
33
+ }
34
+ },
35
+ "end_sleep_time": 1.0,
36
+ },
37
+ {
38
+ "type": "action_node",
39
+ "interaction_action": {
40
+ "click_element": {
41
+ "command": 'get_by_role("button", name="Start test")',
42
+ "prompt_instructions": "Click the 'Start test' button",
43
+ }
44
+ },
45
+ "end_sleep_time": 1.0,
46
+ },
47
+ {
48
+ "type": "action_node",
49
+ "assertion_action": {
50
+ "llm": {
51
+ "extraction_instructions": "Check if the file upload was successful"
52
+ }
53
+ },
54
+ "before_sleep_time": 10.0,
55
+ "end_sleep_time": 0.0,
56
+ },
57
+ ],
58
+ }
59
+ automation = Automation.model_validate(automation_json)
@@ -0,0 +1,126 @@
1
+ from optexity.schema.automation import Automation
2
+
3
+ description = "I94 Example"
4
+ endpoint_name = "i94"
5
+ automation_json = {
6
+ "url": "https://i94.cbp.dhs.gov/search/recent-search",
7
+ "nodes": [
8
+ {
9
+ "type": "action_node",
10
+ "end_sleep_time": 1,
11
+ "before_sleep_time": 3,
12
+ "python_script_action": {
13
+ "execution_code": 'async def code_fn(page):\n print("entering code_fn")\n await page.evaluate(\n """ const el = document.querySelector(\'mat-dialog-content\'); if (el) el.scrollTop = el.scrollHeight;"""\n )\n print("exiting code_fn")\n'
14
+ },
15
+ },
16
+ {
17
+ "type": "action_node",
18
+ "end_sleep_time": 1,
19
+ "interaction_action": {
20
+ "click_element": {
21
+ "command": 'get_by_role("button", name="I ACKNOWLEDGE AND AGREE")',
22
+ "prompt_instructions": "Click the I ACKNOWLEDGE AND AGREE button",
23
+ }
24
+ },
25
+ },
26
+ {
27
+ "type": "action_node",
28
+ "end_sleep_time": 1,
29
+ "interaction_action": {
30
+ "input_text": {
31
+ "command": 'get_by_role("textbox", name="Please enter your first name")',
32
+ "input_text": "{first_name[0]}",
33
+ "prompt_instructions": "Enter the First Name",
34
+ }
35
+ },
36
+ },
37
+ {
38
+ "type": "action_node",
39
+ "end_sleep_time": 1,
40
+ "interaction_action": {
41
+ "input_text": {
42
+ "command": 'get_by_role("textbox", name="Please enter your last name")',
43
+ "input_text": "{last_name[0]}",
44
+ "prompt_instructions": "Enter the Last Name",
45
+ }
46
+ },
47
+ },
48
+ {
49
+ "type": "action_node",
50
+ "end_sleep_time": 1,
51
+ "interaction_action": {
52
+ "input_text": {
53
+ "command": 'get_by_role("textbox", name="Date of Birth")',
54
+ "input_text": "{date_of_birth[0]}",
55
+ "prompt_instructions": "Enter the Date of Birth",
56
+ }
57
+ },
58
+ },
59
+ {
60
+ "type": "action_node",
61
+ "end_sleep_time": 1,
62
+ "interaction_action": {
63
+ "input_text": {
64
+ "command": 'get_by_role("textbox", name="Please enter your document")',
65
+ "input_text": "{document_number[0]}",
66
+ "prompt_instructions": "Enter the Document Number",
67
+ }
68
+ },
69
+ },
70
+ {
71
+ "type": "action_node",
72
+ "end_sleep_time": 1,
73
+ "interaction_action": {
74
+ "input_text": {
75
+ "command": 'get_by_role("combobox", name="Please enter your document")',
76
+ "input_text": "{nationality[0]}",
77
+ "prompt_instructions": "Enter the Nationality",
78
+ }
79
+ },
80
+ },
81
+ {
82
+ "type": "action_node",
83
+ "end_sleep_time": 1,
84
+ "interaction_action": {
85
+ "click_element": {
86
+ "prompt_instructions": "Select {nationality[0]} from the options. Be careful to select the correct option. which will be of the format `nationality (code)`"
87
+ }
88
+ },
89
+ },
90
+ {
91
+ "type": "action_node",
92
+ "end_sleep_time": 1,
93
+ "interaction_action": {
94
+ "click_element": {
95
+ "command": 'get_by_role("button", name="Click to submit the form")',
96
+ "prompt_instructions": "Click the Submit button",
97
+ }
98
+ },
99
+ },
100
+ {
101
+ "type": "action_node",
102
+ "end_sleep_time": 0,
103
+ "before_sleep_time": 3,
104
+ "extraction_action": {
105
+ "network_call": {
106
+ "extract_from": "response",
107
+ "url_pattern": "https://i94.cbp.dhs.gov/api/services/i94/recent",
108
+ }
109
+ },
110
+ },
111
+ ],
112
+ "parameters": {
113
+ "input_parameters": {
114
+ "last_name": ["Last Name"],
115
+ "first_name": ["First Name"],
116
+ "nationality": ["IND"],
117
+ "date_of_birth": ["MM/DD/YYYY"],
118
+ "document_number": ["Document Number"],
119
+ },
120
+ "generated_parameters": {},
121
+ },
122
+ "browser_channel": "chrome",
123
+ }
124
+
125
+
126
+ automation = Automation.model_validate(automation_json)
@@ -0,0 +1,126 @@
1
+ from optexity.schema.automation import Automation
2
+
3
+ description = "I94 Travel History Example"
4
+ endpoint_name = "get_i94_travel_history"
5
+ automation_json = {
6
+ "url": "https://i94.cbp.dhs.gov/search/history-search",
7
+ "nodes": [
8
+ {
9
+ "type": "action_node",
10
+ "end_sleep_time": 1,
11
+ "before_sleep_time": 3,
12
+ "python_script_action": {
13
+ "execution_code": 'async def code_fn(page):\n print("entering code_fn")\n await page.evaluate(\n """ const el = document.querySelector(\'mat-dialog-content\'); if (el) el.scrollTop = el.scrollHeight;"""\n )\n print("exiting code_fn")\n'
14
+ },
15
+ },
16
+ {
17
+ "type": "action_node",
18
+ "end_sleep_time": 1,
19
+ "interaction_action": {
20
+ "click_element": {
21
+ "command": 'get_by_role("button", name="I ACKNOWLEDGE AND AGREE")',
22
+ "prompt_instructions": "Click the I ACKNOWLEDGE AND AGREE button",
23
+ }
24
+ },
25
+ },
26
+ {
27
+ "type": "action_node",
28
+ "end_sleep_time": 1,
29
+ "interaction_action": {
30
+ "input_text": {
31
+ "command": 'get_by_role("textbox", name="Please enter your first name")',
32
+ "input_text": "{first_name[0]}",
33
+ "prompt_instructions": "Enter the First Name",
34
+ }
35
+ },
36
+ },
37
+ {
38
+ "type": "action_node",
39
+ "end_sleep_time": 1,
40
+ "interaction_action": {
41
+ "input_text": {
42
+ "command": 'get_by_role("textbox", name="Please enter your last name")',
43
+ "input_text": "{last_name[0]}",
44
+ "prompt_instructions": "Enter the Last Name",
45
+ }
46
+ },
47
+ },
48
+ {
49
+ "type": "action_node",
50
+ "end_sleep_time": 1,
51
+ "interaction_action": {
52
+ "input_text": {
53
+ "command": 'get_by_role("textbox", name="Date of Birth")',
54
+ "input_text": "{date_of_birth[0]}",
55
+ "prompt_instructions": "Enter the Date of Birth",
56
+ }
57
+ },
58
+ },
59
+ {
60
+ "type": "action_node",
61
+ "end_sleep_time": 1,
62
+ "interaction_action": {
63
+ "input_text": {
64
+ "command": 'get_by_role("textbox", name="Please enter your document")',
65
+ "input_text": "{document_number[0]}",
66
+ "prompt_instructions": "Enter the Document Number",
67
+ }
68
+ },
69
+ },
70
+ {
71
+ "type": "action_node",
72
+ "end_sleep_time": 1,
73
+ "interaction_action": {
74
+ "input_text": {
75
+ "command": 'get_by_role("combobox", name="Please enter your document")',
76
+ "input_text": "{nationality[0]}",
77
+ "prompt_instructions": "Enter the Nationality",
78
+ }
79
+ },
80
+ },
81
+ {
82
+ "type": "action_node",
83
+ "end_sleep_time": 1,
84
+ "interaction_action": {
85
+ "click_element": {
86
+ "prompt_instructions": "Select {nationality[0]} from the options. Be careful to select the correct option. which will be of the format `nationality (code)`"
87
+ }
88
+ },
89
+ },
90
+ {
91
+ "type": "action_node",
92
+ "end_sleep_time": 1,
93
+ "interaction_action": {
94
+ "click_element": {
95
+ "command": 'get_by_role("button", name="Click to submit the form")',
96
+ "prompt_instructions": "Click the Submit button",
97
+ }
98
+ },
99
+ },
100
+ {
101
+ "type": "action_node",
102
+ "end_sleep_time": 0,
103
+ "before_sleep_time": 3,
104
+ "extraction_action": {
105
+ "network_call": {
106
+ "extract_from": "response",
107
+ "url_pattern": "https://i94.cbp.dhs.gov/api/services/travel/history",
108
+ }
109
+ },
110
+ },
111
+ ],
112
+ "parameters": {
113
+ "input_parameters": {
114
+ "last_name": ["Last Name"],
115
+ "first_name": ["First Name"],
116
+ "nationality": ["IND"],
117
+ "date_of_birth": ["MM/DD/YYYY"],
118
+ "document_number": ["Document Number"],
119
+ },
120
+ "generated_parameters": {},
121
+ },
122
+ "browser_channel": "chrome",
123
+ }
124
+
125
+
126
+ automation = Automation.model_validate(automation_json)