Skip to content

[bug] OpenAI v1.x AsyncClient Does Not Work in Guardrails as Expected #685

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

Closed
CalebCourier opened this issue Mar 28, 2024 · 2 comments
Closed
Labels
bug Something isn't working Stale

Comments

@CalebCourier
Copy link
Collaborator

Describe the bug
The only way to utilize Async clients for OpenAI 1.x in guardrails is to wrap it as a custom llm. This is because our identification criteria for OpenAI v1.x functions are weak and rely on the static exported methods.

To Reproduce

import openai
from guardrails import Guard


client = openai.AsyncClient()
guard = Guard().from_string(...) # doesn't matter

response = guard(
    client.chat.completions.create,
    ...
)

Expected behavior
User should be able to use async clients in the same way as synchronous clients.

Library version:
0.4.2

Additional context
There are ways to identify a function as belonging to an OpenAI 1.x client without necessitating they are one of the static methods, but it relies heavily on reflection:

from openai import AsyncClient, resources
async_client = AsyncClient()
llm_api = async_client.chat.completions.create
api_self = getattr(llm_api, "__self__", None)
llm_api_is_async_chat_completions = isinstance(api_self, resources.chat.completions.AsyncCompletions)
print("Llm Api Is Async Chat Completions: ", llm_api_is_async_chat_completions)

Additionally, the way we do things know (re-building the client), we would have to access private attributes:

api_self._client

Also see additional context here: #681

@CalebCourier CalebCourier added the bug Something isn't working label Mar 28, 2024
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Aug 22, 2024
Copy link

github-actions bot commented Sep 5, 2024

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale
Projects
None yet
Development

No branches or pull requests

1 participant