File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
sentry_sdk/integrations/openai_agents/patches Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change 1+ import copy
12from functools import wraps
23
34from sentry_sdk .integrations import DidNotEnable
@@ -31,8 +32,9 @@ def _create_get_model_wrapper(original_get_model):
3132 def wrapped_get_model (cls , agent , run_config ):
3233 # type: (agents.Runner, agents.Agent, agents.RunConfig) -> agents.Model
3334
34- model = original_get_model (agent , run_config )
35- original_get_response = model .get_response
35+ # copy the model to double patching its methods. We use copy on purpose here (instead of deepcopy)
36+ # because we only patch its direct methods, all underlying data can remain unchanged.
37+ model = copy .copy (original_get_model (agent , run_config ))
3638
3739 # Wrap _fetch_response if it exists (for OpenAI models) to capture raw response model
3840 if hasattr (model , "_fetch_response" ):
@@ -48,6 +50,8 @@ async def wrapped_fetch_response(*args, **kwargs):
4850
4951 model ._fetch_response = wrapped_fetch_response
5052
53+ original_get_response = model .get_response
54+
5155 @wraps (original_get_response )
5256 async def wrapped_get_response (* args , ** kwargs ):
5357 # type: (*Any, **Any) -> Any
You can’t perform that action at this time.
0 commit comments