Skip to content

Fully qualify llm_api path for async #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions guardrails/async_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ async def __call(
*args,
**kwargs,
):
llm_api_str = ""
if llm_api:
llm_api_module_name = (
llm_api.__module__ if hasattr(llm_api, "__module__") else ""
)
llm_api_name = (
llm_api.__name__
if hasattr(llm_api, "__name__")
else type(llm_api).__name__
)
llm_api_str = f"{llm_api_module_name}.{llm_api_name}"
if metadata is None:
metadata = {}
if full_schema_reask is None:
Expand All @@ -111,12 +122,7 @@ async def __call(
attributes=[
("guard_id", self._guard_id),
("user_id", self._user_id),
(
"llm_api",
llm_api.__name__
if (llm_api and hasattr(llm_api, "__name__"))
else type(llm_api).__name__,
),
("llm_api", llm_api_str),
("custom_reask_prompt", self.reask_prompt is not None),
(
"custom_reask_instructions",
Expand Down Expand Up @@ -329,6 +335,17 @@ async def __parse(
*args,
**kwargs,
):
llm_api_str = ""
if llm_api:
llm_api_module_name = (
llm_api.__module__ if hasattr(llm_api, "__module__") else ""
)
llm_api_name = (
llm_api.__name__
if hasattr(llm_api, "__name__")
else type(llm_api).__name__
)
llm_api_str = f"{llm_api_module_name}.{llm_api_name}"
final_num_reasks = (
num_reasks if num_reasks is not None else 0 if llm_api is None else None
)
Expand All @@ -339,12 +356,7 @@ async def __parse(
attributes=[
("guard_id", self._guard_id),
("user_id", self._user_id),
(
"llm_api",
llm_api.__name__
if (llm_api and hasattr(llm_api, "__name__"))
else type(llm_api).__name__,
),
("llm_api", llm_api_str),
("custom_reask_prompt", self.reask_prompt is not None),
(
"custom_reask_instructions",
Expand Down
Loading