-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e10809
commit e6423d2
Showing
4 changed files
with
74 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,65 @@ | ||
from __future__ import annotations | ||
|
||
import importlib | ||
|
||
from weave.trace.patcher import MultiPatcher, SymbolPatcher | ||
from weave.trace.autopatch import IntegrationSettings | ||
from weave.trace.patcher import MultiPatcher, NoOpPatcher, SymbolPatcher | ||
|
||
from .instructor_iterable_utils import instructor_wrapper_async, instructor_wrapper_sync | ||
from .instructor_partial_utils import instructor_wrapper_partial | ||
|
||
instructor_patcher = MultiPatcher( | ||
[ | ||
SymbolPatcher( | ||
lambda: importlib.import_module("instructor.client"), | ||
"Instructor.create", | ||
instructor_wrapper_sync(name="Instructor.create"), | ||
), | ||
SymbolPatcher( | ||
lambda: importlib.import_module("instructor.client"), | ||
"AsyncInstructor.create", | ||
instructor_wrapper_async(name="AsyncInstructor.create"), | ||
), | ||
SymbolPatcher( | ||
lambda: importlib.import_module("instructor.client"), | ||
"Instructor.create_partial", | ||
instructor_wrapper_partial(name="Instructor.create_partial"), | ||
), | ||
SymbolPatcher( | ||
lambda: importlib.import_module("instructor.client"), | ||
"AsyncInstructor.create_partial", | ||
instructor_wrapper_partial(name="AsyncInstructor.create_partial"), | ||
), | ||
] | ||
) | ||
_instructor_patcher: MultiPatcher | None = None | ||
|
||
|
||
def get_instructor_patcher( | ||
settings: IntegrationSettings | None = None, | ||
) -> MultiPatcher | NoOpPatcher: | ||
if settings is None: | ||
settings = IntegrationSettings() | ||
|
||
if not settings.enabled: | ||
return NoOpPatcher() | ||
|
||
global _instructor_patcher | ||
if _instructor_patcher is not None: | ||
return _instructor_patcher | ||
|
||
base = settings.op_settings | ||
|
||
create_settings = base.model_copy(update={"name": base.name or "Instructor.create"}) | ||
async_create_settings = base.model_copy( | ||
update={"name": base.name or "AsyncInstructor.create"} | ||
) | ||
create_partial_settings = base.model_copy( | ||
update={"name": base.name or "Instructor.create_partial"} | ||
) | ||
async_create_partial_settings = base.model_copy( | ||
update={"name": base.name or "AsyncInstructor.create_partial"} | ||
) | ||
|
||
_instructor_patcher = MultiPatcher( | ||
[ | ||
SymbolPatcher( | ||
lambda: importlib.import_module("instructor.client"), | ||
"Instructor.create", | ||
instructor_wrapper_sync(create_settings), | ||
), | ||
SymbolPatcher( | ||
lambda: importlib.import_module("instructor.client"), | ||
"AsyncInstructor.create", | ||
instructor_wrapper_async(async_create_settings), | ||
), | ||
SymbolPatcher( | ||
lambda: importlib.import_module("instructor.client"), | ||
"Instructor.create_partial", | ||
instructor_wrapper_partial(create_partial_settings), | ||
), | ||
SymbolPatcher( | ||
lambda: importlib.import_module("instructor.client"), | ||
"AsyncInstructor.create_partial", | ||
instructor_wrapper_partial(async_create_partial_settings), | ||
), | ||
] | ||
) | ||
|
||
return _instructor_patcher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters