optimizely-opal.opal-tools-sdk 0.1.0.dev0__py3-none-any.whl → 0.1.2.dev0__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.
@@ -75,7 +75,11 @@ def tool(name: str, description: str, auth_requirements: Optional[List[Dict[str,
75
75
  param_type = ParameterType.dictionary
76
76
 
77
77
  # Determine if required
78
- required = field_info.default is ... if hasattr(field_info, 'default') else True
78
+ field_info_extra = getattr(field_info, "json_schema_extra") or {}
79
+ if "required" in field_info_extra:
80
+ required = field_info_extra["required"]
81
+ else:
82
+ required = field_info.default is ... if hasattr(field_info, 'default') else True
79
83
 
80
84
  # Get description
81
85
  description_text = ""
opal_tools_sdk/service.py CHANGED
@@ -132,6 +132,11 @@ class ToolsService:
132
132
  if auth_data:
133
133
  print(f"Auth data provided for provider: {auth_data.get('provider', 'unknown')}")
134
134
 
135
+ # Extract environment data if available
136
+ environment = body.get("environment", {})
137
+ if environment:
138
+ print(f"Environment data provided: {environment}")
139
+
135
140
  print(f"Extracted parameters: {params}")
136
141
 
137
142
  # Get the parameter model from handler's signature
@@ -139,24 +144,27 @@ class ToolsService:
139
144
  param_name = list(sig.parameters.keys())[0]
140
145
  param_type = get_type_hints(handler).get(param_name)
141
146
 
142
- # Check signature to see if it accepts auth data
143
- accepts_auth = len(sig.parameters) > 1
144
147
 
148
+ args = []
149
+ kwargs = {}
145
150
  if param_type:
146
151
  # Create instance of param model
147
152
  model_instance = param_type(**params)
148
- if accepts_auth:
149
- # Call with auth data if the handler accepts it
150
- result = await handler(model_instance, auth_data)
151
- else:
152
- # Call without auth data
153
- result = await handler(model_instance)
153
+ args.append(model_instance)
154
154
  else:
155
155
  # Fall back if type hints not available
156
- if accepts_auth:
157
- result = await handler(BaseModel(**params), auth_data)
158
- else:
159
- result = await handler(BaseModel(**params))
156
+ args.append(BaseModel(**params))
157
+
158
+ # Check signature to see if it accepts other values
159
+
160
+ # TODO: Change this to "auth"
161
+ if auth_param := sig.parameters.get("auth_data"):
162
+ kwargs[auth_param.name] = auth_data
163
+
164
+ if environment_param := sig.parameters.get("environment"):
165
+ kwargs[environment_param.name] = environment
166
+
167
+ result = await handler(*args, **kwargs)
160
168
 
161
169
  print(f"Tool {name} returned: {result}")
162
170
  return result
@@ -0,0 +1,138 @@
1
+ Metadata-Version: 2.4
2
+ Name: optimizely-opal.opal-tools-sdk
3
+ Version: 0.1.2.dev0
4
+ Summary: SDK for creating Opal-compatible tools services
5
+ Home-page: https://github.com/optimizely/opal-tools-sdk
6
+ Author: Optimizely
7
+ Author-email: Optimizely <opal-team@optimizely.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/optimizely/opal-tools-sdk
10
+ Project-URL: Bug Tracker, https://github.com/optimizely/opal-tools-sdk/issues
11
+ Keywords: opal,tools,sdk,ai,llm
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: fastapi>=0.100.0
19
+ Requires-Dist: pydantic>=2.0.0
20
+ Requires-Dist: httpx>=0.24.1
21
+ Dynamic: author
22
+ Dynamic: home-page
23
+ Dynamic: requires-python
24
+
25
+ # Opal Tools SDK for Python
26
+
27
+ This SDK simplifies the creation of tools services compatible with the Opal Tools Management Service.
28
+
29
+ ## Features
30
+
31
+ - Easy definition of tool functions with decorators
32
+ - Automatic generation of discovery endpoints
33
+ - Parameter validation and type checking
34
+ - Authentication helpers
35
+ - FastAPI integration
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ pip install optimizely-opal.opal-tools-sdk
41
+ ```
42
+
43
+ Note: While the package is installed as `optimizely-opal.opal-tools-sdk`, you'll still import it in your code as `opal_tools_sdk`:
44
+
45
+ ```python
46
+ # Import using the package name
47
+ from opal_tools_sdk import ToolsService, tool
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ```python
53
+ from opal_tools_sdk import ToolsService, tool
54
+ from pydantic import BaseModel
55
+ from fastapi import FastAPI
56
+
57
+ app = FastAPI()
58
+ tools_service = ToolsService(app)
59
+
60
+ class WeatherParameters(BaseModel):
61
+ location: str
62
+ units: str = "metric"
63
+
64
+ @tool("get_weather", "Gets current weather for a location")
65
+ async def get_weather(parameters: WeatherParameters):
66
+ # Implementation...
67
+ return {"temperature": 22, "condition": "sunny"}
68
+
69
+ # Discovery endpoint is automatically created at /discovery
70
+ ```
71
+
72
+ ## Authentication
73
+
74
+ The SDK provides two ways to require authentication for your tools:
75
+
76
+ ### 1. Using the `@requires_auth` decorator
77
+
78
+ ```python
79
+ from opal_tools_sdk import ToolsService, tool
80
+ from opal_tools_sdk.auth import requires_auth
81
+ from pydantic import BaseModel
82
+ from fastapi import FastAPI
83
+
84
+ app = FastAPI()
85
+ tools_service = ToolsService(app)
86
+
87
+ class CalendarParameters(BaseModel):
88
+ date: str
89
+ timezone: str = "UTC"
90
+
91
+ # Single authentication requirement
92
+ @requires_auth(provider="google", scope_bundle="calendar", required=True)
93
+ @tool("get_calendar_events", "Gets calendar events for a date")
94
+ async def get_calendar_events(parameters: CalendarParameters, auth_data=None):
95
+ # The auth_data parameter contains authentication information
96
+ token = auth_data.get("credentials", {}).get("token", "")
97
+
98
+ # Use the token to make authenticated requests
99
+ # ...
100
+
101
+ return {"events": ["Meeting at 10:00", "Lunch at 12:00"]}
102
+
103
+ # Multiple authentication requirements (tool can work with either provider)
104
+ @requires_auth(provider="google", scope_bundle="calendar", required=True)
105
+ @requires_auth(provider="microsoft", scope_bundle="outlook", required=True)
106
+ @tool("get_calendar_availability", "Check calendar availability")
107
+ async def get_calendar_availability(parameters: CalendarParameters, auth_data=None):
108
+ provider = auth_data.get("provider", "")
109
+ token = auth_data.get("credentials", {}).get("token", "")
110
+
111
+ if provider == "google":
112
+ # Use Google Calendar API
113
+ pass
114
+ elif provider == "microsoft":
115
+ # Use Microsoft Outlook API
116
+ pass
117
+
118
+ return {"available": True, "provider_used": provider}
119
+ ```
120
+
121
+ ### 2. Specifying auth requirements in the `@tool` decorator
122
+
123
+ ```python
124
+ @tool(
125
+ "get_email",
126
+ "Gets emails from the user's inbox",
127
+ auth_requirements=[
128
+ {"provider": "google", "scope_bundle": "gmail", "required": True}
129
+ ]
130
+ )
131
+ async def get_email(parameters: EmailParameters, auth_data=None):
132
+ # Implementation...
133
+ return {"emails": ["Email 1", "Email 2"]}
134
+ ```
135
+
136
+ ## Documentation
137
+
138
+ See full documentation for more examples and configuration options.
@@ -0,0 +1,10 @@
1
+ opal_tools_sdk/__init__.py,sha256=Eu141xM3QVq1O_BLGZS9m_asU1b_KaOApFtwvaYll6E,170
2
+ opal_tools_sdk/_registry.py,sha256=YE3eD4kcS09QDe4RccBYAzXPo9znEU7fblrsB-g3o-Y,67
3
+ opal_tools_sdk/auth.py,sha256=9aMiZv6n6_iu7hQA0sKg4hgNr5DzYFFuP0SWUoZf_Vw,1520
4
+ opal_tools_sdk/decorators.py,sha256=uZ11AY5QUxhi61vfZ3iJTtFoXg-uA0cknx4EWTdDTCo,5276
5
+ opal_tools_sdk/models.py,sha256=fa2hhnZ2GTz6xqhGTNyqyIQj_rBE1UFQxsJ4KfApCiU,2123
6
+ opal_tools_sdk/service.py,sha256=KBqdBHYJ5wgxky0mSv0NJPbbzVhq4YSafgaTbsndTrE,6914
7
+ optimizely_opal_opal_tools_sdk-0.1.2.dev0.dist-info/METADATA,sha256=M7L5-Pegr5M7UpvXKjLvOMQPz9nBjMTQScWkB7Waqs0,4115
8
+ optimizely_opal_opal_tools_sdk-0.1.2.dev0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ optimizely_opal_opal_tools_sdk-0.1.2.dev0.dist-info/top_level.txt,sha256=nCJ5PxF0rgoV6yNJvvuUaZPx4D3EWkl7gpu-6xafH1E,15
10
+ optimizely_opal_opal_tools_sdk-0.1.2.dev0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.3.1)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,24 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: optimizely-opal.opal-tools-sdk
3
- Version: 0.1.0.dev0
4
- Summary: SDK for creating Opal-compatible tools services
5
- Home-page: https://github.com/optimizely/opal-tools-sdk
6
- Author: Optimizely
7
- Author-email: opal-team@optimizely.com
8
- Keywords: opal,tools,sdk,ai,llm
9
- Classifier: Development Status :: 3 - Alpha
10
- Classifier: Intended Audience :: Developers
11
- Classifier: Programming Language :: Python :: 3.10
12
- Classifier: License :: OSI Approved :: MIT License
13
- Requires-Python: >=3.10
14
- Requires-Dist: fastapi>=0.100.0
15
- Requires-Dist: pydantic>=2.0.0
16
- Requires-Dist: httpx>=0.24.1
17
- Dynamic: author
18
- Dynamic: author-email
19
- Dynamic: classifier
20
- Dynamic: home-page
21
- Dynamic: keywords
22
- Dynamic: requires-dist
23
- Dynamic: requires-python
24
- Dynamic: summary
@@ -1,10 +0,0 @@
1
- opal_tools_sdk/__init__.py,sha256=Eu141xM3QVq1O_BLGZS9m_asU1b_KaOApFtwvaYll6E,170
2
- opal_tools_sdk/_registry.py,sha256=YE3eD4kcS09QDe4RccBYAzXPo9znEU7fblrsB-g3o-Y,67
3
- opal_tools_sdk/auth.py,sha256=9aMiZv6n6_iu7hQA0sKg4hgNr5DzYFFuP0SWUoZf_Vw,1520
4
- opal_tools_sdk/decorators.py,sha256=a_CJcA11RW8eAt2xRGXZane_HvTZqR7wfhn-6WFgjOY,5057
5
- opal_tools_sdk/models.py,sha256=fa2hhnZ2GTz6xqhGTNyqyIQj_rBE1UFQxsJ4KfApCiU,2123
6
- opal_tools_sdk/service.py,sha256=tVaQKFpTX778UUWoczlM2WHSiUXqdYtYSKgTdqTH1Z0,6756
7
- optimizely_opal_opal_tools_sdk-0.1.0.dev0.dist-info/METADATA,sha256=EoIwGaRzuaWjMlPwej56DdeTW6IcYtJDjttLigMu9ts,748
8
- optimizely_opal_opal_tools_sdk-0.1.0.dev0.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
9
- optimizely_opal_opal_tools_sdk-0.1.0.dev0.dist-info/top_level.txt,sha256=nCJ5PxF0rgoV6yNJvvuUaZPx4D3EWkl7gpu-6xafH1E,15
10
- optimizely_opal_opal_tools_sdk-0.1.0.dev0.dist-info/RECORD,,