Skip to content

Commit

Permalink
Merge pull request #71 from AgentOps-AI/70-openai-versions-100-are-no…
Browse files Browse the repository at this point in the history
…t-recorded

fixed patcher
  • Loading branch information
areibman authored Jan 7, 2024
2 parents 3eaade1 + 6d2ae89 commit 5a5d60d
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions agentops/llm_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,20 +289,15 @@ def override_api(self, api):
raise ValueError(f"Unsupported API: {api}")

module = import_module(api)

# If openai 1.0.0+ is specified, patch the completions methods
if api == 'openai':
# Patch openai v1.0.0+ methods
if hasattr(module, '__version__'):
module_version = parse(module.__version__)
if module_version >= parse('1.0.0'):
self.override_openai_v1_completion()
self.override_openai_v1_async_completion()

# Patch all methods in every API
if hasattr(module, '__version__'):
module_version = parse(module.__version__)
for version in sorted(self.SUPPORTED_APIS[api], key=parse, reverse=True):
if module_version >= parse(version):
for method_path in self.SUPPORTED_APIS[api][version]:
self._override_method(api, method_path, module)
break
# Patch openai <v1.0.0 methods
else:
for method_path in self.SUPPORTED_APIS['openai']['0.0.0']:
self._override_method(api, method_path, module)

0 comments on commit 5a5d60d

Please sign in to comment.