|
15 | 15 | # this is used as the default value for optional parameters |
16 | 16 | OMIT = typing.cast(typing.Any, ...) |
17 | 17 |
|
18 | | -record_function = lambda *args, **kwargs: lambda fn: fn |
19 | | - |
20 | 18 |
|
21 | 19 | class MultiOn(BaseMultiOn): |
22 | 20 | """ |
@@ -54,37 +52,25 @@ def __init__( |
54 | 52 | agentops_api_key: typing.Optional[str] = os.getenv("AGENTOPS_API_KEY"), |
55 | 53 | **kwargs |
56 | 54 | ): |
57 | | - |
58 | 55 | super().__init__(*args, **kwargs) |
59 | | - self._agentops_api_key = agentops_api_key |
60 | | - |
61 | | - self.sessions = WrappedSessionsClient( |
62 | | - client_wrapper=self._client_wrapper, use_agentops=self._agentops_api_key is not None) |
63 | | - |
64 | | - if self._agentops_api_key is not None: |
| 56 | + self.sessions = WrappedSessionsClient(client_wrapper=self._client_wrapper) |
| 57 | + if agentops_api_key is not None: |
65 | 58 | agentops.init( |
66 | 59 | api_key=agentops_api_key, |
67 | 60 | parent_key=os.getenv("AGENTOPS_PARENT_KEY"), |
68 | 61 | auto_start_session=False, |
69 | 62 | ) |
70 | | - # Redefine the record_function globally |
71 | | - global record_function |
72 | | - record_function = agentops.record_function |
73 | | - # Apply the decorator at runtime |
74 | | - self.browse = record_function(event_name="browse")(self.browse) |
75 | | - self.retrieve = record_function( |
76 | | - event_name="retrieve")(self.retrieve) |
77 | 63 |
|
| 64 | + @agentops.record_function(event_name="browse") # type: ignore |
78 | 65 | @wraps_function(BaseMultiOn.browse) |
79 | 66 | def browse(self, *args, **kwargs) -> BrowseOutput: |
80 | | - if self._agentops_api_key is not None: |
81 | | - agentops.start_session(tags=["multion-sdk"]) |
| 67 | + agentops.start_session(tags=["multion-sdk"]) |
82 | 68 | return super().browse(*args, **kwargs) |
83 | 69 |
|
| 70 | + @agentops.record_function(event_name="retrieve") # type: ignore |
84 | 71 | @wraps_function(BaseMultiOn.retrieve) |
85 | 72 | def retrieve(self, *args, **kwargs) -> RetrieveOutput: |
86 | | - if self._agentops_api_key is not None: |
87 | | - agentops.start_session(tags=["multion-sdk"]) |
| 73 | + agentops.start_session(tags=["multion-sdk"]) |
88 | 74 | return super().retrieve(*args, **kwargs) |
89 | 75 |
|
90 | 76 |
|
@@ -125,31 +111,22 @@ def __init__( |
125 | 111 | **kwargs |
126 | 112 | ): |
127 | 113 | super().__init__(*args, **kwargs) |
128 | | - self._agentops_api_key = agentops_api_key |
129 | | - self.sessions = WrappedAsyncSessionsClient(client_wrapper=self._client_wrapper, |
130 | | - use_agentops=self._agentops_api_key is not None) |
| 114 | + self.sessions = WrappedAsyncSessionsClient(client_wrapper=self._client_wrapper) |
131 | 115 | if agentops_api_key is not None: |
132 | 116 | agentops.init( |
133 | 117 | api_key=agentops_api_key, |
134 | 118 | parent_key=os.getenv("AGENTOPS_PARENT_KEY"), |
135 | 119 | auto_start_session=False, |
136 | 120 | ) |
137 | | - # If agentops is set, we need to wrap the record function |
138 | | - global record_function |
139 | | - record_function = agentops.record_function |
140 | | - |
141 | | - record_function = agentops.record_function |
142 | 121 |
|
143 | | - @record_function(event_name="browse") # type: ignore |
| 122 | + @agentops.record_function(event_name="browse") # type: ignore |
144 | 123 | @wraps_function(AsyncBaseMultiOn.browse) |
145 | 124 | async def browse(self, *args, **kwargs) -> BrowseOutput: |
146 | | - if self._agentops_api_key is not None: |
147 | | - agentops.start_session(tags=["multion-sdk"]) |
| 125 | + agentops.start_session(tags=["multion-sdk"]) |
148 | 126 | return await super().browse(*args, **kwargs) |
149 | 127 |
|
150 | | - @record_function(event_name="retrieve") # type: ignore |
| 128 | + @agentops.record_function(event_name="retrieve") # type: ignore |
151 | 129 | @wraps_function(BaseMultiOn.retrieve) |
152 | 130 | async def retrieve(self, *args, **kwargs) -> RetrieveOutput: |
153 | | - if self._agentops_api_key is not None: |
154 | | - agentops.start_session(tags=["multion-sdk"]) |
| 131 | + agentops.start_session(tags=["multion-sdk"]) |
155 | 132 | return await super().retrieve(*args, **kwargs) |
0 commit comments